提交 1a838b31 作者: 方治民

fix: 修复接口配置、退出登录后校验登录信息引起的错误

上级 12722441
......@@ -3,4 +3,4 @@ VITE_GLOB_API_URL=http://111.22.182.169:49600
# VITE_GLOB_API_URL=http://36.133.16.81:42111
# API 接口地址前缀
VITE_GLOB_API_URL_PREFIX=/jeecg-boot
VITE_GLOB_API_URL_PREFIX=/jeecgboot
......@@ -2,12 +2,6 @@
import { onExit } from '@dcloudio/uni-app'
import { isDevMode } from '@/utils/env'
import { usePermissions } from '@/hooks/app/usePermissions'
import * as UserInfoAPI from '@/api/model/userInfo'
import { useDictStore } from '@/store/modules/dict'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const dictStore = useDictStore()
// import * as Push from '@/utils/push'
......@@ -35,13 +29,6 @@
}
// #endif
})
function getDictList() {
if (!userStore.getToken) return
if (Object.keys(dictStore.getDictList).length !== 0) return
UserInfoAPI.dictList().then((res) => {
dictStore.setDictList(res)
})
}
onExit(() => {
// 停用监听权限
......@@ -50,7 +37,6 @@
onShow(() => {
console.log('App Show')
getDictList()
})
onHide(() => {
......@@ -58,7 +44,7 @@
})
onError((err) => {
// Message.toast(`App Error: ${err}`)
Message.toast(`App Error: ${err}`)
console.error('App Error:', err)
})
......
{
"name": "数智农服",
"appid": "__UNI__FD09823",
"description": "数智农服 APP",
"versionName": "1.0.6",
"versionCode": 10006,
"transformPx": false,
"locale": "zh-Hans",
"vueVersion": "3",
/* 5+App特有相关 */ // 配置文件详细说明
"name" : "数智农服",
"appid" : "__UNI__FD09823",
"description" : "数智农服 APP",
"versionName" : "1.0.6",
"versionCode" : 10006,
"transformPx" : false,
"locale" : "zh-Hans",
"vueVersion" : "3",
/* 5+App特有相关 */// 配置文件详细说明
// https://uniapp.dcloud.net.cn/collocation/manifest-app.html#full-manifest
"app-plus": {
"usingComponents": true,
"nvueCompiler": "uni-app",
"nvueStyleCompiler": "uni-app",
"nvueLaunchMode": "fast",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": false,
"autoclose": false,
"waiting": true
"app-plus" : {
"usingComponents" : true,
"nvueCompiler" : "uni-app",
"nvueStyleCompiler" : "uni-app",
"nvueLaunchMode" : "fast",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : false,
"autoclose" : false,
"waiting" : true
},
"screenOrientation": [
"portrait-primary",
"landscape-primary"
],
"compatible": {
"screenOrientation" : [ "portrait-primary", "landscape-primary" ],
"compatible" : {
// 忽略版本提示
"ignoreVersion": true
"ignoreVersion" : true
},
/* 模块配置 */
"modules": {
"Geolocation": {},
"Camera": {}
"modules" : {
"Geolocation" : {},
"Camera" : {},
"VideoPlayer" : {},
"Barcode" : {},
"Bluetooth" : {}
},
/* 应用发布信息 */
"distribute": {
"distribute" : {
/* android打包配置 */
"android": {
"permissions": [
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
......@@ -54,103 +54,97 @@
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"permissionPhoneState": {
"permissionPhoneState" : {
// app首次启动关闭权限申请
"request": "none"
"request" : "none"
},
"minSdkVersion": 23,
"targetSdkVersion": 30,
"abiFilters": [
"armeabi-v7a",
"arm64-v8a"
]
"minSdkVersion" : 23,
"targetSdkVersion" : 30,
"abiFilters" : [ "armeabi-v7a", "arm64-v8a" ]
},
/* ios打包配置 */
"ios": {
"dSYMs": false,
"privacyDescription": {
"NSUserTrackingUsageDescription": "请放心,开启权限不会获取您在其他站点的隐私信息,该权限仅用于标识设备并保障服务安全与提示浏览体验",
"NSLocationAlwaysAndWhenInUseUsageDescription": "该应用需要你的地理位置,以便检查你当前位置信息",
"NSLocationAlwaysUsageDescription": "该应用需要你的地理位置,以便检查你当前位置信息",
"NSLocationWhenInUseUsageDescription": "该应用需要你的地理位置,以便检查你当前位置信息",
"NSPhotoLibraryUsageDescription": "请允许访问您的照片图库,以便能够上传应用异常问题的截图"
"ios" : {
"dSYMs" : false,
"privacyDescription" : {
"NSUserTrackingUsageDescription" : "请放心,开启权限不会获取您在其他站点的隐私信息,该权限仅用于标识设备并保障服务安全与提示浏览体验",
"NSLocationAlwaysAndWhenInUseUsageDescription" : "该应用需要你的地理位置,以便检查你当前位置信息",
"NSLocationAlwaysUsageDescription" : "该应用需要你的地理位置,以便检查你当前位置信息",
"NSLocationWhenInUseUsageDescription" : "该应用需要你的地理位置,以便检查你当前位置信息",
"NSPhotoLibraryUsageDescription" : "请允许访问您的照片图库,以便能够上传应用异常问题的截图"
}
},
/* SDK配置 */
"sdkConfigs": {
"ad": {},
"statics": {},
"geolocation": {
"system": {
"__platform__": [
"ios",
"android"
]
"sdkConfigs" : {
"ad" : {},
"statics" : {},
"geolocation" : {
"system" : {
"__platform__" : [ "ios", "android" ]
}
}
},
"icons": {
"android": {
"hdpi": "unpackage/res/icons/72x72.png",
"xhdpi": "unpackage/res/icons/96x96.png",
"xxhdpi": "unpackage/res/icons/144x144.png",
"xxxhdpi": "unpackage/res/icons/192x192.png"
"icons" : {
"android" : {
"hdpi" : "unpackage/res/icons/72x72.png",
"xhdpi" : "unpackage/res/icons/96x96.png",
"xxhdpi" : "unpackage/res/icons/144x144.png",
"xxxhdpi" : "unpackage/res/icons/192x192.png"
},
"ios": {
"appstore": "unpackage/res/icons/1024x1024.png",
"ipad": {
"app": "unpackage/res/icons/76x76.png",
"app@2x": "unpackage/res/icons/152x152.png",
"notification": "unpackage/res/icons/20x20.png",
"notification@2x": "unpackage/res/icons/40x40.png",
"proapp@2x": "unpackage/res/icons/167x167.png",
"settings": "unpackage/res/icons/29x29.png",
"settings@2x": "unpackage/res/icons/58x58.png",
"spotlight": "unpackage/res/icons/40x40.png",
"spotlight@2x": "unpackage/res/icons/80x80.png"
"ios" : {
"appstore" : "unpackage/res/icons/1024x1024.png",
"ipad" : {
"app" : "unpackage/res/icons/76x76.png",
"app@2x" : "unpackage/res/icons/152x152.png",
"notification" : "unpackage/res/icons/20x20.png",
"notification@2x" : "unpackage/res/icons/40x40.png",
"proapp@2x" : "unpackage/res/icons/167x167.png",
"settings" : "unpackage/res/icons/29x29.png",
"settings@2x" : "unpackage/res/icons/58x58.png",
"spotlight" : "unpackage/res/icons/40x40.png",
"spotlight@2x" : "unpackage/res/icons/80x80.png"
},
"iphone": {
"app@2x": "unpackage/res/icons/120x120.png",
"app@3x": "unpackage/res/icons/180x180.png",
"notification@2x": "unpackage/res/icons/40x40.png",
"notification@3x": "unpackage/res/icons/60x60.png",
"settings@2x": "unpackage/res/icons/58x58.png",
"settings@3x": "unpackage/res/icons/87x87.png",
"spotlight@2x": "unpackage/res/icons/80x80.png",
"spotlight@3x": "unpackage/res/icons/120x120.png"
"iphone" : {
"app@2x" : "unpackage/res/icons/120x120.png",
"app@3x" : "unpackage/res/icons/180x180.png",
"notification@2x" : "unpackage/res/icons/40x40.png",
"notification@3x" : "unpackage/res/icons/60x60.png",
"settings@2x" : "unpackage/res/icons/58x58.png",
"settings@3x" : "unpackage/res/icons/87x87.png",
"spotlight@2x" : "unpackage/res/icons/80x80.png",
"spotlight@3x" : "unpackage/res/icons/120x120.png"
}
}
},
"splashscreen": {
"useOriginalMsgbox": true
"splashscreen" : {
"useOriginalMsgbox" : true
}
},
"uniStatistics": {
"enable": true
"uniStatistics" : {
"enable" : true
}
},
"uniStatistics": {
"enable": true,
"version": "2",
"debug": true
"uniStatistics" : {
"enable" : true,
"version" : "2",
"debug" : true
},
/* 快应用特有相关 */
"quickapp": {},
"quickapp" : {},
/* 小程序特有相关 */
"mp-weixin": {
"appid": "",
"setting": {
"urlCheck": false
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents": true
"usingComponents" : true
},
"mp-alipay": {
"usingComponents": true
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu": {
"usingComponents": true
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao": {
"usingComponents": true
"mp-toutiao" : {
"usingComponents" : true
}
}
......@@ -8,7 +8,7 @@
const userStore = useUserStore()
onLoad(async () => {
onShow(async () => {
// 获取推送标识并设置 PushClientId 缓存
// uni.getPushClientId({
// success: (res) => {
......@@ -37,6 +37,7 @@
// 跳转到登录页
goHome()
Message.toast(`欢迎回来~`)
} else {
// 关闭启动页并检查更新
try {
......@@ -59,7 +60,7 @@
show: false,
isLogin: false,
loading: false,
text: '',
text: defaultText,
form: {
rules: [
{
......@@ -128,7 +129,7 @@
// 打开登录页
goHome()
Message.toast(`登录成功, 欢迎回来!`)
Message.toast(`登录成功, 欢迎回来~`)
} else {
Message.toast(body.message)
return false
......@@ -153,7 +154,7 @@
// 添加欢迎登录的文字打字动态效果
let loop = null
let direction = 'right'
const count = ref(0)
const count = ref(defaultText.length)
watch(
() => model.show,
(show) => {
......@@ -185,9 +186,12 @@
},
)
onUnload(() => {
model.show = false
onHide(() => {
loop && clearInterval(loop)
loop = null
direction = 'right'
count.value = 0
model.show = false
})
function onReadConfirm(val) {
......@@ -392,7 +396,7 @@
// position: absolute;
// left: 40rpx;
// bottom: 40rpx;
font-size: 40rpx;
font-size: 38rpx;
color: #474747;
display: flex;
flex-direction: column;
......
......@@ -5,6 +5,12 @@
import { closeSplashscreenAndChechUpgrade } from '@/utils/upgrade'
import * as WeatherAPI from '@/api/model/weather'
import * as HomeAPI from '@/api/model/home'
import * as UserInfoAPI from '@/api/model/userInfo'
import { useDictStore } from '@/store/modules/dict'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const dictStore = useDictStore()
const model = reactive({
// 湖南省人民政府
......@@ -47,6 +53,9 @@
},
})
// 获取字典数据
getDictList()
// 查询金刚区数据
getServiceItems()
getMenuItems()
......@@ -106,6 +115,18 @@
})
}
function getDictList() {
if (!userStore.getToken) {
return
}
if (Object.keys(dictStore.getDictList).length !== 0) {
return
}
UserInfoAPI.dictList().then((res) => {
dictStore.setDictList(res)
})
}
// 页面数据
const pageData = reactive({
// 顶部标题和搜索
......
import { defineStore } from 'pinia'
import { store } from '/@/store'
import { useDictStore } from './dict'
import { Storage } from '@/utils/storage'
import { TOKEN_KEY, USER_INFO_KEY } from '@/enums/cacheEnum'
import Navigate from '@/utils/page/navigate'
import * as API from '/@/api/model/userInfo'
import { useDictStore } from './dict'
export interface UserInfo {
id: string
......@@ -37,6 +36,8 @@ export const useUserStore = defineStore({
this.token = token
return token
}
return null
},
getUserInfo(): Nullable<UserInfo> {
if (this.userInfo) {
......@@ -62,11 +63,19 @@ export const useUserStore = defineStore({
actions: {
setToken(token: string) {
this.token = token
Storage.set(TOKEN_KEY, token)
if (!token) {
Storage.remove(TOKEN_KEY)
} else {
Storage.set(TOKEN_KEY, token)
}
},
setUserInfo(info: UserInfo) {
this.userInfo = info
Storage.set(USER_INFO_KEY, info ? JSON.stringify(info) : null)
if (!info) {
Storage.remove(USER_INFO_KEY)
} else {
Storage.set(USER_INFO_KEY, info ? JSON.stringify(info) : null)
}
},
async logout() {
if (this.loading) {
......@@ -84,8 +93,10 @@ export const useUserStore = defineStore({
const dictStore = useDictStore(store)
dictStore.clearDict()
await Navigate.to('/pages/login/login')
this.loading = false
uni.reLaunch({
url: '/pages/login/login',
})
}
},
async refreshUserInfo() {
......
......@@ -48,8 +48,9 @@ const transform: AxiosTransform = {
// 错误的时候返回
const { data } = res
if (!data) {
if (!data || typeof data !== 'object') {
// return '[HTTP] Request has no return value';
// Message.toast(`${JSON.stringify(options)} --- ${res.data}`)
throw new Error(t('sys.api.apiRequestFailed'))
}
// 这里 status,body,message为 后台统一的字段,需要在 types.ts 内修改为项目自己的接口返回格式
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论