Browse Source

优化eslint 规则
Signed-off-by: Caner <5658514@qq.com>

Caner 3 years ago
parent
commit
69ff5dbac6

+ 0 - 60
.eslintrc.cjs

@@ -1,60 +0,0 @@
-module.exports = {
-  root: true,
-  env: {
-    node: true,
-    browser: true,
-    es2021: true
-  },
-  parserOptions: {
-    ecmaVersion: 'latest',
-    parser: '@typescript-eslint/parser',
-    sourceType: 'module'
-  },
-  extends: [
-    'plugin:vue/vue3-recommended',
-    'airbnb-base'
-  ],
-  rules: {
-    'no-console': 1, // 禁用打印
-    'comma-dangle': [ 2, 'never' ], // 禁止使用拖尾逗号
-    'no-extra-semi': 2, // 禁止不必要的分号
-    'array-bracket-spacing': [ 2, 'always' ], // 指定数组的元素之间要以空格隔开
-    'jsx-quotes': 0, // 强制使用单引号
-    'max-len': 0, // 强制一行的最大长度
-    semi: [ 2, 'never' ], // 禁止使用分号
-    'no-unused-vars': 2,
-    'no-unneeded-ternary': 2, // 禁止不必要的嵌套 var isYes = answer === 1 ? true : false;
-    'no-unreachable': 2, // 不能有无法执行的代码
-    'no-unused-expressions': 2, // 禁止无用的表达式
-    'linebreak-style': [ 0, 'error', 'windows' ],
-    'import/no-unresolved': 0,
-    'import/extensions': 0,
-    'import/no-absolute-path': 0,
-    'import/no-extraneous-dependencies': 2,
-    'class-methods-use-this': 0,
-    'no-mixed-operators': 0,
-    'eol-last': 0,
-    'import/newline-after-import': 0,
-    'vue/multi-word-component-names': 0,
-    'no-param-reassign': 0,
-    'no-restricted-syntax': 0,
-    'no-underscore-dangle': 0,
-    'no-plusplus': 0,
-    'no-bitwise': 0,
-    'guard-for-in': 0,
-    'func-names': 0,
-    'import/order': 0,
-    'vue/no-deprecated-slot-attribute': 0,
-    'vue/v-on-event-hyphenation': 0,
-    'vue/no-deprecated-filter': 0,
-    'vue/require-explicit-emits': 0,
-    'vue/no-v-html': 0,
-    'vue/order-in-components': 0,
-    'vue/no-reserved-component-names': 0,
-    'no-promise-executor-return': 0,
-    'no-sparse-arrays': 0,
-    'no-nested-ternary': 0,
-    'no-continue': 0,
-    complexity: [ 2, 5 ]
-  }
-}

+ 60 - 0
.eslintrc.json

@@ -0,0 +1,60 @@
+{
+  "root": true,
+  "env": {
+    "node": true,
+    "browser": true,
+    "es2021": true
+  },
+  "parserOptions": {
+    "ecmaVersion": "latest",
+    "parser": "@typescript-eslint/parser",
+    "sourceType": "module"
+  },
+  "extends": [
+    "plugin:vue/vue3-recommended",
+    "airbnb-base"
+  ],
+  "rules": {
+    "no-console": 0, // 禁用打印
+    "comma-dangle": [ 2, "never" ], // 禁止使用拖尾逗号
+    "no-extra-semi": 2, // 禁止不必要的分号
+    "array-bracket-spacing": [ 2, "always" ], // 指定数组的元素之间要以空格隔开
+    "jsx-quotes": 0, // 强制使用单引号
+    "max-len": 0, // 强制一行的最大长度
+    "semi": [ 2, "never" ], // 禁止使用分号
+    "no-unused-vars": 2,
+    "no-unneeded-ternary": 2, // 禁止不必要的嵌套 var isYes = answer === 1 ? true : false;
+    "no-unreachable": 2, // 不能有无法执行的代码
+    "no-unused-expressions": 2, // 禁止无用的表达式
+    "linebreak-style": [ 0, "error", "windows" ],
+    "import/no-unresolved": 0,
+    "import/extensions": 0,
+    "import/no-absolute-path": 0,
+    "import/no-extraneous-dependencies": 2,
+    "class-methods-use-this": 0,
+    "no-mixed-operators": 0,
+    "eol-last": 0,
+    "import/newline-after-import": 0,
+    "vue/multi-word-component-names": 0,
+    "no-param-reassign": 0,
+    "no-restricted-syntax": 0,
+    "no-underscore-dangle": 0,
+    "no-plusplus": 0,
+    "no-bitwise": 0,
+    "guard-for-in": 0,
+    "func-names": 0,
+    "import/order": 0,
+    "vue/no-deprecated-slot-attribute": 0,
+    "vue/v-on-event-hyphenation": 0,
+    "vue/no-deprecated-filter": 0,
+    "vue/require-explicit-emits": 0,
+    "vue/no-v-html": 0,
+    "vue/order-in-components": 0,
+    "vue/no-reserved-component-names": 0,
+    "no-promise-executor-return": 0,
+    "no-sparse-arrays": 0,
+    "no-nested-ternary": 0,
+    "no-continue": 0,
+    "complexity": [ 2, 5 ]
+  }
+}

