diff --git a/api/request.js b/api/request.js index 0765a65..e28c0e9 100644 --- a/api/request.js +++ b/api/request.js @@ -3,75 +3,88 @@ import Request from 'luch-request' import config from '@/config' import { getToken } from '@/utils/auth.js' // import store from '@/store'; - -const baseUrl = config.baseUrl - + +let baseUrl = '' +if (uni.getStorageSync('jwtToken')) { + baseUrl = config.baseUrl +} else { + baseUrl = config.loginBaseUrl +} +console.log('baseUrl-请求', baseUrl) + const http = new Request({ - // baseURL: "http://172.16.19.33:8081/prod-api", //设置请求的base url - // baseURL: "/dev-api", //设置请求的base url - baseURL: baseUrl, //设置请求的base url - timeout: 300000, //超时时长5分钟, - header: { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Authorization':getToken() - } + // baseURL: "http://172.16.19.33:8081/prod-api", //设置请求的base url + // baseURL: "/dev-api", //设置请求的base url + baseURL: baseUrl, //设置请求的base url + timeout: 300000, //超时时长5分钟, + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + Authorization: getToken() + } }) //请求拦截器 -http.interceptors.request.use((config) => { // 可使用async await 做异步操作 - // console.log('请求拦截器'); - - // // console.log(config); - // if (config.method === 'POST' && config.data.h) { - // config.header = { - // ...config.header, - // 'Content-Type': 'application/json;charset=UTF-8;' - // } - // // config.data = JSON.stringify(config.data); - // }else{ - // config.header = { - // ...config.header, - // // 'uToken':Vue.prototype.$store.state.token, - // 'content-type':'application/x-www-form-urlencoded', - // } - // } +http.interceptors.request.use( + config => { + // 可使用async await 做异步操作 + // console.log('请求拦截器'); - // // if(getToken()){ - // // console.log(">>>>>>",getToken()); - // // config.header.Authorization='Bearer ' +getToken(); - // // } - if(config.data&&!config.data.noShowLoading){ - uni.showLoading({ - title: '加载中' - }); - } - console.log(config.data) - - return config -}, error => { - return Promise.resolve(error) -}) + // // console.log(config); + // if (config.method === 'POST' && config.data.h) { + // config.header = { + // ...config.header, + // 'Content-Type': 'application/json;charset=UTF-8;' + // } + // // config.data = JSON.stringify(config.data); + // }else{ + // config.header = { + // ...config.header, + // // 'uToken':Vue.prototype.$store.state.token, + // 'content-type':'application/x-www-form-urlencoded', + // } + // } + + // // if(getToken()){ + // // console.log(">>>>>>",getToken()); + // // config.header.Authorization='Bearer ' +getToken(); + // // } + if (config.data && !config.data.noShowLoading) { + uni.showLoading({ + title: '加载中' + }) + } + console.log(config.data) + + return config + }, + error => { + return Promise.resolve(error) + } +) // 响应拦截器 -http.interceptors.response.use((response) => { - // console.log('响应拦截器'); - uni.hideLoading(); - return response -}, (error) => { - if (error.statusCode == 302) { - uni.clearStorageSync(); - uni.switchTab({ - url: "/pages/gzt/index" - }) - } - //未登录时清空缓存跳转 - if (error.statusCode == 401) { - uni.clearStorageSync(); - uni.switchTab({ - // url: "/pages/changguan/subscribe-fill" - url: "/pages/gzt/index" - }) - } - return Promise.resolve(error) -}) -export default http; \ No newline at end of file +http.interceptors.response.use( + response => { + // console.log('响应拦截器'); + uni.hideLoading() + return response + }, + error => { + if (error.statusCode == 302) { + uni.clearStorageSync() + uni.switchTab({ + url: '/pages/gzt/index' + }) + } + //未登录时清空缓存跳转 + if (error.statusCode == 401) { + uni.clearStorageSync() + uni.switchTab({ + // url: "/pages/changguan/subscribe-fill" + url: '/pages/gzt/index' + }) + } + return Promise.resolve(error) + } +) +export default http diff --git a/config.js b/config.js index 9cf7cd2..a0dca32 100644 --- a/config.js +++ b/config.js @@ -1,10 +1,11 @@ // 应用全局配置 module.exports = { // baseUrl:'/prod-api', - baseUrl:'http://112.29.103.165:1616', + loginBaseUrl:'http://112.29.103.165:1616', + // baseUrl:'http://192.168.0.14:2900', + baseUrl:'http://192.168.0.32:2900', loginUrl: 'http://112.29.103.165:1616', - login: 'http://192.168.0.14:19200', - // baseUrl:'http://192.168.0.137:2900', + login: 'http://192.168.0.32:19200', // 图片展示基础地址 fileUrl:'http://192.168.0.137:2909/exam-file/', // 上传文件地址 diff --git a/manifest.json b/manifest.json index 2a0409a..850d120 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name" : "作业管控智慧平台", - "appid" : "__UNI__0EB2E47", + "appid" : "__UNI__4165875", "description" : "作业管控智慧平台", "versionName" : "1.0.4", "versionCode" : 104, @@ -71,33 +71,33 @@ "icons" : { "ios" : { "iphone" : { - "app@2x" : "unpackage/res/icons/120x120.png", - "app@3x" : "unpackage/res/icons/180x180.png", - "spotlight@2x" : "unpackage/res/icons/80x80.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@3x" : "unpackage/res/icons/120x120.png" + "app@2x" : "", + "app@3x" : "", + "spotlight@2x" : "", + "notification@2x" : "", + "notification@3x" : "", + "settings@2x" : "", + "settings@3x" : "", + "spotlight@3x" : "" }, - "appstore" : "unpackage/res/icons/1024x1024.png", + "appstore" : "", "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" + "app" : "", + "app@2x" : "", + "notification" : "", + "notification@2x" : "", + "proapp@2x" : "", + "settings" : "", + "settings@2x" : "", + "spotlight" : "", + "spotlight@2x" : "" } }, "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" + "hdpi" : "", + "xhdpi" : "", + "xxhdpi" : "", + "xxxhdpi" : "" } }, "splashscreen" : { diff --git a/pages.json b/pages.json index ff2c78d..a387fee 100644 --- a/pages.json +++ b/pages.json @@ -201,6 +201,20 @@ { "navigationBarTitleText" : "人脸识别" } + }, + { + "path" : "pages/YNEduApp/user/myMsg", + "style" : + { + "navigationBarTitleText" : "消息通知" + } + }, + { + "path" : "pages/YNEduApp/user/msgDetail", + "style" : + { + "navigationBarTitleText" : "消息详情" + } } ], "globalStyle": { diff --git a/pages/YNEduApp/index/index.vue b/pages/YNEduApp/index/index.vue index 737558a..39b21fa 100644 --- a/pages/YNEduApp/index/index.vue +++ b/pages/YNEduApp/index/index.vue @@ -5,7 +5,7 @@ @@ -28,18 +28,33 @@ scrollable color="#808080" background-color="transparent" - text="uni-app 版正式发布,开发一次,同时发布iOS、Android、H5、微信小程序、支付宝小程序、百度小程序、头条小程序等7大平台。" + :text="msgList.length > 0 ? msgList[0].noticeName : '暂无消息'" + @click="handleMsg" /> 我的任务 - + + + {{ item.name }} + {{ item.userName }} + {{ item.validityDate }} + + + {{ item.trainPercentage }}% + + 可联系管理员发布 - + @@ -48,12 +63,14 @@ diff --git a/pages/YNEduApp/user/msgDetail.vue b/pages/YNEduApp/user/msgDetail.vue new file mode 100644 index 0000000..4a82a86 --- /dev/null +++ b/pages/YNEduApp/user/msgDetail.vue @@ -0,0 +1,43 @@ + + + + {{ noticeName }} + + + + + + + + diff --git a/pages/YNEduApp/user/myMsg.vue b/pages/YNEduApp/user/myMsg.vue new file mode 100644 index 0000000..1e95c67 --- /dev/null +++ b/pages/YNEduApp/user/myMsg.vue @@ -0,0 +1,72 @@ + + + + {{ item.noticeName }} + {{ item.createTime }} + + + + + + + diff --git a/pages/YNEduApp/user/user.vue b/pages/YNEduApp/user/user.vue index d19275f..c334d30 100644 --- a/pages/YNEduApp/user/user.vue +++ b/pages/YNEduApp/user/user.vue @@ -9,7 +9,7 @@ {{ className }} - 修改资料 + 修改资料 @@ -56,18 +56,19 @@ export default { totalCer: 26 }, allDuration: 0, - value: 0, // + value: 0, // secList: [ { id: 1, title: '切换门户', src: '/static/eduImg/changeGate.png', path: 'changeGate' }, { id: 2, title: '人脸识别', src: '/static/eduImg/faceScan.png', path: 'faceScan' }, { id: 3, title: '我的消息', src: '/static/eduImg/myMsg.png', path: 'myMsg' }, { id: 4, title: '设置', src: '/static/eduImg/settings.png', path: 'settings' } ], - token: '' + token: uni.getStorageSync('App-Token') } }, onLoad() { - this.token = uni.getStorageSync('App-Token') + // this.token = uni.getStorageSync('App-Token') + console.log('🚀 ~ onLoad ~ this.token:', this.token) this.getUserInfo() this.getLearnStats() }, @@ -98,7 +99,7 @@ export default { this.className = req.data.loginUser.sysUser.className this.facePath = config.fileUrl + req.data.loginUser.sysUser.facePath uni.setStorageSync('facePath', this.facePath) - + console.log('🚀 ~ getUserInfo ~ this.facePath:', this.facePath) }, fail: err => { @@ -112,16 +113,25 @@ export default { url: config.baseUrl + '/exam-student/personalCenter/getStudyAndCer', method: 'post', header: { - 'Content-Type': 'application/x-www-form-urlencoded', Authorization: this.token }, data: {}, success: res => { console.log('🚀 ~ getLearnStats ~ res:', res) - this.allDuration = res.data.data.allDuration - this.value = res.data.data.value + this.allDuration = (res.data && res.data.data.allDuration) || 0 + this.value = (res.data && res.data.data.value) || 0 } }) + }, + // 修改资料 + handleEdit() { + const params = { + userName: this.userName, + className: this.className + } + uni.navigateTo({ + url: '/pages/YNEduApp/user/editProfile?params=' + JSON.stringify(params) + }) } } } diff --git a/utils/request.js b/utils/request.js index e3d7944..23e2dab 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,11 +1,17 @@ import store from '@/store' import config from '@/config' -import { getToken } from '@/utils/auth' +import { getToken, setToken } from '@/utils/auth' import errorCode from '@/utils/errorCode' import { toast, showConfirm, tansParams } from '@/utils/common' let timeout = 10000 -const baseUrl = config.baseUrl +let baseUrl = '' +if (uni.getStorageSync('jwtToken')) { + baseUrl = config.baseUrl +} else { + baseUrl = config.loginBaseUrl +} +console.log('baseUrl-请求', baseUrl) const request = config => { // 是否需要设置 token @@ -13,6 +19,15 @@ const request = config => { config.header = config.header || {} if (getToken() && !isToken) { config.header['Authorization'] = 'Bearer ' + getToken() + } else { + // 没有token - 去登录 + // store.dispatch('LogOut').then(() => { + // uni.reLaunch({ url: '/pages/login' }) + // }) + // const token = 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjozMSwidXNlcl9rZXkiOiJiZmJmOGEzZC1hYTc1LTQ4MzQtOGM3NC0yZmQzOTEwZDllYzAiLCJ1c2VybmFtZSI6IuaWueS6riJ9.kv1WmthbgTrqapbsGLvevk-nwbWbYJMniyjj8DC3BSnQjCwm8csQ5GaNpfsLFFFYIHBYa8CrN_sBxXhDKOfR_A' + // const userId = 31 + // setUserId(userId) + // setToken(token) } // get请求映射params参数 if (config.params) { @@ -20,23 +35,25 @@ const request = config => { url = url.slice(0, -1) config.url = url } - if (config.method === 'post' ) { - config.header = { - ...config.header, - 'Content-Type': 'application/x-www-form-urlencoded' - } - // config.data = JSON.stringify(config.data); + if (config.method === 'post') { + config.header = { + ...config.header, + 'Content-Type': 'application/x-www-form-urlencoded' + } + // config.data = JSON.stringify(config.data); } return new Promise((resolve, reject) => { - uni.request({ + uni + .request({ method: config.method || 'get', - timeout: config.timeout || timeout, - url: config.baseUrl || baseUrl + config.url, + timeout: config.timeout || timeout, + url: baseUrl + config.url, data: config.data, header: config.header, dataType: 'json' - }).then(response => { - // console.log(response) + }) + .then(response => { + // console.log(response) let [error, res] = response if (error) { toast('后端接口连接异常')