From 03e023cbc42ad36bc4e76829c962152a57592f7f Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 28 Mar 2025 23:23:07 +0800 Subject: [PATCH] update vue3 --- config.js | 2 +- index.html | 17 ++++ main.js | 31 ++++--- manifest.json | 2 +- pages/login.vue | 153 ++++++++++++++++++----------------- pages/mine/about/index.vue | 12 +-- pages/mine/help/index.vue | 82 +++++++++---------- pages/mine/index.vue | 89 ++++++++++---------- pages/mine/info/edit.vue | 121 ++++++++++++++------------- pages/mine/info/index.vue | 35 ++++---- pages/mine/pwd/index.vue | 94 ++++++++++----------- pages/mine/setting/index.vue | 50 ++++++------ pages/register.vue | 137 +++++++++++++++---------------- pages/work/index.vue | 47 +++++------ plugins/index.js | 16 ++-- store/index.js | 8 +- utils/request.js | 7 +- utils/upload.js | 88 ++++++++++---------- 18 files changed, 477 insertions(+), 514 deletions(-) create mode 100644 index.html diff --git a/config.js b/config.js index 333f63e..4a31f28 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,5 @@ // 应用全局配置 -module.exports = { +export default { baseUrl: 'https://vue.ruoyi.vip/prod-api', // baseUrl: 'http://localhost:8080', // 应用信息 diff --git a/index.html b/index.html new file mode 100644 index 0000000..3c1a975 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/main.js b/main.js index e742834..4b783a9 100644 --- a/main.js +++ b/main.js @@ -1,17 +1,14 @@ -import Vue from 'vue' -import App from './App' -import store from './store' // store -import plugins from './plugins' // plugins -import './permission' // permission -Vue.use(plugins) - -Vue.config.productionTip = false -Vue.prototype.$store = store - -App.mpType = 'app' - -const app = new Vue({ - ...App -}) - -app.$mount() +import { createSSRApp } from 'vue' +import App from './App' +import store from './store' // store +import { install } from './plugins' // plugins +import './permission' // permission + +export function createApp() { + const app = createSSRApp(App) + app.use(store) + install(app) + return { + app + } +} diff --git a/manifest.json b/manifest.json index 03ee107..21b8f4b 100644 --- a/manifest.json +++ b/manifest.json @@ -53,7 +53,7 @@ }, "usingComponents" : true }, - "vueVersion" : "2", + "vueVersion" : "3", "h5" : { "template" : "static/index.html", "devServer" : { diff --git a/pages/login.vue b/pages/login.vue index 7ca13c3..0be013d 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -38,86 +38,88 @@ - diff --git a/pages/mine/about/index.vue b/pages/mine/about/index.vue index baffb0d..85eb5be 100644 --- a/pages/mine/about/index.vue +++ b/pages/mine/about/index.vue @@ -43,15 +43,9 @@ - diff --git a/pages/work/index.vue b/pages/work/index.vue index fed7f1d..04c6161 100644 --- a/pages/work/index.vue +++ b/pages/work/index.vue @@ -74,35 +74,24 @@ - diff --git a/plugins/index.js b/plugins/index.js index 22bb75c..015b568 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -2,13 +2,11 @@ import tab from './tab' import auth from './auth' import modal from './modal' -export default { - install(Vue) { - // 页签操作 - Vue.prototype.$tab = tab - // 认证对象 - Vue.prototype.$auth = auth - // 模态框对象 - Vue.prototype.$modal = modal - } +export function install(app) { + // 页签操作 + app.config.globalProperties.$tab = tab + // 认证对象 + app.config.globalProperties.$auth = auth + // 模态框对象 + app.config.globalProperties.$modal = modal } diff --git a/store/index.js b/store/index.js index cb58786..d787e08 100644 --- a/store/index.js +++ b/store/index.js @@ -1,15 +1,11 @@ -import Vue from 'vue' -import Vuex from 'vuex' +import { createStore } from "vuex" import user from '@/store/modules/user' import getters from './getters' -Vue.use(Vuex) - -const store = new Vuex.Store({ +const store = createStore({ modules: { user }, getters }) - export default store diff --git a/utils/request.js b/utils/request.js index 80c0738..de57fbf 100644 --- a/utils/request.js +++ b/utils/request.js @@ -29,12 +29,7 @@ const request = config => { header: config.header, dataType: 'json' }).then(response => { - let [error, res] = response - if (error) { - toast('后端接口连接异常') - reject('后端接口连接异常') - return - } + const res = response const code = res.data.code || 200 const msg = errorCode[code] || res.data.msg || errorCode['default'] if (code === 401) { diff --git a/utils/upload.js b/utils/upload.js index 4d9d431..04bd7bb 100644 --- a/utils/upload.js +++ b/utils/upload.js @@ -7,7 +7,7 @@ import { toast, showConfirm, tansParams } from '@/utils/common' let timeout = 10000 const baseUrl = config.baseUrl -const upload = config => { +export default function upload(config) { // 是否需要设置 token const isToken = (config.headers || {}).isToken === false config.header = config.header || {} @@ -21,50 +21,50 @@ const upload = config => { config.url = url } 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, - 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) + uni.uploadFile({ + timeout: config.timeout || timeout, + url: baseUrl + config.url, + filePath: config.filePath, + name: config.name || 'file', + header: config.header, + formData: config.formData, + 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 +