+ 6 - 4
src/pages/index/main.ts

@@ -7,6 +7,8 @@ import '@/utils/rem'
 // 动态路由
 // 动态路由
 const routes = Object.values(import.meta.glob('./views/*/route.ts', { eager: true, import: 'default' }))
 const routes = Object.values(import.meta.glob('./views/*/route.ts', { eager: true, import: 'default' }))
 routes.push({ path: '/:path(.*)', redirect: '/' })
 routes.push({ path: '/:path(.*)', redirect: '/' })
+console.log(123, routes)
+
 const store = createPinia()
 const store = createPinia()
 const app = createApp(App)
 const app = createApp(App)
 const router = createRouter({
 const router = createRouter({
@@ -14,10 +16,10 @@ const router = createRouter({
   routes
   routes
 })
 })
 // 路由守卫
 // 路由守卫
-router.beforeEach((to, from, next) => {
-  // do something
-  next()
-})
+// router.beforeEach((to, from, next) => {
+//   // do something
+//   next()
+// })
 app.use(store)
 app.use(store)
   .use(naive)
   .use(naive)
   .use(router)
   .use(router)

+ 0 - 5
src/pages/index/views/home/index.vue

@@ -5,8 +5,3 @@
     </n-button>
     </n-button>
   </div>
   </div>
 </template>
 </template>
-<script setup lang="ts">
-import { reactive, ref } from 'vue'
-const t = ref(0)
-const a = reactive({ test: 1 })
-</script>

+ 34 - 14
src/utils/JsFn.ts

@@ -27,7 +27,7 @@ export const sleep = (ms: number) => { return new Promise((resolve) => { setTime
  * @param arr
  * @param arr
  * @returns
  * @returns
  */
  */
-export const flatten:any = (arr: Array<Any>) => {
+export const flatten: any = (arr: Array<Any>) => {
   return [].concat(
   return [].concat(
     ...arr.map((x) => (Array.isArray(x) ? flatten(x) : x))
     ...arr.map((x) => (Array.isArray(x) ? flatten(x) : x))
   )
   )
@@ -55,24 +55,24 @@ export const search = (data: Array<Any>, key: string) => {
  * @param fmt 日期格式
  * @param fmt 日期格式
  * @returns 
  * @returns 
  */
  */
- export const fomartTime = (date: Date, fmt = 'yyyy-MM-dd hh:mm:ss') => {
+export const fomartTime = (date: Date, fmt = 'yyyy-MM-dd hh:mm:ss') => {
   if (!date) return ''
   if (!date) return ''
   const o = {
   const o = {
-      "M+": date.getMonth() + 1,                 //月份 
-      "d+": date.getDate(),                    //日 
-      "h+": date.getHours(),                   //小时 
-      "m+": date.getMinutes(),                 //分 
-      "s+": date.getSeconds(),                 //秒 
-      "q+": Math.floor((date.getMonth() + 3) / 3), //季度 
-      "S": date.getMilliseconds()             //毫秒 
+    "M+": date.getMonth() + 1,                 //月份 
+    "d+": date.getDate(),                    //日 
+    "h+": date.getHours(),                   //小时 
+    "m+": date.getMinutes(),                 //分 
+    "s+": date.getSeconds(),                 //秒 
+    "q+": Math.floor((date.getMonth() + 3) / 3), //季度 
+    "S": date.getMilliseconds()             //毫秒 
   } as any
   } as any
   if (/(y+)/.test(fmt)) {
   if (/(y+)/.test(fmt)) {
-      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
+    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
   }
   }
   for (let k in o) {
   for (let k in o) {
-      if (new RegExp("(" + k + ")").test(fmt)) {
-          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
-      }
+    if (new RegExp("(" + k + ")").test(fmt)) {
+      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
+    }
   }
   }
   return fmt;
   return fmt;
 }
 }
@@ -84,7 +84,7 @@ export const search = (data: Array<Any>, key: string) => {
 */
 */
 export const mileage2string = (num: number) => {
 export const mileage2string = (num: number) => {
   const a = Math.floor(num / 1000).toString()
   const a = Math.floor(num / 1000).toString()
-  const ab =parseFloat((num % 1000).toFixed(1)) 
+  const ab = parseFloat((num % 1000).toFixed(1))
   const b = Math.floor(num % 1000).toString()
   const b = Math.floor(num % 1000).toString()
   const c = b.length === 1 ? `00${ab}` : b.length === 2 ? `0${ab}` : ab
   const c = b.length === 1 ? `00${ab}` : b.length === 2 ? `0${ab}` : ab
   return `${a}+${c}`
   return `${a}+${c}`
@@ -108,3 +108,23 @@ export const uniqueArr = <T = Any>(arr: T[], key: keyof T) => {
   }
   }
   return newArr
   return newArr
 }
 }
+
+/**
+ * 数组按指定key值分组
+ * @param {*} array 
+ * @param {*} id 
+ * @returns 
+ */
+export const groupBy = (array: Array<any>, id: string) => {
+  let groups = {} as any;
+  array.forEach((o) => {
+    let group = JSON.stringify(o[id]);
+    if (typeof o[id] === 'string') {
+      group = o[id]
+    }
+    groups[group] = groups[group] || [];
+    groups[group].push(o);
+  });
+  // return Object.values(groups);
+  return groups;
+}

+ 10 - 8
src/utils/SRSWebRtcPlayer.ts

@@ -3,16 +3,18 @@
  * auth Caner
  * auth Caner
  */
  */
 class WebRtcPlayer {
 class WebRtcPlayer {
-    private Peer: any
-    private TIMER: any
+    private Peer: RTCPeerConnection | null
+    private TIMER: number | null
     constructor(option: { HOST: string; TOKEN: string; UUID: string; PROFILE: number; PORT: number; DOM: HTMLVideoElement }) {
     constructor(option: { HOST: string; TOKEN: string; UUID: string; PROFILE: number; PORT: number; DOM: HTMLVideoElement }) {
+        this.TIMER = null
+        this.Peer = null
         this.initWebRtc(option.HOST, option.PORT, option.TOKEN, option.UUID, option.PROFILE, option.DOM).then(res => {
         this.initWebRtc(option.HOST, option.PORT, option.TOKEN, option.UUID, option.PROFILE, option.DOM).then(res => {
             this.Peer = res
             this.Peer = res
         }).catch(() => {
         }).catch(() => {
             this.Peer = null
             this.Peer = null
         })
         })
     }
     }
-    
+
     /**
     /**
      * 同步睡眠
      * 同步睡眠
      * @param ms 毫秒
      * @param ms 毫秒
@@ -29,18 +31,18 @@ class WebRtcPlayer {
      * @param DOM video节点
      * @param DOM video节点
      * @returns 
      * @returns 
      */
      */
-    private async initWebRtc(HOST: string, PORT: number, TOKEN: string, UUID: string, PROFILE: number, DOM: HTMLVideoElement) {
+    private async initWebRtc(HOST: string, PORT: number, TOKEN: string, UUID: string, PROFILE: number, DOM: HTMLVideoElement): Promise<RTCPeerConnection | null> {
         try {
         try {
-            const Peer = new RTCPeerConnection() as any
+            const Peer = new RTCPeerConnection()
             Peer.addTransceiver('video', { direction: 'recvonly' })
             Peer.addTransceiver('video', { direction: 'recvonly' })
             const offer = await Peer.createOffer()
             const offer = await Peer.createOffer()
             await Peer.setLocalDescription(offer)
             await Peer.setLocalDescription(offer)
 
 
             // 监听视频=播放
             // 监听视频=播放
-            Peer.ontrack = (event: Event | any) => {
+            Peer.ontrack = (event: RTCTrackEvent) => {
                 if (DOM) {
                 if (DOM) {
                     const { streams } = event
                     const { streams } = event
-                    DOM.srcObject = streams[0]
+                    DOM.srcObject = streams![0]
                     console.log('track', event)
                     console.log('track', event)
                 }
                 }
             }
             }
@@ -113,7 +115,7 @@ class WebRtcPlayer {
                     }
                     }
                 })
                 })
             })
             })
-        }, 500);
+        }, 500) as unknown as number
     }
     }
 
 
     /**
     /**

+ 5 - 5
src/utils/exp2File.ts

@@ -16,12 +16,12 @@ const number2times = (num: number) => {
  * @param url 保存地址|blob
  * @param url 保存地址|blob
  * @param saveName 文件名
  * @param saveName 文件名
  */
  */
