Jelajahi Sumber

配置typescript base

gemercheung 2 tahun lalu
induk
melakukan
54063937ff

+ 81 - 0
.eslintrc.js

@@ -0,0 +1,81 @@
+// @ts-check
+const { defineConfig } = require('eslint-define-config');
+module.exports = defineConfig({
+  root: true,
+  env: {
+    browser: true,
+    node: true,
+    es6: true,
+  },
+  parser: 'vue-eslint-parser',
+  parserOptions: {
+    parser: '@typescript-eslint/parser',
+    ecmaVersion: 2020,
+    sourceType: 'module',
+    jsxPragma: 'React',
+    ecmaFeatures: {
+      jsx: true,
+    },
+  },
+  extends: [
+    'plugin:vue/vue3-recommended',
+    'plugin:@typescript-eslint/recommended',
+    'prettier',
+    'plugin:prettier/recommended',
+    'plugin:jest/recommended',
+  ],
+  rules: {
+    'vue/script-setup-uses-vars': 'error',
+    '@typescript-eslint/ban-ts-ignore': 'off',
+    '@typescript-eslint/explicit-function-return-type': 'off',
+    '@typescript-eslint/no-explicit-any': 'off',
+    '@typescript-eslint/no-var-requires': 'off',
+    '@typescript-eslint/no-empty-function': 'off',
+    'vue/custom-event-name-casing': 'off',
+    'no-use-before-define': 'off',
+    '@typescript-eslint/no-use-before-define': 'off',
+    '@typescript-eslint/ban-ts-comment': 'off',
+    '@typescript-eslint/ban-types': 'off',
+    '@typescript-eslint/no-non-null-assertion': 'off',
+    '@typescript-eslint/explicit-module-boundary-types': 'off',
+    '@typescript-eslint/no-unused-vars': [
+      'error',
+      {
+        argsIgnorePattern: '^_',
+        varsIgnorePattern: '^_',
+      },
+    ],
+    'no-unused-vars': [
+      'error',
+      {
+        argsIgnorePattern: '^_',
+        varsIgnorePattern: '^_',
+      },
+    ],
+    'space-before-function-paren': 'off',
+
+    'vue/attributes-order': 'off',
+    'vue/one-component-per-file': 'off',
+    'vue/html-closing-bracket-newline': 'off',
+    'vue/max-attributes-per-line': 'off',
+    'vue/multiline-html-element-content-newline': 'off',
+    'vue/singleline-html-element-content-newline': 'off',
+    'vue/attribute-hyphenation': 'off',
+    'vue/require-default-prop': 'off',
+    'vue/require-explicit-emits': 'off',
+    'vue/no-useless-template-attributes': 'off',
+    'vue/html-self-closing': [
+      'error',
+      {
+        html: {
+          void: 'always',
+          normal: 'never',
+          component: 'always',
+        },
+        svg: 'always',
+        math: 'always',
+      },
+    ],
+    'vue/multi-word-component-names': 'off',
+  },
+});

+ 0 - 61
.eslintrc.json

@@ -1,61 +0,0 @@
-{
-  "root": true,
-  "rules": {
-    //强制使用单引号
-    "quotes": ["error", "single"],
-    //强制不使用分号结尾
-    "semi": ["error", "never"],
-    // 允许使用{}
-    "@typescript-eslint/ban-types": [
-      "error",
-      {
-        "extendDefaults": true,
-        "types": {
-          "{}": false
-        }
-      }
-    ],
-    // 允许any
-    "@typescript-eslint/no-explicit-any": "off"
-  },
-  "parser": "@typescript-eslint/parser",
-  "parserOptions": {
-    "ecmaVersion": "latest",
-    "sourceType": "module"
-  },
-  "extends": [
-    "plugin:@typescript-eslint/eslint-recommended",
-    "plugin:@typescript-eslint/recommended",
-    "plugin:prettier/recommended"
-  ],
-  "overrides": [
-    {
-      "files": ["src/*.ts"],
-      "env": { "browser": true }
-    },
-    {
-      "files": ["./vite.config.ts"],
-      "env": { "node": true }
-    },
-    {
-      "files": ["scripts/*.js"],
-      "env": { "node": true },
-      "parser": "espree"
-    },
-    {
-      "files": ["src/**/*.vue"],
-      "parser": "vue-eslint-parser",
-      "globals": {
-        "defineOptions": "writable"
-      },
-      "extends": ["plugin:vue/vue3-recommended", "plugin:prettier/recommended"],
-      "env": { "browser": true },
-      "parserOptions": {
-        "parser": "@typescript-eslint/parser"
-      },
-      "rules": {
-        "vue/multi-word-component-names": 0
-      }
-    }
-  ]
-}

+ 34 - 1
.vscode/settings.json

@@ -16,5 +16,38 @@
   },
   "editor.codeActionsOnSave": {
     "source.fixAll.eslint": true
-  }
+  },
+  "cSpell.words": [
+    "nocheck",
+    "windi",
+    "browserslist",
+    "tailwindcss",
+    "esnext",
+    "antv",
+    "tinymce",
+    "qrcode",
+    "sider",
+    "pinia",
+    "sider",
+    "nprogress",
+    "INTLIFY",
+    "stylelint",
+    "esno",
+    "vitejs",
+    "sortablejs",
+    "mockjs",
+    "codemirror",
+    "iconify",
+    "commitlint",
+    "vditor",
+    "echarts",
+    "cropperjs",
+    "logicflow",
+    "vueuse",
+    "zxcvbn",
+    "lintstagedrc",
+    "brotli",
+    "tailwindcss",
+    "sider"
+  ]
 }

