From 6afaaae3bca9ecb5add2773c60e227b3e6a5eb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=7E=E6=B5=B7=7E=E7=88=B1=E6=B5=B7=E7=88=B1?= =?UTF-8?q?=E6=B5=B7=7E=E5=8F=B3?= <1828712314@qq.com> Date: Thu, 23 Jan 2025 17:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 - App.vue | 48 ++-- api/system/dict.js | 12 + api/system/user.js | 50 ++-- main.js | 3 +- manifest.json | 2 +- pages/login.vue | 118 +++++---- permission.js | 47 ++-- store/modules/user.js | 18 +- sub/owner/edit.vue | 268 ++++++++++++++------ uni_modules/s-components/s-header/index.vue | 111 ++++---- utils/dict.js | 8 + utils/request.js | 2 - utils/ruoyi.js | 80 +++--- utils/upload.js | 136 +++++----- 15 files changed, 534 insertions(+), 378 deletions(-) create mode 100644 api/system/dict.js create mode 100644 utils/dict.js diff --git a/.gitignore b/.gitignore index 5ff51cc..29f016c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,8 @@ -###################################################################### -# Build Tools - /unpackage/* /node_modules/* - -###################################################################### -# Development Tools - /.idea/* /.vscode/* /.hbuilderx/* - package-lock.json yarn.lock -/unpackage/ diff --git a/App.vue b/App.vue index 6a5b013..65781a9 100644 --- a/App.vue +++ b/App.vue @@ -4,30 +4,30 @@ import store from '@/store' import { getAccessToken } from '@/utils/auth' export default { - onLaunch: function () { - this.initApp() - }, - methods: { - // 初始化应用 - async initApp() { - await uni.hideTabBar() - uni.hideTabBar({ - animation: false - }) - // 初始化应用配置 - this.initConfig() - // 检查用户登录状态 - // this.checkLogin() - }, - initConfig() { - this.globalData.config = config - }, - checkLogin() { - if (!getAccessToken()) { - this.$tab.reLaunch('/pages/login') - } - } - } + onLaunch: function () { + this.initApp() + }, + methods: { + // 初始化应用 + async initApp() { + await uni.hideTabBar() + uni.hideTabBar({ + animation: false + }) + // 初始化应用配置 + this.initConfig() + // 检查用户登录状态 + this.checkLogin() + }, + initConfig() { + this.globalData.config = config + }, + checkLogin() { + if (!getAccessToken()) { + this.$tab.reLaunch('/pages/login') + } + } + } } diff --git a/api/system/dict.js b/api/system/dict.js new file mode 100644 index 0000000..17abb24 --- /dev/null +++ b/api/system/dict.js @@ -0,0 +1,12 @@ +import request from '@/utils/request' + +/** + * 获取字典 + */ +export function getDictBatchByType(params) { + return request({ + url: `/system/dict-data/lists_dict_type`, + method: 'GET', + params + }) +} \ No newline at end of file diff --git a/api/system/user.js b/api/system/user.js index 59e9304..2ca9286 100644 --- a/api/system/user.js +++ b/api/system/user.js @@ -3,40 +3,40 @@ import request from '@/utils/request' // 用户密码重置 export function updateUserPwd(oldPassword, newPassword) { - const data = { - oldPassword, - newPassword - } - return request({ - url: '/system/user/profile/update-password', - method: 'PUT', - params: data - }) + const data = { + oldPassword, + newPassword + } + return request({ + url: '/system/user/profile/update-password', + method: 'PUT', + params: data + }) } // 查询用户个人信息 export function getUserProfile() { - return request({ - url: '/system/user/profile/get', - method: 'GET' - }) + return request({ + url: '/system/user/profile/get', + method: 'GET' + }) } // 修改用户个人信息 export function updateUserProfile(data) { - return request({ - url: '/system/user/profile/update', - method: 'PUT', - data: data - }) + return request({ + url: '/system/user/profile/update', + method: 'PUT', + data: data + }) } // 用户头像上传 export function uploadAvatar(data) { - return upload({ - url: '/system/user/profile/update-avatar', - method: 'PUT', - name: data.name, - filePath: data.filePath - }) -} + return upload({ + url: '/admin-api/system/user/profile/update-avatar', + method: 'PUT', + name: data.name, + filePath: data.filePath + }) +} \ No newline at end of file diff --git a/main.js b/main.js index 69cb804..5adc14d 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,7 @@ import App from './App' import store from './store' // store import plugins from './plugins' // plugins import './permission' // permission - +import * as dict from '@/utils/dict.js' // 引入uView import uView from '@/uni_modules/uview-ui' @@ -14,6 +14,7 @@ Vue.config.productionTip = false // 挂载vuex Vue.prototype.$store = store +Vue.prototype.$dict = dict App.mpType = 'app' diff --git a/manifest.json b/manifest.json index b875a5e..d58f663 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "appid": "__UNI__25A9D80", "description": "", "versionName": "1.0.0", - "versionCode": "100", + "versionCode": 1, "transformPx": false, "app-plus": { "usingComponents": true, diff --git a/pages/login.vue b/pages/login.vue index d99ea29..84c765e 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -1,60 +1,82 @@ diff --git a/permission.js b/permission.js index e3ef650..c1a1b3d 100644 --- a/permission.js +++ b/permission.js @@ -22,27 +22,28 @@ function checkWhite(url) { // 页面跳转验证拦截器 let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"] list.forEach(item => { - // uni.addInterceptor(item, { - // invoke(to) { - // if (getAccessToken()) { - // if (to.path === loginPage) { - // uni.reLaunch({ - // url: "/" - // }) - // } - // return true - // } else { - // if (checkWhite(to.url)) { - // return true - // } - // uni.reLaunch({ - // url: loginPage - // }) - // return false - // } - // }, - // fail(err) { - // console.log(err) - // } - // }) + uni.addInterceptor(item, { + invoke(to) { + console.log('addInterceptor', to); + if (getAccessToken()) { + if (to.path === loginPage) { + uni.reLaunch({ + url: "/" + }) + } + return true + } else { + if (checkWhite(to.url)) { + return true + } + uni.reLaunch({ + url: loginPage + }) + return false + } + }, + fail(err) { + console.log(err) + } + }) }) \ No newline at end of file diff --git a/store/modules/user.js b/store/modules/user.js index 8fe0708..ffaab75 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -26,10 +26,6 @@ const user = { SET_ID: (state, id) => { state.id = id }, - SET_NAME: (state, name) => { - state.name = name - storage.set(constant.name, name) - }, SET_AVATAR: (state, avatar) => { state.avatar = avatar storage.set(constant.avatar, avatar) @@ -51,10 +47,11 @@ const user = { }, userInfo) { return new Promise((resolve, reject) => { login(userInfo).then(res => { - console.log('Login', res); - res = res.data; + const { + data + } = res // 设置 token - setToken(res) + setToken(data) resolve() }).catch(error => { reject(error) @@ -69,19 +66,16 @@ const user = { }) { return new Promise((resolve, reject) => { getInfo().then(res => { - res = res.data; // 读取 data 数据 - const user = res.user + const user = res.data.user const avatar = (user == null || user.avatar === "" || user.avatar == null) ? require( "@/static/images/avatar.jpg") : user.avatar - const nickname = (user == null || user.nickname === "" || user.nickname == null) ? "" : user - .nickname if (res.roles && res.roles.length > 0) { commit('SET_ROLES', res.roles) commit('SET_PERMISSIONS', res.permissions) } else { commit('SET_ROLES', ['ROLE_DEFAULT']) } - commit('SET_NAME', nickname) + commit('SET_ID', res.data.user.id) commit('SET_AVATAR', avatar) resolve(res) }).catch(error => { diff --git a/sub/owner/edit.vue b/sub/owner/edit.vue index bf414df..541a1f8 100644 --- a/sub/owner/edit.vue +++ b/sub/owner/edit.vue @@ -1,87 +1,205 @@ diff --git a/uni_modules/s-components/s-header/index.vue b/uni_modules/s-components/s-header/index.vue index 73a230f..0027906 100644 --- a/uni_modules/s-components/s-header/index.vue +++ b/uni_modules/s-components/s-header/index.vue @@ -1,67 +1,68 @@ diff --git a/utils/dict.js b/utils/dict.js new file mode 100644 index 0000000..2c900b7 --- /dev/null +++ b/utils/dict.js @@ -0,0 +1,8 @@ +/** + * 回显字典值 + * @param {Object} dict + * @param {Object} value + */ +export function echoDicValue(dict, value) { + return dict.find(d => d.value == value.toString()).label || '' +} \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index 39434b8..8be7a2e 100644 --- a/utils/request.js +++ b/utils/request.js @@ -63,8 +63,6 @@ const request = config => { } else if (code !== 200) { toast(msg) reject(code) - } else { - toast(msg) } resolve(res.data) }) diff --git a/utils/ruoyi.js b/utils/ruoyi.js index fb60217..5bc3a70 100644 --- a/utils/ruoyi.js +++ b/utils/ruoyi.js @@ -5,43 +5,43 @@ // 日期格式化 export function parseTime(time, pattern) { - if (arguments.length === 0 || !time) { - return null - } - const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' - let date - if (typeof time === 'object') { - date = time - } else { - if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { - time = parseInt(time) - } else if (typeof time === 'string') { - time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm),''); - } - if ((typeof time === 'number') && (time.toString().length === 10)) { - time = time * 1000 - } - date = new Date(time) - } - const formatObj = { - y: date.getFullYear(), - m: date.getMonth() + 1, - d: date.getDate(), - h: date.getHours(), - i: date.getMinutes(), - s: date.getSeconds(), - a: date.getDay() - } - const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { - let value = formatObj[key] - // Note: getDay() returns 0 on Sunday - if (key === 'a') { - return ['日', '一', '二', '三', '四', '五', '六'][value] - } - if (result.length > 0 && value < 10) { - value = '0' + value - } - return value || 0 - }) - return time_str -} + if (arguments.length === 0 || !time) { + return null + } + const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time + } else { + if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { + time = parseInt(time) + } else if (typeof time === 'string') { + time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), ''); + } + if ((typeof time === 'number') && (time.toString().length === 10)) { + time = time * 1000 + } + date = new Date(time) + } + const formatObj = { + y: date.getFullYear(), + m: date.getMonth() + 1, + d: date.getDate(), + h: date.getHours(), + i: date.getMinutes(), + s: date.getSeconds(), + a: date.getDay() + } + const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { + let value = formatObj[key] + // Note: getDay() returns 0 on Sunday + if (key === 'a') { + return ['日', '一', '二', '三', '四', '五', '六'][value] + } + if (result.length > 0 && value < 10) { + value = '0' + value + } + return value || 0 + }) + return time_str +} \ No newline at end of file diff --git a/utils/upload.js b/utils/upload.js index fb6b379..bd29a23 100644 --- a/utils/upload.js +++ b/utils/upload.js @@ -1,73 +1,83 @@ import store from '@/store' import config from '@/config' -import { getAccessToken } from '@/utils/auth' +import { + getAccessToken +} from '@/utils/auth' import errorCode from '@/utils/errorCode' -import { toast, showConfirm, tansParams } from '@/utils/common' +import { + toast, + showConfirm, + tansParams +} from '@/utils/common' let timeout = 10000 const baseUrl = config.baseUrl const upload = config => { - // 是否需要设置 token - const isToken = (config.headers || {}).isToken === false - config.header = config.header || {} - if (getAccessToken() && !isToken) { - config.header['Authorization'] = 'Bearer ' + getAccessToken() - } - // get请求映射params参数 - if (config.params) { - let url = config.url + '?' + tansParams(config.params) - url = url.slice(0, -1) - config.url = url - } - // 设置租户 TODO 芋艿:强制 1 先 - config.header['tenant-id'] = '1'; - return new Promise((resolve, reject) => { - uni.uploadFile({ - timeout: config.timeout || timeout, - url: baseUrl + config.url, - filePath: config.filePath, - name: config.name || 'file', - header: config.header, - formData: config.formData, - method: config.method || 'post', - success: (res) => { - let result = JSON.parse(res.data) - const code = result.code || 200 - const msg = errorCode[code] || result.msg || errorCode['default'] - if (code === 200) { - resolve(result) - } else if (code == 401) { - showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => { - if (res.confirm) { - store.dispatch('LogOut').then(res => { - uni.reLaunch({ url: '/pages/login/login' }) - }) - } - }) - reject('无效的会话,或者会话已过期,请重新登录。') - } else if (code === 500) { - toast(msg) - reject('500') - } else if (code !== 200) { - toast(msg) - reject(code) - } - }, - fail: (error) => { - let { message } = error - if (message == 'Network Error') { - message = '后端接口连接异常' - } else if (message.includes('timeout')) { - message = '系统接口请求超时' - } else if (message.includes('Request failed with status code')) { - message = '系统接口' + message.substr(message.length - 3) + '异常' - } - toast(message) - reject(error) - } - }) - }) + // 是否需要设置 token + const isToken = (config.headers || {}).isToken === false + config.header = config.header || {} + if (getAccessToken() && !isToken) { + config.header['Authorization'] = 'Bearer ' + getAccessToken() + } + // get请求映射params参数 + if (config.params) { + let url = config.url + '?' + tansParams(config.params) + url = url.slice(0, -1) + config.url = url + } + // 设置租户 TODO 芋艿:强制 1 先 + config.header['tenant-id'] = '1'; + return new Promise((resolve, reject) => { + uni.uploadFile({ + timeout: config.timeout || timeout, + url: baseUrl + config.url, + filePath: config.filePath, + name: config.name || 'file', + header: config.header, + formData: config.formData, + method: config.method || 'post', + success: (res) => { + let result = JSON.parse(res.data) + const code = result.code || 200 + const msg = errorCode[code] || result.msg || errorCode['default'] + if (code === 200) { + resolve(result) + } else if (code == 401) { + showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => { + if (res.confirm) { + store.dispatch('LogOut').then(res => { + uni.reLaunch({ + url: '/pages/login/login' + }) + }) + } + }) + reject('无效的会话,或者会话已过期,请重新登录。') + } else if (code === 500) { + toast(msg) + reject('500') + } else if (code !== 200) { + toast(msg) + reject(code) + } + }, + fail: (error) => { + let { + message + } = error + if (message == 'Network Error') { + message = '后端接口连接异常' + } else if (message.includes('timeout')) { + message = '系统接口请求超时' + } else if (message.includes('Request failed with status code')) { + message = '系统接口' + message.substr(message.length - 3) + '异常' + } + toast(message) + reject(error) + } + }) + }) } -export default upload +export default upload \ No newline at end of file