From 5503ff036bfd277a9a3e6396aeebeb768b21e6df Mon Sep 17 00:00:00 2001 From: yxq Date: Wed, 4 Sep 2024 14:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E5=AE=A4=E7=82=B9=E5=90=8D=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitorMobile/App.vue | 4 +- monitorMobile/api/work/rollCall.js | 38 +++++ monitorMobile/http/api.js | 35 +++- monitorMobile/pages.json | 9 +- monitorMobile/pages/login.vue | 1 + monitorMobile/pages/my/index.vue | 2 +- .../pages/work/passengerFlow/index.vue | 5 +- monitorMobile/pages/work/rollCall/detail.vue | 153 +++++++++++------- monitorMobile/pages/work/rollCall/index.vue | 86 ++++------ monitorMobile/store/index.js | 42 ++++- 10 files changed, 247 insertions(+), 128 deletions(-) create mode 100644 monitorMobile/api/work/rollCall.js diff --git a/monitorMobile/App.vue b/monitorMobile/App.vue index 981ee0f..cac54d5 100644 --- a/monitorMobile/App.vue +++ b/monitorMobile/App.vue @@ -2,7 +2,7 @@ export default { onLaunch: function() {}, onShow: function() {}, - onHide: function() {} + onHide: function() {}, } @@ -11,7 +11,7 @@ @import "uview-ui/index.scss"; @font-face { - font-family: 'Alimama ShuHeiTi';//字体别名 + font-family: 'Alimama ShuHeiTi'; //字体别名 src: url('/static/fonts/alimamashuheiti.ttf') format('truetype'); font-weight: normal; font-style: normal; diff --git a/monitorMobile/api/work/rollCall.js b/monitorMobile/api/work/rollCall.js new file mode 100644 index 0000000..b68dc45 --- /dev/null +++ b/monitorMobile/api/work/rollCall.js @@ -0,0 +1,38 @@ +import http from '@/http/api.js' +const url = '/api/business/classRoomCallApi' + +// 获取列表 +export const page = (params) => { + return http.request({ + url: url + '/getPageList', + method: 'get', + params + }) +} + +// 获取不分页列表 +export const list = (params) => { + return http.request({ + url: url + '/getNoPageList', + method: 'get', + params + }) +} + +// 获取点名列表某一项所有人员 +export const detail = (data) => { + return http.request({ + url: '/api/business/personApi/pageQuery', + method: 'post', + data + }) +} + +// 获取点名任务列表 +export const taskPage = (params) => { + return http.request({ + url: url + '/getTaskPageList', + method: 'get', + params + }) +} \ No newline at end of file diff --git a/monitorMobile/http/api.js b/monitorMobile/http/api.js index c900b0d..2ad7776 100644 --- a/monitorMobile/http/api.js +++ b/monitorMobile/http/api.js @@ -3,11 +3,23 @@ import { } from '@/http/config.js'; import Request from '@/utils/luch-request/index.js'; const http = new Request(options); +import store from "@/store" http.interceptors.request.use((config) => { // 可使用async await 做异步操作 // 假设有token值需要在头部需要携带 let token = uni.getStorageSync('token'); if (token) { config.header['Authorization'] = 'Bearer ' + token; + + const jwt = decryptJWT(token); + const exp = getJWTDate(jwt.exp); + // token 已经过期 + if (new Date() <= exp) { + let refreshToken = store.state.refreshToken; + // 携带刷新 token + if (refreshToken) { + config.header["X-" + 'Authorization'] = 'Bearer ' + refreshToken; + } + } } // #ifndef H5 @@ -22,10 +34,7 @@ http.interceptors.request.use((config) => { // 可使用async await 做异步操 return Promise.reject(config) }) http.interceptors.response.use((response) => { - // 若有数据返回则通过 - if (response.data.access_token || response.data.key) { - return response.data - } + checkAndStoreAuthentication(response) // 服务端返回的状态码不等于200,则reject() if (response.data.code && response.data.code !== 200) { setTimeout(() => { @@ -49,6 +58,7 @@ http.interceptors.response.use((response) => { if (response.statusCode == 401) { const pages = getCurrentPages() const currentPage = pages[pages.length - 1] + this.$store.dispatch('clearToken') uni.redirectTo({ url: `/pages/login?redirect=/${currentPage.route}` }) @@ -74,4 +84,21 @@ function decryptJWT(token) { function getJWTDate(timestamp) { return new Date(timestamp * 1000); } +/** + * 检查并存储授权信息 + * @param res 响应对象 + */ +const checkAndStoreAuthentication = (res) => { + // 读取响应报文头 token 信息 + let token = res.header['access-token']; + let refreshToken = res.header['x-access-token']; + // 判断是否是无效 token + if (token === "invalid_token") { + stroe.dispatch('clearToken') + } + // 判断是否存在刷新 token,如果存在则存储在本地 + else if (refreshToken && token && token !== "invalid_token") { + stroe.dispatch('setToken',{token,refreshToken}) + } +} export default http; \ No newline at end of file diff --git a/monitorMobile/pages.json b/monitorMobile/pages.json index 6c21822..40f9f7d 100644 --- a/monitorMobile/pages.json +++ b/monitorMobile/pages.json @@ -57,7 +57,8 @@ { "path": "pages/work/returnBed/index", "style": { - "navigationBarTitleText": "归寝" + "navigationBarTitleText": "归寝", + "enablePullDownRefresh": true } }, { @@ -71,7 +72,8 @@ { "path": "pages/work/passengerFlow/index", "style": { - "navigationBarTitleText": "客流" + "navigationBarTitleText": "客流", + "enablePullDownRefresh": true } }, { @@ -85,7 +87,8 @@ { "path": "pages/work/rollCall/index", "style": { - "navigationBarTitleText": "点名" + "navigationBarTitleText": "点名", + "enablePullDownRefresh": true } }, { diff --git a/monitorMobile/pages/login.vue b/monitorMobile/pages/login.vue index c254dfa..6b7c961 100644 --- a/monitorMobile/pages/login.vue +++ b/monitorMobile/pages/login.vue @@ -89,6 +89,7 @@ let data = res.data this.$store.dispatch('setToken',{token:data.token}) this.$store.dispatch('getUserInfo') + this.$store.dispatch('getAllOptions') this.NAV_TO('/') }).finally(() => { this.isLoading = false diff --git a/monitorMobile/pages/my/index.vue b/monitorMobile/pages/my/index.vue index 669da38..67c34ff 100644 --- a/monitorMobile/pages/my/index.vue +++ b/monitorMobile/pages/my/index.vue @@ -125,7 +125,7 @@ }, loginOut() { this.CONFIRM('您是否确认退出登录?').then(()=>{ - this.$store.dispatch('clearToken') + this.CLEAR_STORAGE() this.JUMP_TO('/pages/login') }) } diff --git a/monitorMobile/pages/work/passengerFlow/index.vue b/monitorMobile/pages/work/passengerFlow/index.vue index 8638b67..a6b0524 100644 --- a/monitorMobile/pages/work/passengerFlow/index.vue +++ b/monitorMobile/pages/work/passengerFlow/index.vue @@ -37,7 +37,6 @@ -