update vue3

This commit is contained in:
RuoYi
2025-03-28 23:23:07 +08:00
parent fb0656fe14
commit 03e023cbc4
18 changed files with 477 additions and 514 deletions

View File

@@ -1,5 +1,5 @@
// 应用全局配置 // 应用全局配置
module.exports = { export default {
baseUrl: 'https://vue.ruoyi.vip/prod-api', baseUrl: 'https://vue.ruoyi.vip/prod-api',
// baseUrl: 'http://localhost:8080', // baseUrl: 'http://localhost:8080',
// 应用信息 // 应用信息

17
index.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script>
</body>
</html>

31
main.js
View File

@@ -1,17 +1,14 @@
import Vue from 'vue' import { createSSRApp } from 'vue'
import App from './App' import App from './App'
import store from './store' // store import store from './store' // store
import plugins from './plugins' // plugins import { install } from './plugins' // plugins
import './permission' // permission import './permission' // permission
Vue.use(plugins)
export function createApp() {
Vue.config.productionTip = false const app = createSSRApp(App)
Vue.prototype.$store = store app.use(store)
install(app)
App.mpType = 'app' return {
app
const app = new Vue({ }
...App }
})
app.$mount()

View File

@@ -53,7 +53,7 @@
}, },
"usingComponents" : true "usingComponents" : true
}, },
"vueVersion" : "2", "vueVersion" : "3",
"h5" : { "h5" : {
"template" : "static/index.html", "template" : "static/index.html",
"devServer" : { "devServer" : {

View File

@@ -38,86 +38,88 @@
</view> </view>
</template> </template>
<script> <script setup>
import { getCodeImg } from '@/api/login' import { getCodeImg } from '@/api/login'
import store from '@/store'
import { ref, getCurrentInstance } from "vue"
export default { const { proxy } = getCurrentInstance()
data() { const globalConfig = getApp().globalData.config
return { const codeUrl = ref("")
codeUrl: "", // 验证码开关
captchaEnabled: true, const captchaEnabled = ref(true)
// 用户注册开关 // 用户注册开关
register: false, const register = ref(false)
globalConfig: getApp().globalData.config, const loginForm = ref({
loginForm: { username: "admin",
username: "admin", password: "admin123",
password: "admin123", code: "",
code: "", uuid: ""
uuid: "" })
// 用户注册
function handleUserRegister() {
proxy.$tab.redirectTo(`/pages/register`)
}
// 隐私协议
function handlePrivacy() {
let site = globalConfig.appInfo.agreements[0]
proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
}
// 用户协议
function handleUserAgrement() {
let site = globalConfig.appInfo.agreements[1]
proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
}
// 获取图形验证码
function getCode() {
getCodeImg().then(res => {
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
if (captchaEnabled.value) {
codeUrl.value = 'data:image/gif;base64,' + res.img
loginForm.value.uuid = res.uuid
} }
} })
}, }
created() {
this.getCode() // 登录方法
}, async function handleLogin() {
methods: { if (loginForm.value.username === "") {
// 用户注册 proxy.$modal.msgError("请输入账号")
handleUserRegister() { } else if (loginForm.value.password === "") {
this.$tab.redirectTo(`/pages/register`) proxy.$modal.msgError("请输入密码")
}, } else if (loginForm.value.code === "" && captchaEnabled.value) {
// 隐私协议 proxy.$modal.msgError("请输入验证码")
handlePrivacy() { } else {
let site = this.globalConfig.appInfo.agreements[0] proxy.$modal.loading("登录中,请耐心等待...")
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`) pwdLogin()
},
// 用户协议
handleUserAgrement() {
let site = this.globalConfig.appInfo.agreements[1]
this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
},
// 获取图形验证码
getCode() {
getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
if (this.captchaEnabled) {
this.codeUrl = 'data:image/gif;base64,' + res.img
this.loginForm.uuid = res.uuid
}
})
},
// 登录方法
async handleLogin() {
if (this.loginForm.username === "") {
this.$modal.msgError("请输入账号")
} else if (this.loginForm.password === "") {
this.$modal.msgError("请输入密码")
} else if (this.loginForm.code === "" && this.captchaEnabled) {
this.$modal.msgError("请输入验证码")
} else {
this.$modal.loading("登录中,请耐心等待...")
this.pwdLogin()
}
},
// 密码登录
async pwdLogin() {
this.$store.dispatch('Login', this.loginForm).then(() => {
this.$modal.closeLoading()
this.loginSuccess()
}).catch(() => {
if (this.captchaEnabled) {
this.getCode()
}
})
},
// 登录成功后,处理函数
loginSuccess(result) {
// 设置用户信息
this.$store.dispatch('GetInfo').then(res => {
this.$tab.reLaunch('/pages/index')
})
}
} }
} }
// 密码登录
async function pwdLogin() {
store.dispatch('Login', loginForm.value).then(() => {
proxy.$modal.closeLoading()
loginSuccess()
}).catch(() => {
if (captchaEnabled.value) {
getCode()
}
})
}
// 登录成功后,处理函数
function loginSuccess(result) {
// 设置用户信息
store.dispatch('GetInfo').then(res => {
proxy.$tab.reLaunch('/pages/index')
})
}
getCode()
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -198,5 +200,4 @@
} }
} }
} }
</style> </style>

View File

@@ -43,15 +43,9 @@
</view> </view>
</template> </template>
<script> <script setup>
export default { const url = getApp().globalData.config.appInfo.site_url
data() { const version = getApp().globalData.config.appInfo.version
return {
url: getApp().globalData.config.appInfo.site_url,
version: getApp().globalData.config.appInfo.version
}
}
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -15,49 +15,45 @@
</view> </view>
</template> </template>
<script> <script setup>
export default { import { ref, getCurrentInstance } from "vue"
data() {
return { const { proxy } = getCurrentInstance()
list: [{
icon: 'iconfont icon-github', const list = ref([{
title: '若依问题', icon: 'iconfont icon-github',
childList: [{ title: '若依问题',
title: '若依开源吗?', childList: [{
content: '开源' title: '若依开源吗?',
}, { content: '开源'
title: '若依可以商用吗?', }, {
content: '可以' title: '若依可以商用吗?',
}, { content: '可以'
title: '若依官网地址多少?', }, {
content: 'http://ruoyi.vip' title: '若依官网地址多少?',
}, { content: 'http://ruoyi.vip'
title: '若依文档地址多少?', }, {
content: 'http://doc.ruoyi.vip' title: '若依文档地址多少?',
}] content: 'http://doc.ruoyi.vip'
}, }]
{ },
icon: 'iconfont icon-help', {
title: '其他问题', icon: 'iconfont icon-help',
childList: [{ title: '其他问题',
title: '如何退出登录?', childList: [{
content: '请点击[我的] - [应用设置] - [退出登录]即可退出登录', title: '如何退出登录?',
}, { content: '请点击[我的] - [应用设置] - [退出登录]即可退出登录',
title: '如何修改用户头像?', }, {
content: '请点击[我的] - [选择头像] - [点击提交]即可更换用户头像', title: '如何修改用户头像',
}, { content: '请点击[我的] - [选择头像] - [点击提交]即可更换用户头像',
title: '如何修改登录密码?', }, {
content: '请点击[我的] - [应用设置] - [修改密码]即可修改登录密码', title: '如何修改登录密码',
}] content: '请点击[我的] - [应用设置] - [修改密码]即可修改登录密码',
} }]
] }])
}
}, function handleText(item) {
methods: { proxy.$tab.navigateTo(`/pages/common/textview/index?title=${item.title}&content=${item.content}`)
handleText(item) {
this.$tab.navigateTo(`/pages/common/textview/index?title=${item.title}&content=${item.content}`)
}
}
} }
</script> </script>

View File

@@ -76,51 +76,50 @@
</view> </view>
</template> </template>
<script> <script setup>
export default { import store from '@/store'
data() { import { computed , getCurrentInstance } from "vue"
return {
name: this.$store.state.user.name, const { proxy } = getCurrentInstance()
version: getApp().globalData.config.appInfo.version const name = store.state.user.name
} const version= getApp().globalData.config.appInfo.version
}, const avatar = computed(() => store.state.user.avatar)
computed: { const windowHeight = computed(() => uni.getSystemInfoSync().windowHeight - 50)
avatar() {
return this.$store.state.user.avatar function handleToInfo() {
}, proxy.$tab.navigateTo('/pages/mine/info/index')
windowHeight() { }
return uni.getSystemInfoSync().windowHeight - 50
} function handleToEditInfo() {
}, proxy.$tab.navigateTo('/pages/mine/info/edit')
methods: { }
handleToInfo() {
this.$tab.navigateTo('/pages/mine/info/index') function handleToSetting() {
}, proxy.$tab.navigateTo('/pages/mine/setting/index')
handleToEditInfo() { }
this.$tab.navigateTo('/pages/mine/info/edit')
}, function handleToLogin() {
handleToSetting() { proxy.$tab.reLaunch('/pages/login')
this.$tab.navigateTo('/pages/mine/setting/index') }
},
handleToLogin() { function handleToAvatar() {
this.$tab.reLaunch('/pages/login') proxy.$tab.navigateTo('/pages/mine/avatar/index')
}, }
handleToAvatar() {
this.$tab.navigateTo('/pages/mine/avatar/index') function handleHelp() {
}, proxy.$tab.navigateTo('/pages/mine/help/index')
handleHelp() { }
this.$tab.navigateTo('/pages/mine/help/index')
}, function handleAbout() {
handleAbout() { proxy.$tab.navigateTo('/pages/mine/about/index')
this.$tab.navigateTo('/pages/mine/about/index') }
},
handleJiaoLiuQun() { function handleJiaoLiuQun() {
this.$modal.showToast('QQ群①133713780(满)、②146013835(满)、③189091635') proxy.$modal.showToast('QQ群①133713780(满)、②146013835(满)、③189091635')
}, }
handleBuilding() {
this.$modal.showToast('模块建设中~') function handleBuilding() {
} proxy.$modal.showToast('模块建设中~')
}
} }
</script> </script>

View File

@@ -20,75 +20,72 @@
</view> </view>
</template> </template>
<script> <script setup>
import { getUserProfile } from "@/api/system/user" import { getUserProfile } from "@/api/system/user"
import { updateUserProfile } from "@/api/system/user" import { updateUserProfile } from "@/api/system/user"
import { ref , getCurrentInstance } from "vue"
import { onReady } from "@dcloudio/uni-app"
export default { const { proxy } = getCurrentInstance()
data() { const user = ref({
return { nickName: "",
user: { phonenumber: "",
nickName: "", email: "",
phonenumber: "", sex: ""
email: "", })
sex: "" const sexs = [{
}, text: '男',
sexs: [{ value: "0"
text: '男', }, {
value: "0" text: '女',
}, { value: "1"
text: '女', }]
value: "1" const rules = ref({
}], nickName: {
rules: { rules: [{
nickName: { required: true,
rules: [{ errorMessage: '用户昵称不能为空'
required: true, }]
errorMessage: '用户昵称不能为空'
}]
},
phonenumber: {
rules: [{
required: true,
errorMessage: '手机号码不能为空'
}, {
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
errorMessage: '请输入正确的手机号码'
}]
},
email: {
rules: [{
required: true,
errorMessage: '邮箱地址不能为空'
}, {
format: 'email',
errorMessage: '请输入正确的邮箱地址'
}]
}
}
}
}, },
onLoad() { phonenumber: {
this.getUser() rules: [{
required: true,
errorMessage: '手机号码不能为空'
}, {
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
errorMessage: '请输入正确的手机号码'
}]
}, },
onReady() { email: {
this.$refs.form.setRules(this.rules) rules: [{
}, required: true,
methods: { errorMessage: '邮箱地址不能为空'
getUser() { }, {
getUserProfile().then(response => { format: 'email',
this.user = response.data errorMessage: '请输入正确的邮箱地址'
}) }]
},
submit(ref) {
this.$refs.form.validate().then(res => {
updateUserProfile(this.user).then(response => {
this.$modal.msgSuccess("修改成功")
})
})
}
} }
})
function getUser() {
getUserProfile().then(response => {
user.value = response.data
})
} }
function submit(ref) {
proxy.$refs.form.validate().then(res => {
updateUserProfile(user.value).then(response => {
proxy.$modal.msgSuccess("修改成功")
})
})
}
onReady(() => {
proxy.$refs.form.setRules(rules.value)
})
getUser()
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -11,30 +11,23 @@
</view> </view>
</template> </template>
<script> <script setup>
import { getUserProfile } from "@/api/system/user" import { getUserProfile } from "@/api/system/user"
import { ref, reactive } from "vue"
export default { const user = ref({})
data() { const roleGroup = ref("")
return { const postGroup = ref("")
user: {},
roleGroup: "", function getUser() {
postGroup: "" getUserProfile().then(response => {
} user.value = response.data
}, roleGroup.value = response.roleGroup
onLoad() { postGroup.value = response.postGroup
this.getUser() })
},
methods: {
getUser() {
getUserProfile().then(response => {
this.user = response.data
this.roleGroup = response.roleGroup
this.postGroup = response.postGroup
})
}
}
} }
getUser()
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@@ -15,61 +15,55 @@
</view> </view>
</template> </template>
<script> <script setup>
import { updateUserPwd } from "@/api/system/user" import { updateUserPwd } from "@/api/system/user"
import { ref, reactive , getCurrentInstance } from "vue"
import { onReady } from "@dcloudio/uni-app"
export default { const { proxy } = getCurrentInstance()
data() { const user = reactive({
return { oldPassword: undefined,
user: { newPassword: undefined,
oldPassword: undefined, confirmPassword: undefined
newPassword: undefined, })
confirmPassword: undefined const rules = ref({
}, oldPassword: {
rules: { rules: [{
oldPassword: { required: true,
rules: [{ errorMessage: '旧密码不能为空'
required: true, }]
errorMessage: '旧密码不能为空'
}]
},
newPassword: {
rules: [{
required: true,
errorMessage: '新密码不能为空',
},
{
minLength: 6,
maxLength: 20,
errorMessage: '长度在 6 到 20 个字符'
}
]
},
confirmPassword: {
rules: [{
required: true,
errorMessage: '确认密码不能为空'
}, {
validateFunction: (rule, value, data) => data.newPassword === value,
errorMessage: '两次输入的密码不一致'
}
]
}
}
}
}, },
onReady() { newPassword: {
this.$refs.form.setRules(this.rules) rules: [{
required: true,
errorMessage: '新密码不能为空',
}, {
minLength: 6,
maxLength: 20,
errorMessage: '长度在 6 到 20 个字符'
}]
}, },
methods: { confirmPassword: {
submit() { rules: [{
this.$refs.form.validate().then(res => { required: true,
updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => { errorMessage: '确认密码不能为空'
this.$modal.msgSuccess("修改成功") }, {
}) validateFunction: (rule, value, data) => user.newPassword === value,
}) errorMessage: '两次输入的密码不一致'
} }]
} }
})
onReady(() => {
proxy.$refs.form.setRules(rules.value)
})
function submit() {
proxy.$refs.form.validate().then(res => {
updateUserPwd(user.oldPassword, user.newPassword).then(response => {
proxy.$modal.msgSuccess("修改成功")
})
})
} }
</script> </script>

View File

@@ -30,31 +30,31 @@
</view> </view>
</template> </template>
<script> <script setup>
export default { import store from '@/store'
data() { import { ref, computed , getCurrentInstance } from "vue"
return {
windowHeight: uni.getSystemInfoSync().windowHeight const { proxy } = getCurrentInstance()
} const windowHeight = computed(() => uni.getSystemInfoSync().windowHeight - 50)
},
methods: { function handleToPwd() {
handleToPwd() { proxy.$tab.navigateTo('/pages/mine/pwd/index')
this.$tab.navigateTo('/pages/mine/pwd/index') }
},
handleToUpgrade() { function handleToUpgrade() {
this.$modal.showToast('模块建设中~') proxy.$modal.showToast('模块建设中~')
}, }
handleCleanTmp() {
this.$modal.showToast('模块建设中~') function handleCleanTmp() {
}, proxy.$modal.showToast('模块建设中~')
handleLogout() { }
this.$modal.confirm('确定注销并退出系统吗?').then(() => {
this.$store.dispatch('LogOut').then(() => {}).finally(()=>{ function handleLogout() {
this.$tab.reLaunch('/pages/index') proxy.$modal.confirm('确定注销并退出系统吗?').then(() => {
}) store.dispatch('LogOut').then(() => {}).finally(()=>{
}) proxy.$tab.reLaunch('/pages/index')
} })
} })
} }
</script> </script>

View File

@@ -35,80 +35,78 @@
</view> </view>
</template> </template>
<script> <script setup>
import { getCodeImg, register } from '@/api/login' import { getCodeImg, register } from '@/api/login'
import { ref, getCurrentInstance } from "vue"
export default { const { proxy } = getCurrentInstance()
data() { const globalConfig = getApp().globalData.config
return { const codeUrl = ref("")
codeUrl: "", // 验证码开关
captchaEnabled: true, const captchaEnabled = ref(true)
globalConfig: getApp().globalData.config, const registerForm = ref({
registerForm: { username: "",
username: "", password: "",
password: "", confirmPassword: "",
confirmPassword: "", code: "",
code: "", uuid: ""
uuid: "" })
}
} // 用户登录
}, function handleUserLogin() {
created() { proxy.$tab.navigateTo(`/pages/login`)
this.getCode() }
},
methods: { // 获取图形验证码
// 用户登录 function getCode() {
handleUserLogin() { getCodeImg().then(res => {
this.$tab.navigateTo(`/pages/login`) captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
}, if (captchaEnabled.value) {
// 获取图形验证码 codeUrl.value = 'data:image/gif;base64,' + res.img
getCode() { registerForm.value.uuid = res.uuid
getCodeImg().then(res => {
this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
if (this.captchaEnabled) {
this.codeUrl = 'data:image/gif;base64,' + res.img
this.registerForm.uuid = res.uuid
}
})
},
// 注册方法
async handleRegister() {
if (this.registerForm.username === "") {
this.$modal.msgError("请输入您的账号")
} else if (this.registerForm.password === "") {
this.$modal.msgError("请输入您的密码")
} else if (this.registerForm.confirmPassword === "") {
this.$modal.msgError("请再次输入您的密码")
} else if (this.registerForm.password !== this.registerForm.confirmPassword) {
this.$modal.msgError("两次输入的密码不一致")
} else if (this.registerForm.code === "" && this.captchaEnabled) {
this.$modal.msgError("请输入验证码")
} else {
this.$modal.loading("注册中,请耐心等待...")
this.register()
}
},
// 用户注册
async register() {
register(this.registerForm).then(res => {
this.$modal.closeLoading()
uni.showModal({
title: "系统提示",
content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!",
success: function (res) {
if (res.confirm) {
uni.redirectTo({ url: `/pages/login` });
}
}
})
}).catch(() => {
if (this.captchaEnabled) {
this.getCode()
}
})
} }
})
}
// 注册方法
async function handleRegister() {
if (registerForm.value.username === "") {
proxy.$modal.msgError("请输入您的账号")
} else if (registerForm.value.password === "") {
proxy.$modal.msgError("请输入您的密码")
} else if (registerForm.value.confirmPassword === "") {
proxy.$modal.msgError("请再次输入您的密码")
} else if (registerForm.value.password !== registerForm.value.confirmPassword) {
proxy.$modal.msgError("两次输入的密码不一致")
} else if (registerForm.value.code === "" && captchaEnabled.value) {
proxy.$modal.msgError("请输入验证码")
} else {
proxy.$modal.loading("注册中,请耐心等待...")
userRegister()
} }
} }
// 用户注册
async function userRegister() {
register(registerForm.value).then(res => {
proxy.$modal.closeLoading()
uni.showModal({
title: "系统提示",
content: "恭喜你,您的账号 " + registerForm.value.username + " 注册成功!",
success: function (res) {
if (res.confirm) {
uni.redirectTo({ url: `/pages/login` })
}
}
})
}).catch(() => {
if (captchaEnabled.value) {
getCode()
}
})
}
getCode()
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -185,5 +183,4 @@
} }
} }
} }
</style> </style>

View File

@@ -74,35 +74,24 @@
</view> </view>
</template> </template>
<script> <script setup>
export default { import { ref, getCurrentInstance } from "vue"
data() {
return { const { proxy } = getCurrentInstance()
current: 0, const current = ref(0)
swiperDotIndex: 0, const swiperDotIndex = ref(0)
data: [{ const data = ref([{ image: '/static/images/banner/banner01.jpg' }, { image: '/static/images/banner/banner02.jpg' }, { image: '/static/images/banner/banner03.jpg' }])
image: '/static/images/banner/banner01.jpg'
}, function clickBannerItem(item) {
{ console.info(item)
image: '/static/images/banner/banner02.jpg' }
},
{ function changeSwiper(e) {
image: '/static/images/banner/banner03.jpg' current.value = e.detail.current
} }
]
} function changeGrid(e) {
}, proxy.$modal.showToast('模块建设中~')
methods: {
clickBannerItem(item) {
console.info(item)
},
changeSwiper(e) {
this.current = e.detail.current
},
changeGrid(e) {
this.$modal.showToast('模块建设中~')
}
}
} }
</script> </script>

View File

@@ -2,13 +2,11 @@ import tab from './tab'
import auth from './auth' import auth from './auth'
import modal from './modal' import modal from './modal'
export default { export function install(app) {
install(Vue) { // 页签操作
// 页签操作 app.config.globalProperties.$tab = tab
Vue.prototype.$tab = tab // 认证对象
// 认证对象 app.config.globalProperties.$auth = auth
Vue.prototype.$auth = auth // 模态框对象
// 模态框对象 app.config.globalProperties.$modal = modal
Vue.prototype.$modal = modal
}
} }

View File

@@ -1,15 +1,11 @@
import Vue from 'vue' import { createStore } from "vuex"
import Vuex from 'vuex'
import user from '@/store/modules/user' import user from '@/store/modules/user'
import getters from './getters' import getters from './getters'
Vue.use(Vuex) const store = createStore({
const store = new Vuex.Store({
modules: { modules: {
user user
}, },
getters getters
}) })
export default store export default store

View File

@@ -29,12 +29,7 @@ const request = config => {
header: config.header, header: config.header,
dataType: 'json' dataType: 'json'
}).then(response => { }).then(response => {
let [error, res] = response const res = response
if (error) {
toast('后端接口连接异常')
reject('后端接口连接异常')
return
}
const code = res.data.code || 200 const code = res.data.code || 200
const msg = errorCode[code] || res.data.msg || errorCode['default'] const msg = errorCode[code] || res.data.msg || errorCode['default']
if (code === 401) { if (code === 401) {

View File

@@ -7,7 +7,7 @@ import { toast, showConfirm, tansParams } from '@/utils/common'
let timeout = 10000 let timeout = 10000
const baseUrl = config.baseUrl const baseUrl = config.baseUrl
const upload = config => { export default function upload(config) {
// 是否需要设置 token // 是否需要设置 token
const isToken = (config.headers || {}).isToken === false const isToken = (config.headers || {}).isToken === false
config.header = config.header || {} config.header = config.header || {}
@@ -21,50 +21,50 @@ const upload = config => {
config.url = url config.url = url
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.uploadFile({ uni.uploadFile({
timeout: config.timeout || timeout, timeout: config.timeout || timeout,
url: baseUrl + config.url, url: baseUrl + config.url,
filePath: config.filePath, filePath: config.filePath,
name: config.name || 'file', name: config.name || 'file',
header: config.header, header: config.header,
formData: config.formData, formData: config.formData,
success: (res) => { success: (res) => {
let result = JSON.parse(res.data) let result = JSON.parse(res.data)
const code = result.code || 200 const code = result.code || 200
const msg = errorCode[code] || result.msg || errorCode['default'] const msg = errorCode[code] || result.msg || errorCode['default']
if (code === 200) { if (code === 200) {
resolve(result) resolve(result)
} else if (code == 401) { } else if (code == 401) {
showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => { showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
if (res.confirm) { if (res.confirm) {
store.dispatch('LogOut').then(res => { store.dispatch('LogOut').then(res => {
uni.reLaunch({ url: '/pages/login/login' }) uni.reLaunch({ url: '/pages/login/login' })
}) })
} }
}) })
reject('无效的会话,或者会话已过期,请重新登录。') reject('无效的会话,或者会话已过期,请重新登录。')
} else if (code === 500) { } else if (code === 500) {
toast(msg) toast(msg)
reject('500') reject('500')
} else if (code !== 200) { } else if (code !== 200) {
toast(msg) toast(msg)
reject(code) 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)
} }
}) },
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