提交 1a838b31 作者: 方治民

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

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