+ 1 - 0
src/hook/useI18n.ts

@@ -39,6 +39,7 @@ export function useI18n(namespace?: string): {
   const tFn: I18nGlobalTranslation = (key: string, ...arg: any[]) => {
     if (!key) return ''
     if (!key.includes('.') && !namespace) return key
+    // @ts-ignore typescript bug?
     const res = t(
       getKey(namespace, key),
       ...(arg as I18nTranslationRestParameters)

+ 1 - 1
src/locales/helper.ts

@@ -13,7 +13,7 @@ export function setLoadLocalePool(cb: (loadLocalePool: LocaleType[]) => void) {
 }
 
 export function genMessage(
-  langs: Record<string, Record<string, any>>,
+  langs: Record<string, Record<string, any | unknown>>,
   prefix = 'lang'
 ) {
   const obj: Recordable = {}

+ 2 - 1
src/locales/lang/en.ts

@@ -1,8 +1,9 @@
 import { genMessage } from '../helper'
 import antdLocale from 'ant-design-vue/es/locale/en_US'
 
+type modulesType = Record<string, Record<string, any>>
 // const modules = import.meta.globEager('./en/**/*.ts')
-const modules = import.meta.glob('./en/**/*.ts', { eager: true })
+const modules: modulesType = import.meta.glob('./en/**/*.ts', { eager: true })
 
 export default {
   message: {

+ 2 - 2
src/locales/lang/en/base.ts

@@ -12,6 +12,6 @@ export default {
   delete: 'Delete',
   save: 'Save',
   cancel: 'Cancel',
-  loginFail: '登录状态失效,请重新登录',
-  saveSuccess: '保存成功'
+  loginFail: 'login fail, please Login again!',
+  saveSuccess: 'save successfully!'
 }

+ 2 - 1
src/locales/lang/en/room.ts

@@ -20,7 +20,8 @@ export default {
     selectScene: 'select scene',
     addScene: 'add scene'
   },
-  roomOnfired: '房间直播中, 请先关闭直播再修改 !',
+  roomOnfired:
+    'The studio is livestreaming; please stop the livestream before making any changes!',
   copyLink: 'Copy link',
   linkCopySuccess: 'Link copied successfully!',
   deletedScenes: 'Deleted scenes',

+ 4 - 2
src/locales/lang/zh_CN.ts

@@ -1,8 +1,10 @@
 import { genMessage } from '../helper'
 import antdLocale from 'ant-design-vue/es/locale/zh_CN'
-
+type modulesType = Record<string, Record<string, any>>
 // const modules = import.meta.globEager('./zh-CN/**/*.ts')
-const modules = import.meta.glob('./zh-CN/**/*.ts', { eager: true })
+const modules: modulesType = import.meta.glob('./zh-CN/**/*.ts', {
+  eager: true
+})
 export default {
   message: {
     ...genMessage(modules, 'zh-CN'),

+ 2 - 0
src/locales/setupI18n.ts

@@ -39,6 +39,8 @@ async function createI18nOptions(): Promise<I18nOptions> {
 // setup i18n instance with glob
 export async function setupI18n(app: App) {
   const options = await createI18nOptions()
+
+  //@ts-ignore
   i18n = createI18n(options) as I18n
   app.use(i18n)
 }

+ 0 - 1
src/locales/useLocale.ts

@@ -2,7 +2,6 @@
  * Multi-language related operations
  */
 import type { LocaleType } from '#/config'
-
 import { i18n } from './setupI18n'
 import { useLocaleStoreWithOut } from '@/store/modules/locale'
 import { unref, computed } from 'vue'

+ 6 - 2
src/utils/getImgSrc.ts

@@ -1,7 +1,11 @@
 const getImgSrc = (name: string) => {
   if (typeof name === 'undefined') return 'error.png'
   const path = `/src/assets/images/${name}.png`
-  const modules = import.meta.globEager('/src/assets/images/*')
-  return modules[path]?.default
+  const modules = import.meta.glob('/src/assets/images/*', { eager: true })
+  type modulesType = {
+    default?: string
+  }
+  const src = (modules[path] as modulesType)?.default
+  return src
 }
 export { getImgSrc }

+ 1 - 1
src/views/room/edit-room/props.ts

@@ -1,4 +1,4 @@
-import type { Room } from '@/store'
+import type { Room } from '@/store/modules/room'
 import type { PropType, ExtractPropTypes } from 'vue'
 
 export const props = {

+ 13 - 2
tsconfig.json

@@ -10,9 +10,14 @@
     "resolveJsonModule": true,
     "isolatedModules": true,
     "esModuleInterop": true,
+    "skipDefaultLibCheck": true,
     "lib": ["ESNext", "DOM"],
     "skipLibCheck": true,
-    "types": ["unplugin-vue-define-options/macros-global", "./types"],
+    "types": [
+      "unplugin-vue-define-options/macros-global",
+      "./types",
+      "vite/client"
+    ],
     "typeRoots": ["./node_modules/@types/", "./types"],
     "baseUrl": "./",
     "paths": {
@@ -20,6 +25,12 @@
       "#/*": ["types/*"]
     }
   },
-  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
+  "include": [
+    "src/**/*.ts",
+    "src/**/*.d.ts",
+    "src/**/*.tsx",
+    "src/**/*.vue",
+    "types/**/*.ts"
+  ],
   "references": [{ "path": "./tsconfig.node.json" }]
 }