Преглед на файлове

style: 总算处理好所有的 eslint 报错

feige996 преди 10 месеца
родител
ревизия
e1654359fd
променени са 6 файла, в които са добавени 55 реда и са изтрити 55 реда
  1. 1 0
      eslint.config.mjs
  2. 0 1
      scripts/postupgrade.js
  3. 1 1
      src/env.d.ts
  4. 40 40
      src/hooks/useUpload.ts
  5. 0 1
      src/interceptors/prototype.ts
  6. 13 12
      src/store/user.ts

+ 1 - 0
eslint.config.mjs

@@ -17,5 +17,6 @@ export default antfu({
     'jsdoc/check-param-names': 'off',
     'jsdoc/require-returns-description': 'off',
     'ts/no-empty-object-type': 'off',
+    'no-extend-native': 'off',
   },
 })

+ 0 - 1
scripts/postupgrade.js

@@ -2,7 +2,6 @@
 // # 在升级完后,会自动添加很多无用依赖,这需要删除以减小依赖包体积
 // # 只需要执行下面的命令即可
 
-// eslint-disable-next-line @typescript-eslint/no-var-requires
 const { exec } = require('node:child_process')
 
 // 定义要执行的命令

+ 1 - 1
src/env.d.ts

@@ -3,7 +3,7 @@
 
 declare module '*.vue' {
   import type { DefineComponent } from 'vue'
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
+
   const component: DefineComponent<{}, {}, any>
   export default component
 }

+ 40 - 40
src/hooks/useUpload.ts

@@ -30,6 +30,46 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
   const error = ref<Error | null>(null)
   const data = ref<any>(null)
 
+  const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string, size: number }) => {
+    if (size > maxSize) {
+      uni.showToast({
+        title: `文件大小不能超过 ${maxSize / 1024 / 1024}MB`,
+        icon: 'none',
+      })
+      return
+    }
+
+    // const fileExtension = file?.tempFiles?.name?.split('.').pop()?.toLowerCase()
+    // const isTypeValid = accept.some((type) => type === '*' || type.toLowerCase() === fileExtension)
+
+    // if (!isTypeValid) {
+    //   uni.showToast({
+    //     title: `仅支持 ${accept.join(', ')} 格式的文件`,
+    //     icon: 'none',
+    //   })
+    //   return
+    // }
+
+    loading.value = true
+    uploadFile({
+      tempFilePath,
+      formData,
+      onSuccess: (res) => {
+        const { data: _data } = JSON.parse(res)
+        data.value = _data
+        // console.log('上传成功', res)
+        success?.(_data)
+      },
+      onError: (err) => {
+        error.value = err
+        onError?.(err)
+      },
+      onComplete: () => {
+        loading.value = false
+      },
+    })
+  }
+
   const run = () => {
     // 微信小程序从基础库 2.21.0 开始, wx.chooseImage 停止维护,请使用 uni.chooseMedia 代替。
     // 微信小程序在2023年10月17日之后,使用本API需要配置隐私协议
@@ -81,46 +121,6 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
     }
   }
 
-  const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string, size: number }) => {
-    if (size > maxSize) {
-      uni.showToast({
-        title: `文件大小不能超过 ${maxSize / 1024 / 1024}MB`,
-        icon: 'none',
-      })
-      return
-    }
-
-    // const fileExtension = file?.tempFiles?.name?.split('.').pop()?.toLowerCase()
-    // const isTypeValid = accept.some((type) => type === '*' || type.toLowerCase() === fileExtension)
-
-    // if (!isTypeValid) {
-    //   uni.showToast({
-    //     title: `仅支持 ${accept.join(', ')} 格式的文件`,
-    //     icon: 'none',
-    //   })
-    //   return
-    // }
-
-    loading.value = true
-    uploadFile({
-      tempFilePath,
-      formData,
-      onSuccess: (res) => {
-        const { data: _data } = JSON.parse(res)
-        data.value = _data
-        // console.log('上传成功', res)
-        success?.(_data)
-      },
-      onError: (err) => {
-        error.value = err
-        onError?.(err)
-      },
-      onComplete: () => {
-        loading.value = false
-      },
-    })
-  }
-
   return { loading, error, data, run }
 }
 

+ 0 - 1
src/interceptors/prototype.ts

@@ -2,7 +2,6 @@ export const prototypeInterceptor = {
   install() {
     // 解决低版本手机不识别 array.at() 导致运行报错的问题
     if (typeof Array.prototype.at !== 'function') {
-      // eslint-disable-next-line no-extend-native
       Array.prototype.at = function (index: number) {
         if (index < 0)
           return this[this.length + index]

+ 13 - 12
src/store/user.ts

@@ -46,6 +46,18 @@ export const useUserStore = defineStore(
       uni.removeStorageSync('userInfo')
       uni.removeStorageSync('token')
     }
+    /**
+     * 获取用户信息
+     */
+    const getUserInfo = async () => {
+      const res = await _getUserInfo()
+      const userInfo = res.data
+      setUserInfo(userInfo)
+      uni.setStorageSync('userInfo', userInfo)
+      uni.setStorageSync('token', userInfo.token)
+      // TODO 这里可以增加获取用户路由的方法 根据用户的角色动态生成路由
+      return res
+    }
     /**
      * 用户登录
      * @param credentials 登录参数
@@ -63,18 +75,7 @@ export const useUserStore = defineStore(
       await getUserInfo()
       return res
     }
-    /**
-     * 获取用户信息
-     */
-    const getUserInfo = async () => {
-      const res = await _getUserInfo()
-      const userInfo = res.data
-      setUserInfo(userInfo)
-      uni.setStorageSync('userInfo', userInfo)
-      uni.setStorageSync('token', userInfo.token)
-      // TODO 这里可以增加获取用户路由的方法 根据用户的角色动态生成路由
-      return res
-    }
+
     /**
      * 退出登录 并 删除用户信息
      */