diff --git a/eslint.config.mjs b/eslint.config.mjs index 62165d9..03038dc 100644 --- a/eslint.config.mjs +++ b/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', }, }) diff --git a/scripts/postupgrade.js b/scripts/postupgrade.js index f8ada60..b1671d2 100644 --- a/scripts/postupgrade.js +++ b/scripts/postupgrade.js @@ -2,7 +2,6 @@ // # 在升级完后,会自动添加很多无用依赖,这需要删除以减小依赖包体积 // # 只需要执行下面的命令即可 -// eslint-disable-next-line @typescript-eslint/no-var-requires const { exec } = require('node:child_process') // 定义要执行的命令 diff --git a/src/env.d.ts b/src/env.d.ts index 846ff39..ffa725c 100644 --- a/src/env.d.ts +++ b/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 } diff --git a/src/hooks/useUpload.ts b/src/hooks/useUpload.ts index 79225dd..3080d5a 100644 --- a/src/hooks/useUpload.ts +++ b/src/hooks/useUpload.ts @@ -30,6 +30,46 @@ export default function useUpload(options: TOptions = {} const error = ref(null) const data = ref(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(options: TOptions = {} } } - 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 } } diff --git a/src/interceptors/prototype.ts b/src/interceptors/prototype.ts index 360e65c..647e6bd 100644 --- a/src/interceptors/prototype.ts +++ b/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] diff --git a/src/store/user.ts b/src/store/user.ts index 522036f..da73da3 100644 --- a/src/store/user.ts +++ b/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 - } + /** * 退出登录 并 删除用户信息 */