diff --git a/monitorMobile/api/user.js b/monitorMobile/api/user.js index f3df701..0199891 100644 --- a/monitorMobile/api/user.js +++ b/monitorMobile/api/user.js @@ -1,85 +1,18 @@ import http from '@/http/api.js' -// 获取token -export const token = (tenantId, username, password, type) => { +let url = '/api/sys/auth/b' +// 登录 +export const login = (data) => { return http.request({ - url: '/api/blade-auth/oauth/token', + url: url + '/login', method: 'POST', - header: { - 'Tenant-Id': tenantId - }, - params: { - tenantId, - username, - password, - grant_type: "password", - scope: "all", - type - } + data }) } -export const getTenantId = (params) => { +// 获取登录用户信息 +export const getLoginUser = (params) => { return http.request({ - url: '/api/blade-auth/oauth/getTenantId', - method: 'get', - params: { - ...params - } - }) -} - -export const refreshToken = (refresh_token, tenantId) => { - return http.request({ - url: '/api/blade-auth/oauth/token', - method: 'post', - header: { - 'Tenant-Id': tenantId - }, - params: { - tenantId, - refresh_token, - grant_type: "refresh_token", - scope: "all", - } - }) -} - -// 获取用户信息 -export const userInfo = () => { - return http.request({ - url: '/api/blade-user/info', - method: 'GET', - }) -} - -// 获取用户信息 -export const getUser = (id) => { - return http.request({ - url: '/api/blade-user/detail', + url: url + '/getLoginUser', method: 'GET', - params: { id } + params }) -} -/* 修改用户信息 */ -export const updateInfo = (row) => { - return http.request({ - url: '/api/blade-user/update-info', - method: 'post', - data: row - }) -} -// 修改密码 -export const updatePassword = (data) => { - return http.request({ - url: '/api/blade-user/update-password', - method: 'post', - params: data - }) -} -// 修改密码 -export const passwordCheck = (data) => { - return http.request({ - url: '/api/blade-user/passwordCheck', - method: 'post', - params: data - }) -} +} \ No newline at end of file diff --git a/monitorMobile/common/mixins.vue b/monitorMobile/common/mixins.vue index 6947778..06eb62c 100644 --- a/monitorMobile/common/mixins.vue +++ b/monitorMobile/common/mixins.vue @@ -6,10 +6,6 @@ import { Base64 } from '@/utils/base64.js'; - import { - clientId, - clientSecret - } from '@/common/setting' export default{ methods:{ // 暂存一个跨页面变量 (与 this.GET_PARAM 成对使用) @@ -58,6 +54,42 @@ return url + query }, + // 获取一个全局变量 + // key 为键名 + GET_GLOBAL(key) { + return this.$store.state[key] + }, + + // 设置一个全局变量 + // key 为键名 + // val 为值 + SET_GLOBAL(key, val) { + this.$store.commit(key, val) + }, + + // 清空全局变量 + CLEAR_GLOBAL() { + this.$store.commit('clear') + uni.removeStorageSync('token') + }, + // 将数据写入本地缓存 + SET_STORAGE(key, data) { + if (data === null) { + uni.removeStorageSync(key) + } else { + uni.setStorageSync(key, data) + } + }, + + // 获取之前写入本地缓存的数据 + GET_STORAGE(key) { + return uni.getStorageSync(key) + }, + + // 清空本地缓存 + CLEAR_STORAGE() { + uni.clearStorageSync() + }, // 设置页面标题 SET_TITLE(title) { uni.setNavigationBarTitle({ @@ -103,6 +135,10 @@ }); }) }, + // 展示提示框 + // title 为提示文字 + // mask 为是否禁止点击 + // icon 为显示图标,可以改为 'success' TOAST(title){ uni.showToast({ icon: "none", @@ -110,17 +146,18 @@ duration: 2000, }); }, + // 停止展示 toast 提示框 + HIDE_TOAST() { + uni.hideToast() + }, UPLOAD_FILE(filePath){ let that = this // 假设有token值需要在头部需要携带 let header = {} - let accessToken = uni.getStorageSync('accessToken'); - if (accessToken) { - header['Blade-Auth'] = 'bearer ' + accessToken; + let token = uni.getStorageSync('token'); + if (token) { + config.header['Authorization'] = 'Bearer ' + token; } - // 客户端认证参数 - header['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret); - console.log(filePath) return new Promise(resovle=>{ uni.uploadFile({ url:options.baseURL + '/api/blade-resource/oss/endpoint/put-uplaod-file?bucketName=', @@ -179,18 +216,9 @@ data: item, // 要复制的路径 success: function(res) { resolve(true) - // uni.getClipboardData({ - // success: function(data) { - // resolve(true) - // }, - // fail: function(data1) { - // resolve(false) - // } - // }); } }); }) - }, }, } diff --git a/monitorMobile/common/setting.js b/monitorMobile/common/setting.js index 8db6a83..1bebddd 100644 --- a/monitorMobile/common/setting.js +++ b/monitorMobile/common/setting.js @@ -3,7 +3,6 @@ */ // #ifdef H5 let origin = window.location.origin -console.log(window.location.origin) // #endif module.exports = { // 应用名 @@ -25,16 +24,11 @@ module.exports = { // 小程序接口Url // #ifndef H5 - // devUrl: 'http://192.168.10.46', - devUrl: 'https://www.bjjyp.org.cn/rider',//开发环境接口Url - prodUrl: `https://www.bjjyp.org.cn/rider`,//线上环境接口Url - // prodUrl: 'http://192.168.100.236:1888', - // prodUrl: 'http://114.255.136.189:1888', + devUrl: `${origin}/`,//开发环境接口Url + prodUrl: `${origin}/`,//线上环境接口Url // #endif - - // 后端数据的接收方式application/json;charset=UTF-8或者application/x-www-form-urlencoded;charset=UTF-8 contentType: 'application/json;charset=UTF-8', // 后端返回状态码 @@ -43,15 +37,8 @@ module.exports = { successCode: 200, // 登录失效code invalidCode: 401, - // 客户端ID - clientId: 'rider', - // 客户端密钥 - clientSecret: 'rider_secret', // token过期时间 tokenTime: 3000, - switchMode: true, // 是否开启部门切换模式 - //本地 - previewUrl: 'http://cp.qjkjedu.com/onlinePreview', - //金隅生产 - // previewUrl: 'https://www.bjjyp.org.cn/preview/onlinePreview', + //文件预览地址 + previewUrl: '', } diff --git a/monitorMobile/http/api.js b/monitorMobile/http/api.js index 8c1a1cc..c900b0d 100644 --- a/monitorMobile/http/api.js +++ b/monitorMobile/http/api.js @@ -1,52 +1,22 @@ -import { - devUrl, - clientId, - clientSecret -} from '@/common/setting' import { options } from '@/http/config.js'; -import { - Base64 -} from '@/utils/base64.js'; import Request from '@/utils/luch-request/index.js'; const http = new Request(options); http.interceptors.request.use((config) => { // 可使用async await 做异步操作 - // 假设有token值需要在头部需要携带 - let accessToken = uni.getStorageSync('accessToken'); - if (accessToken) { - config.header['Blade-Auth'] = 'bearer ' + accessToken; + let token = uni.getStorageSync('token'); + if (token) { + config.header['Authorization'] = 'Bearer ' + token; } - // 客户端认证参数 - config.header['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret); - + // #ifndef H5 let url = config.url if (process.env.NODE_ENV == 'development' && !url.startsWith("http")) { - // url = url.substring(url.indexOf('/api') + 4) config.url = url } // #endif - // 额外参数 - // config.data = config.data || {}; - // config.data.pf = uni.getSystemInfoSync().platform; - // config.data.sys = uni.getSystemInfoSync().system; - - // 演示custom 用处 - // if (config.custom.auth) { - // config.header.token = 'token' - // } - // if (config.custom.loading) { - // uni.showLoading() - // } - /** - /* 演示 - if (!token) { // 如果token不存在,return Promise.reject(config) 会取消本次请求 - return Promise.reject(config) - } - **/ return config }, config => { // 可使用async await 做异步操作 return Promise.reject(config) @@ -58,7 +28,7 @@ http.interceptors.response.use((response) => { } // 服务端返回的状态码不等于200,则reject() if (response.data.code && response.data.code !== 200) { - setTimeout(()=>{ + setTimeout(() => { uni.showToast({ title: response.data.msg, icon: 'none' @@ -69,20 +39,39 @@ http.interceptors.response.use((response) => { return response.data; }, (response) => { /* 对响应错误做点什么 (statusCode !== 200)*/ - setTimeout(()=>{ + setTimeout(() => { uni.showToast({ title: response.data.msg || response.data.error_description || '网络错误', icon: 'none' }); }) - + if (response.statusCode == 401) { const pages = getCurrentPages() const currentPage = pages[pages.length - 1] uni.redirectTo({ - url: `/pages/login/login?redirect=/${currentPage.route}` + url: `/pages/login?redirect=/${currentPage.route}` }) } return Promise.reject(response) }) -export default http; +/** + * @description 解密 JWT token 的信息 + * @param token jwt token 字符串 + * @returns object + */ +function decryptJWT(token) { + token = token.replace(/_/g, "/").replace(/-/g, "+"); + const json = decodeURIComponent(escape(window.atob(token.split(".")[1]))); + return JSON.parse(json); +} + +/** + * @description 将 JWT 时间戳转换成 Date,主要针对 `exp`,`iat`,`nbf` + * @param timestamp 时间戳 + * @returns Date 对象 + */ +function getJWTDate(timestamp) { + return new Date(timestamp * 1000); +} +export default http; \ No newline at end of file diff --git a/monitorMobile/http/config.js b/monitorMobile/http/config.js index 206323d..33be5e9 100644 --- a/monitorMobile/http/config.js +++ b/monitorMobile/http/config.js @@ -44,6 +44,6 @@ var options = { // previewUrl: 'https://www.bjjyp.org.cn/preview/onlinePreview', // previewUrl: 'http://114.255.136.189:6696/onlinePreview', // previewUrl: 'http://192.168.100.236:85/onlinePreview', - previewUrl: 'http://cp.qjkjedu.com/onlinePreview', + previewUrl: '', }; export { options }; diff --git a/monitorMobile/main.js b/monitorMobile/main.js index 587410e..6ca9977 100644 --- a/monitorMobile/main.js +++ b/monitorMobile/main.js @@ -1,12 +1,9 @@ import App from './App' import Vue from 'vue' -import store from '@/store'; import mixins from '@/common/mixins.vue' - Vue.mixin(mixins) // 引入vuex -Vue.prototype.$u = {} const vuexStore = require("@/store/$u.mixin.js"); Vue.mixin(vuexStore); @@ -34,6 +31,7 @@ export function createApp() { } // #endif +// 添加http实例 import http from '@/http/api.js' Vue.prototype.$http = http diff --git a/monitorMobile/manifest.json b/monitorMobile/manifest.json index 3ccf32f..a3da677 100644 --- a/monitorMobile/manifest.json +++ b/monitorMobile/manifest.json @@ -65,6 +65,21 @@ "mp-toutiao" : { "usingComponents" : true }, + "h5" : { + "devServer" : { + "port" : 1888, + "proxy" : { + "/api" : { + "target" : "http://192.168.10.186:8003", + "changeOrigin" : true, + "pathRewrite" : { + "^/api" : "" + } + } + }, + "https" : false + } + }, "uniStatistics" : { "enable" : false }, diff --git a/monitorMobile/package-lock.json b/monitorMobile/package-lock.json index e2cce77..70203bc 100644 --- a/monitorMobile/package-lock.json +++ b/monitorMobile/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "sm-crypto": "^0.3.13", "uview-ui": "^2.0.36", "vuex": "^3.6.2" }, @@ -801,6 +802,11 @@ "node": ">= 10.13.0" } }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmmirror.com/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==" + }, "node_modules/json-parse-even-better-errors": { "version": "2.3.1", "resolved": "https://registry.npmmirror.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", @@ -1137,6 +1143,14 @@ "randombytes": "^2.1.0" } }, + "node_modules/sm-crypto": { + "version": "0.3.13", + "resolved": "https://registry.npmmirror.com/sm-crypto/-/sm-crypto-0.3.13.tgz", + "integrity": "sha512-ztNF+pZq6viCPMA1A6KKu3bgpkmYti5avykRHbcFIdSipFdkVmfUw2CnpM2kBJyppIalqvczLNM3wR8OQ0pT5w==", + "dependencies": { + "jsbn": "^1.1.0" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmmirror.com/source-map/-/source-map-0.6.1.tgz", diff --git a/monitorMobile/package.json b/monitorMobile/package.json index 3d6d61b..f6edf72 100644 --- a/monitorMobile/package.json +++ b/monitorMobile/package.json @@ -1,5 +1,6 @@ { "dependencies": { + "sm-crypto": "^0.3.13", "uview-ui": "^2.0.36", "vuex": "^3.6.2" }, diff --git a/monitorMobile/pages.json b/monitorMobile/pages.json index 15e2ec6..6c21822 100644 --- a/monitorMobile/pages.json +++ b/monitorMobile/pages.json @@ -2,14 +2,13 @@ "easycom": { "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue" }, - "tabBar":{ - "color":"#777777", - "selectedColor":"#2388FF", - "backgroundColor":"#FFFFFF", - "borderStyle":"white", - "fontSize":"18rpx", - "list": [ - { + "tabBar": { + "color": "#777777", + "selectedColor": "#2388FF", + "backgroundColor": "#FFFFFF", + "borderStyle": "white", + "fontSize": "18rpx", + "list": [{ "pagePath": "pages/earlyWarning/index", "iconPath": "/static/image/tabbar/earlyWarning.png", "selectedIconPath": "/static/image/tabbar/earlyWarning_active.png", @@ -30,6 +29,14 @@ ] }, "pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages + { + "path": "pages/blankPage", + "style": { + "navigationBarTitleText": "", + "enablePullDownRefresh": false, + "navigationStyle": "custom" + } + }, // 预警 { "path": "pages/earlyWarning/index", @@ -54,12 +61,11 @@ } }, { - "path" : "pages/work/returnBed/detail", - "style" : - { - "navigationBarTitleText": "归寝", - "enablePullDownRefresh": false - } + "path": "pages/work/returnBed/detail", + "style": { + "navigationBarTitleText": "归寝", + "enablePullDownRefresh": false + } }, // 客流 { @@ -69,12 +75,11 @@ } }, { - "path" : "pages/work/passengerFlow/detail", - "style" : - { - "navigationBarTitleText": "分片详情", - "enablePullDownRefresh": false - } + "path": "pages/work/passengerFlow/detail", + "style": { + "navigationBarTitleText": "分片详情", + "enablePullDownRefresh": false + } }, // 点名 { @@ -84,12 +89,11 @@ } }, { - "path" : "pages/work/rollCall/detail", - "style" : - { - "navigationBarTitleText": "查看", - "enablePullDownRefresh": false - } + "path": "pages/work/rollCall/detail", + "style": { + "navigationBarTitleText": "查看", + "enablePullDownRefresh": false + } }, // 巡警 { @@ -132,7 +136,7 @@ "navigationStyle": "custom" } } - ], + ], "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "校园监控预警平台", @@ -140,4 +144,4 @@ "backgroundColor": "#F8F8F8" }, "uniIdRouter": {} -} +} \ No newline at end of file diff --git a/monitorMobile/pages/blankPage.vue b/monitorMobile/pages/blankPage.vue new file mode 100644 index 0000000..8426837 --- /dev/null +++ b/monitorMobile/pages/blankPage.vue @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/monitorMobile/pages/login.vue b/monitorMobile/pages/login.vue index 8f5b7ae..c254dfa 100644 --- a/monitorMobile/pages/login.vue +++ b/monitorMobile/pages/login.vue @@ -37,7 +37,10 @@