-const openDownloadDialog = (url: any, saveName: string) => {
+const openDownloadDialog = (url: string | Blob | object, saveName: string) => {
     if (typeof url === 'object' && url instanceof Blob) {
     if (typeof url === 'object' && url instanceof Blob) {
         url = URL.createObjectURL(url) // 创建blob地址
         url = URL.createObjectURL(url) // 创建blob地址
     }
     }
     const aLink = document.createElement('a')
     const aLink = document.createElement('a')
-    aLink.href = url
+    aLink.href = url as any
     aLink.download = saveName || '' // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
     aLink.download = saveName || '' // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
     let event
     let event
     if (window.MouseEvent) event = new MouseEvent('click')
     if (window.MouseEvent) event = new MouseEvent('click')
@@ -41,8 +41,8 @@ export const exp2json = async (file: File) => {
     return await new Promise((resolve, reject) => {
     return await new Promise((resolve, reject) => {
         try {
         try {
             const reader = new FileReader()
             const reader = new FileReader()
-            reader.onload = (e: any) => {
-                const wb = XLSX.read(e.target.result, {
+            reader.onload = (e) => {
+                const wb = XLSX.read(e.target?.result, {
                     type: 'binary'
                     type: 'binary'
                 }) // 读取完成的数据
                 }) // 读取完成的数据
                 // 转成json header解析第一行标题
                 // 转成json header解析第一行标题
@@ -62,7 +62,7 @@ export const exp2json = async (file: File) => {
  * @param arr 数据是数组包含的对象
  * @param arr 数据是数组包含的对象
  * @param fileName 名字
  * @param fileName 名字
  */
  */
-export const exp2excel = (arr: Array<any>, fileName:string,cellMerges?:Array<any>) => {
+export const exp2excel = (arr: object[], fileName:string,cellMerges?:Array<any>) => {
     const sheet = XLSX.utils.json_to_sheet(arr);
     const sheet = XLSX.utils.json_to_sheet(arr);
     // excel宽高设置
     // excel宽高设置
     sheet["!cols"] = arr.map(() => {
     sheet["!cols"] = arr.map(() => {

+ 1 - 1
src/utils/html2File.ts

@@ -133,7 +133,7 @@ export const exp2png = async (domID: string, fileName: string, bkcolor: string)
         let htmlrq = new XMLHttpRequest() as any
         let htmlrq = new XMLHttpRequest() as any
         htmlrq.open('GET', imgURL, true)
         htmlrq.open('GET', imgURL, true)
         htmlrq.responseType = 'blob'
         htmlrq.responseType = 'blob'
-        htmlrq.onload = function (e: any) {
+        htmlrq.onload =  (e: { target: { status: number; response: Blob | MediaSource; } })=> {
             if (e.target.status === 200) {
             if (e.target.status === 200) {
                 imgURL = URL.createObjectURL(e.target.response) // 创建blob地址
                 imgURL = URL.createObjectURL(e.target.response) // 创建blob地址
                 download(imgURL, fileName)
                 download(imgURL, fileName)

+ 2 - 2
src/utils/rem.js → src/utils/rem.ts

@@ -14,8 +14,7 @@
     // 1rem =100px
     // 1rem =100px
     let width = docEl.clientWidth
     let width = docEl.clientWidth
     if (isAndroid || isIOS) {
     if (isAndroid || isIOS) {
-      // eslint-disable-next-line radix
-      docEl.style.fontSize = `${parseInt((100 * (width / 750)) * 2)}px`
+      docEl.style.fontSize = `${Math.floor((100 * (width / 750)) * 2)}px`
     } else {
     } else {
       if (width < 1920) {
       if (width < 1920) {
         width = 1920
         width = 1920
@@ -30,3 +29,4 @@
   win.addEventListener(resizeEvt, recalc, false)
   win.addEventListener(resizeEvt, recalc, false)
   console.log('rem自适应')
   console.log('rem自适应')
 }(document, window))
 }(document, window))
+export {}