Skip to content

Commit

Permalink
feat: 添加 TypeScript 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwangyihao committed Oct 7, 2024
1 parent 2e02b13 commit 6083a3f
Show file tree
Hide file tree
Showing 8 changed files with 3,239 additions and 5,518 deletions.
8,525 changes: 3,056 additions & 5,469 deletions package-lock.json

Large diffs are not rendered by default.

46 changes: 24 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,33 @@
]
},
"devDependencies": {
"@aiot-toolkit/jsc": "^1.0.3",
"@aiot-toolkit/velasim": "^0.1.26-beta.3",
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"aiot-toolkit": "1.1.0",
"babel-eslint": "^10.0.1",
"eslint": "^6.0.0",
"eslint-config-prettier": "^6.0.0",
"eslint-import-resolver-node": "^0.3.7",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^3.4.0",
"@aiot-toolkit/jsc": "^1.0.7",
"@aiot-toolkit/velasim": "^0.1.26",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"aiot-toolkit": "1.1.4",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-ux": "^0.0.4",
"husky": "^8.0.1",
"less": "^3.12.2",
"less-loader": "^6.2.0",
"lint-staged": "^8.2.1",
"postcss-html": "^1.3.0",
"husky": "^9.1.6",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"lint-staged": "^15.2.10",
"postcss-html": "^1.7.0",
"postcss-less": "^6.0.0",
"prettier": "^2.7.1",
"stylelint": "^14.5.3",
"stylelint-config-recess-order": "^3.0.0",
"stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0",
"prettier": "^3.3.3",
"stylelint": "^16.9.0",
"stylelint-config-recess-order": "^5.1.1",
"stylelint-config-standard": "^36.0.1",
"stylelint-order": "^6.0.4",
"ux-types": "^0.1.1",
"ts-loader": "^9.5.1",
"typescript": "^5.6.2",
"vitepress": "^1.3.4",
"vue": "^3.5.5"
"vue": "^3.5.11"
}
}
14 changes: 14 additions & 0 deletions quickapp.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
module.exports = {
webpack: {
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
},
],
},
],
},
},
cli: {
"enable-custom-component": true,
"enable-jsc": true,
Expand Down
3 changes: 0 additions & 3 deletions src/pages/search/search.ux
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ export default {
}
},
toggleMenu() {
if (this.imgMenu === "animation-in") {
this.toggleImgMenu()
}
if (this.menu === "animation-in") {
this.menu = "animation-out-back"
} else {
Expand Down
47 changes: 23 additions & 24 deletions src/utils/index.js → src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import systemRouter from "@system.router"
import storage from "@system.storage"
import prompt from "@system.prompt"
import systemFetch from "@system.fetch"
import systemDevice from "@system.device"
import {
fetch as systemFetch,
storage,
device as systemDevice,
router as systemRouter,
prompt
} from "./tsimports"
import {Source, SourceData} from "./source"

const config = {
animationDuration: 200,
Expand All @@ -11,7 +14,7 @@ const config = {

let thisObj = undefined

const state = {
export const state = {
animationBack: false
}

Expand All @@ -36,11 +39,11 @@ const router = {
}
}, config.animationDuration + config.animationDelay)
},
back(path) {
if (typeof path !== "string") if (thisObj.onBack?.call()) return
back(path?: string) {
if (!path) if (thisObj.onBack?.call()) return
animation.out(true)
setTimeout(() => {
if (typeof path === "string") {
if (path) {
systemRouter.back({
path
})
Expand Down Expand Up @@ -332,7 +335,7 @@ const setting = {
if (name === "page_transition") {
systemRouter.clear()
}
resolve()
resolve(true)
},
fail: (err) => {
reject(err)
Expand All @@ -342,7 +345,7 @@ const setting = {
},

async init() {
Promise.all(
await Promise.all(
this.list.map((item) => {
if (item.value !== undefined) {
return setting.getRaw(item.name).then((value) => {
Expand All @@ -354,7 +357,7 @@ const setting = {
}
}

setting.init()
setting.init().then()

const template = {
private: {
Expand Down Expand Up @@ -385,7 +388,7 @@ setting.getRaw("page_transition").then((value) => {
}
})

const fetch = (url, options) => {
export const fetch = (url, options) => {
return new Promise((resolve, reject) => {
systemFetch.fetch({
url,
Expand All @@ -401,12 +404,12 @@ const fetch = (url, options) => {
}

const source = {
list: [],
list: [] as Source[],
init() {
storage.get({
key: "source",
success: (data) => {
this.list = JSON.parse(data)
this.list = (JSON.parse(data) as SourceData[]).map((item) => new Source(item))
}
})
},
Expand Down Expand Up @@ -437,7 +440,7 @@ const source = {
save() {
storage.set({
key: "source",
value: JSON.stringify(this.list)
value: JSON.stringify(this.list.map((item) => item.raw))
})
},
mapForUi() {
Expand All @@ -447,8 +450,8 @@ const source = {
bookSourceName: item.bookSourceName,
enabled: item.enabled,
enabledExplore: item.enabledExplore,
hasExplore: !!item.exploreUrl,
hasLogin: !!item.loginUrl
hasExplore: item.hasExplore,
hasLogin: item.hasLogin
}
})
},
Expand Down Expand Up @@ -514,7 +517,7 @@ const device = {
}
}

device.init()
device.init().then()

const date = {
format(date, format) {
Expand Down Expand Up @@ -556,11 +559,7 @@ global.animation = animation
global.on = on
global.template = template
global.setting = setting
global.fetch = fetch
global.fetch = fetch as any
global.source = source
global.device = device
global.date = date

export default {
state
}
100 changes: 100 additions & 0 deletions src/utils/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
export interface SourceData {
bookSourceComment: string
bookSourceGroup: string
bookSourceName: string
bookSourceType: number
bookSourceUrl: string
concurrentRate: string
customOrder: number
enabled: boolean
enabledCookieJar: boolean
enabledExplore: boolean
exploreUrl: string
lastUpdateTime: number
loginCheckJs: string
loginUrl: string
respondTime: number
ruleBookInfo: RuleBookInfo
ruleContent: RuleContent
ruleExplore: RuleExplore
ruleSearch: RuleSearch
ruleToc: RuleToc
searchUrl: string
weight: number
}

export interface RuleBookInfo {
author: string
coverUrl: string
intro: string
kind: string
lastChapter: string
name: string
tocUrl: string
wordCount: string
}

export interface RuleContent {
content: string
}

export interface RuleExplore {
author: string
bookList: string
bookUrl: string
coverUrl: string
intro: string
kind: string
name: string
wordCount: string
}

export interface RuleSearch extends RuleExplore {
checkKeyWord: string
}

export interface RuleToc {
chapterList: string
chapterName: string
chapterUrl: string
isVolume: string
}

export class Source {
raw: SourceData
constructor(public data: SourceData) {
this.raw = data
}

get bookSourceUrl() {
return this.raw.bookSourceUrl
}

get bookSourceName() {
return this.raw.bookSourceName
}

get enabled() {
return this.raw.enabled
}

set enabled(value: boolean) {
this.raw.enabled = value
}

get enabledExplore() {
return this.raw.enabledExplore
}

set enabledExplore(value: boolean) {
this.raw.enabledExplore = value
}

get hasExplore() {
return this.raw.ruleExplore !== undefined
}

get hasLogin() {
return this.raw.loginUrl !== undefined
}
}
7 changes: 7 additions & 0 deletions src/utils/tsimports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import router from "@system.router"
import storage from "@system.storage"
import prompt from "@system.prompt"
import fetch from "@system.fetch"
import device from "@system.device"

export {fetch, storage, device, router, prompt}
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"allowJs": true,
"esModuleInterop": true,
"module": "commonjs",
"target": "es5",
"outDir": "./dist"
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.ux"
]
}

0 comments on commit 6083a3f

Please sign in to comment.