云下生产图片使用页面打开地址作为基础路径

This commit is contained in:
白菜
2025-12-15 14:26:53 +08:00
parent 9379c3834a
commit 291cbe93ed
2 changed files with 149 additions and 135 deletions

View File

@ -1,8 +1,8 @@
import router from '@/router'
import {MessageBox,} from 'element-ui'
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { isHttp, isEmpty } from "@/utils/validate"
import {getInfo, login, logout} from '@/api/login'
import {getToken, removeToken, setToken} from '@/utils/auth'
import {isEmpty, isHttp} from "@/utils/validate"
import defAva from '@/assets/images/profile.jpg'
const user = {
@ -65,7 +65,8 @@ const user = {
const user = res.user
let avatar = user.avatar || ""
if (!isHttp(avatar)) {
avatar = (isEmpty(avatar)) ? defAva : process.env.VUE_APP_IMG_URL + avatar
const imgBase = process.env.NODE_ENV === 'production' ? window.location.origin : process.env.VUE_APP_IMG_URL
avatar = (isEmpty(avatar)) ? defAva : imgBase + avatar
}
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles)
@ -79,15 +80,25 @@ const user = {
commit('SET_AVATAR', avatar)
/* 初始密码提示 */
if (res.isDefaultModifyPwd) {
MessageBox.confirm('您的密码还是初始密码,请修改密码!', '安全提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
MessageBox.confirm('您的密码还是初始密码,请修改密码!', '安全提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
router.push({name: 'Profile', params: {activeTab: 'resetPwd'}})
}).catch(() => {})
}).catch(() => {
})
}
/* 过期密码提示 */
if (!res.isDefaultModifyPwd && res.isPasswordExpired) {
MessageBox.confirm('您的密码已过期,请尽快修改密码!', '安全提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => {
MessageBox.confirm('您的密码已过期,请尽快修改密码!', '安全提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
router.push({name: 'Profile', params: {activeTab: 'resetPwd'}})
}).catch(() => {})
}).catch(() => {
})
}
resolve(res)
}).catch(error => {

View File

@ -1,7 +1,9 @@
<template>
<div>
<div class="user-info-head" @click="editCropper()"><img v-bind:src="options.img" title="点击上传头像" class="img-circle img-lg" /></div>
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @opened="modalOpened" @close="closeDialog">
<div class="user-info-head" @click="editCropper()"><img v-bind:src="options.img" title="点击上传头像"
class="img-circle img-lg"/></div>
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @opened="modalOpened"
@close="closeDialog">
<el-row>
<el-col :xs="24" :md="12" :style="{height: '350px'}">
<vue-cropper
@ -136,8 +138,9 @@ export default {
let formData = new FormData()
formData.append("avatarfile", data, this.options.filename)
uploadAvatar(formData).then(response => {
const imgBase = process.env.NODE_ENV === 'production' ? window.location.origin : process.env.VUE_APP_IMG_URL
this.open = false
this.options.img = process.env.VUE_APP_IMG_URL + response.imgUrl
this.options.img = imgBase + response.imgUrl
store.commit('SET_AVATAR', this.options.img)
this.$modal.msgSuccess("修改成功")
this.visible = false