This commit is contained in:
Vinjor 2025-03-27 09:50:13 +08:00
parent 9127778c6f
commit f78f20f0a7
7 changed files with 556 additions and 496 deletions

View File

@ -3,39 +3,39 @@ import request from '@/utils/request'
// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
const data = {
oldPassword,
newPassword
}
return request({
url: '/system/user/profile/updatePwd',
method: 'put',
data: data
})
const data = {
oldPassword,
newPassword
}
return request({
url: '/system/user/profile/updatePwd',
method: 'put',
data: data
})
}
// 查询用户个人信息
export function getUserProfile() {
return request({
url: '/system/user/profile',
method: 'get'
})
return request({
url: '/system/user/profile',
method: 'get'
})
}
// 修改用户个人信息
export function updateUserProfile(data) {
return request({
url: '/system/user/profile',
method: 'put',
data: data
})
return request({
url: '/system/user/profile',
method: 'put',
data: data
})
}
// 用户头像上传
export function uploadAvatar(data) {
return upload({
url: '/system/user/profile/avatar',
name: data.name,
filePath: data.filePath
})
}
return upload({
url: '/system/user/profile/avatar',
name: data.name,
filePath: data.filePath
})
}

View File

@ -1,110 +1,110 @@
{
"pages": [{
"path": "pages/index",
"style": {
"navigationBarTitleText": "首页",
"navigationStyle": "custom"
}
}, {
"path": "pages/login",
"style": {
"navigationBarTitleText": "登录"
}
}, {
"path": "pages/register",
"style": {
"navigationBarTitleText": "注册"
}
}, {
"path": "pages/work/index",
"style": {
"navigationBarTitleText": "工作台"
}
}, {
"path": "pages/work/my-notice",
"style": {
"navigationBarTitleText": "我的通告"
}
}, {
"path": "pages/mine/index",
"style": {
"navigationBarTitleText": "我的"
}
}, {
"path": "pages/mine/avatar/index",
"style": {
"navigationBarTitleText": "修改头像"
}
}, {
"path": "pages/mine/info/index",
"style": {
"navigationBarTitleText": "个人信息"
}
}, {
"path": "pages/mine/info/edit",
"style": {
"navigationBarTitleText": "编辑资料"
}
}, {
"path": "pages/mine/pwd/index",
"style": {
"navigationBarTitleText": "修改密码"
}
}, {
"path": "pages/mine/setting/index",
"style": {
"navigationBarTitleText": "应用设置"
}
}, {
"path": "pages/mine/help/index",
"style": {
"navigationBarTitleText": "常见问题"
}
}, {
"path": "pages/mine/about/index",
"style": {
"navigationBarTitleText": "关于我们"
}
}, {
"path": "pages/common/webview/index",
"style": {
"navigationBarTitleText": "浏览网页"
}
}, {
"path": "pages/common/textview/index",
"style": {
"navigationBarTitleText": "浏览文本"
}
}, {
"path": "pages/common/richview/index",
"style": {
"navigationBarTitleText": "浏览富文本"
}
},
{
"path" : "pages/components/index",
"style" :
{
"navigationBarTitleText" : "通告首页"
}
},{
"path" : "pages/components/notice-item",
"style" :
{
"navigationBarTitleText" : "通告组件"
}
}],
// "subPackages": [
// {
// "root": "pages/notice",
// "pages": [
// ]
// }
// ],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "多点通告",
"navigationBarBackgroundColor": "#FFFFFF"
}
}
"pages": [{
"path": "pages/index",
"style": {
"navigationBarTitleText": "首页",
"navigationStyle": "custom"
}
}, {
"path": "pages/login",
"style": {
"navigationBarTitleText": "登录"
}
}, {
"path": "pages/register",
"style": {
"navigationBarTitleText": "注册"
}
}, {
"path": "pages/work/index",
"style": {
"navigationBarTitleText": "工作台"
}
}, {
"path": "pages/work/my-notice",
"style": {
"navigationBarTitleText": "我的通告"
}
}, {
"path": "pages/mine/index",
"style": {
"navigationBarTitleText": "我的"
}
}, {
"path": "pages/mine/avatar/index",
"style": {
"navigationBarTitleText": "修改头像"
}
}, {
"path": "pages/mine/info/index",
"style": {
"navigationBarTitleText": "个人信息"
}
}, {
"path": "pages/mine/info/edit",
"style": {
"navigationBarTitleText": "编辑资料"
}
}, {
"path": "pages/mine/pwd/index",
"style": {
"navigationBarTitleText": "修改密码"
}
}, {
"path": "pages/mine/setting/index",
"style": {
"navigationBarTitleText": "应用设置"
}
}, {
"path": "pages/mine/help/index",
"style": {
"navigationBarTitleText": "常见问题"
}
}, {
"path": "pages/mine/about/index",
"style": {
"navigationBarTitleText": "关于我们"
}
}, {
"path": "pages/common/webview/index",
"style": {
"navigationBarTitleText": "浏览网页"
}
}, {
"path": "pages/common/textview/index",
"style": {
"navigationBarTitleText": "浏览文本"
}
}, {
"path": "pages/common/richview/index",
"style": {
"navigationBarTitleText": "浏览富文本"
}
},
{
"path": "pages/components/index",
"style": {
"navigationBarTitleText": "通告首页"
}
}, {
"path": "pages/components/notice-item",
"style": {
"navigationBarTitleText": "通告组件"
}
}
],
"subPackages": [{
"root": "pages/notice",
"pages": [{
"path": "detail",
"style": {
"navigationBarTitleText": "通告详情"
}
}]
}],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "多点通告",
"navigationBarBackgroundColor": "#FFFFFF"
}
}

View File

@ -1,6 +1,6 @@
<template>
<view class="dl-components">
<view v-for="(item,index) in dataList" class="dl-notice-box">
<view v-for="(item,index) in dataList" class="dl-notice-box" @click="goDetail(item)">
<view class="dl-notice-title">
<image class="dl-image" :src="'/static/platform/'+item.platformCode+'.png'" mode="aspectFit"></image>
<view class="dl-text">{{item.title}}</view>
@ -60,8 +60,19 @@
}
},
methods: {
/**
* 数值单位转换
* @param {Object} number
*/
formatNumberWithUnits(number) {
return formatNumberWithUnits(number)
},
/**
* 查看通告详情
* @param {Object} item
*/
goDetail(item) {
this.$emit("goDetail", item)
}
}
}

View File

@ -1,265 +1,270 @@
<template>
<view class="normal-login-container">
<view class="logo-content align-center justify-center flex">
<!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
<!-- </image>-->
<text class="title">请登录</text>
</view>
<view class="login-form-content">
<!-- <view class="input-item flex align-center">-->
<!-- <view class="iconfont icon-user icon"></view>-->
<!-- <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />-->
<!-- </view>-->
<!-- <view class="input-item flex align-center">-->
<!-- <view class="iconfont icon-password icon"></view>-->
<!-- <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />-->
<!-- </view>-->
<!-- <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">-->
<!-- <view class="iconfont icon-code icon"></view>-->
<!-- <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />-->
<!-- <view class="login-code"> -->
<!-- <image :src="codeUrl" @click="getCode" class="login-code-img"></image>-->
<!-- </view>-->
<!-- </view>-->
<view class="action-btn">
<button open-type="getPhoneNumber" @getphonenumber="getPhone" class="login-btn cu-btn block bg-blue lg round">手机号快捷登录</button>
<!-- <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>-->
<!-- <u-button open-type='getPhoneNumber' text="手机号快捷登录" @getphonenumber="wxHandleLogin" class="login-btn cu-btn block bg-green lg round"></u-button>-->
</view>
<!-- <view class="reg text-center" v-if="register">-->
<!-- <text class="text-grey1">没有账号</text>-->
<!-- <text @click="handleUserRegister" class="text-blue">立即注册</text>-->
<!-- </view>-->
<view class="xieyi text-center">
<text class="text-grey1">登录即代表同意</text>
<text @click="handleUserAgrement(globalConfig.appInfo.agreements[0])" class="text-blue">{{globalConfig.appInfo.agreements[0].title}}</text>
<text @click="handleUserAgrement(globalConfig.appInfo.agreements[1])" class="text-blue">{{ globalConfig.appInfo.agreements[1].title }}</text>
</view>
</view>
<view class="normal-login-container">
<view class="logo-content align-center justify-center flex">
<!-- <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">-->
<!-- </image>-->
<text class="title">请登录</text>
</view>
<view class="login-form-content">
<!-- <view class="input-item flex align-center">-->
<!-- <view class="iconfont icon-user icon"></view>-->
<!-- <input v-model="loginForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />-->
<!-- </view>-->
<!-- <view class="input-item flex align-center">-->
<!-- <view class="iconfont icon-password icon"></view>-->
<!-- <input v-model="loginForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />-->
<!-- </view>-->
<!-- <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">-->
<!-- <view class="iconfont icon-code icon"></view>-->
<!-- <input v-model="loginForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />-->
<!-- <view class="login-code"> -->
<!-- <image :src="codeUrl" @click="getCode" class="login-code-img"></image>-->
<!-- </view>-->
<!-- </view>-->
<view class="action-btn">
<button open-type="getPhoneNumber" @getphonenumber="getPhone"
class="login-btn cu-btn block bg-blue lg round">手机号快捷登录</button>
<!-- <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>-->
<!-- <u-button open-type='getPhoneNumber' text="手机号快捷登录" @getphonenumber="wxHandleLogin" class="login-btn cu-btn block bg-green lg round"></u-button>-->
</view>
<!-- <view class="reg text-center" v-if="register">-->
<!-- <text class="text-grey1">没有账号</text>-->
<!-- <text @click="handleUserRegister" class="text-blue">立即注册</text>-->
<!-- </view>-->
<view class="xieyi text-center">
<text class="text-grey1">登录即代表同意</text>
<text @click="handleUserAgrement(globalConfig.appInfo.agreements[0])"
class="text-blue">{{globalConfig.appInfo.agreements[0].title}}</text>
<text @click="handleUserAgrement(globalConfig.appInfo.agreements[1])"
class="text-blue">{{ globalConfig.appInfo.agreements[1].title }}</text>
</view>
</view>
</view>
</view>
</template>
<script>
import { getCodeImg } from '@/api/login'
import {
getCodeImg
} from '@/api/login'
export default {
data() {
return {
codeUrl: "",
captchaEnabled: true,
//
register: false,
globalConfig: getApp().globalData.config,
loginForm: {
username: "admin",
password: "admin123",
code: "",
uuid: ''
},
//
wxLoginForm: {
code: "",
encryptedIv: "",
encryptedData: ""
}
}
},
created() {
this.getCode()
this.wxLogin()
},
methods: {
//
handleUserRegister() {
this.$tab.redirectTo(`/pages/register`)
},
//
handleUserAgrement(site) {
this.$tab.navigateTo(`/pages/common/richview/index?title=${site.title}&code=${site.code}`)
},
//
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
}
})
},
wxLogin() {
let that = this
uni.login({
provider: 'weixin',
success(res) {
console.log(543, res);
if (res.code) {
that.wxLoginForm.code= res.code
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
//
getPhone(e) {
console.log("微信小程序发起授权登录")
this.$modal.loading("登录中...")
uni.checkSession({
success: () => {
this.wxLoginForm.encryptedIv = e.detail.iv
this.wxLoginForm.encryptedData = e.detail.encryptedData
this.sendWxLoginFormToLocalService()
},
fail: () => {
uni.showToast({
icon: 'error',
duration: 2000,
title: "登录状态过期,重新登录"
});
}
})
},
//
sendWxLoginFormToLocalService(){
this.$store.dispatch('WxLogin', this.wxLoginForm).then(() => {
this.$modal.closeLoading()
this.loginSuccess()
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
// if (this.captchaEnabled) {
// // this.getCode()
// }
})
},
//
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')
})
}
}
}
export default {
data() {
return {
codeUrl: "",
captchaEnabled: true,
//
register: false,
globalConfig: getApp().globalData.config,
loginForm: {
username: "admin",
password: "admin123",
code: "",
uuid: ''
},
//
wxLoginForm: {
code: "",
encryptedIv: "",
encryptedData: ""
}
}
},
created() {
this.getCode()
this.wxLogin()
},
methods: {
//
handleUserRegister() {
this.$tab.redirectTo(`/pages/register`)
},
//
handleUserAgrement(site) {
this.$tab.navigateTo(`/pages/common/richview/index?title=${site.title}&code=${site.code}`)
},
//
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
}
})
},
wxLogin() {
let that = this
uni.login({
provider: 'weixin',
success(res) {
console.log(543, res);
if (res.code) {
that.wxLoginForm.code = res.code
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
//
getPhone(e) {
console.log("微信小程序发起授权登录")
this.$modal.loading("登录中...")
uni.checkSession({
success: () => {
this.wxLoginForm.encryptedIv = e.detail.iv
this.wxLoginForm.encryptedData = e.detail.encryptedData
this.sendWxLoginFormToLocalService()
},
fail: () => {
uni.showToast({
icon: 'error',
duration: 2000,
title: "登录状态过期,重新登录"
});
}
})
},
//
sendWxLoginFormToLocalService() {
this.$store.dispatch('WxLogin', this.wxLoginForm).then(() => {
this.$modal.closeLoading()
this.loginSuccess()
}).catch((e) => {
uni.showToast({
icon: 'error',
duration: 2000,
title: e
});
})
},
//
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')
})
}
}
}
</script>
<style lang="scss">
page {
background-color: #ffffff;
}
.dl{
width: 90%;
height: 44px;
background-color: #0D2E8D;
border-radius: 50px;
margin: 0 auto;
font-size: 16px;
color: #FFFFFF;
display: flex;
justify-content: center;
align-items: center;
}
.normal-login-container {
width: 100%;
page {
background-color: #ffffff;
}
.logo-content {
width: 100%;
font-size: 21px;
text-align: center;
padding-top: 15%;
.dl {
width: 90%;
height: 44px;
background-color: #0D2E8D;
border-radius: 50px;
margin: 0 auto;
font-size: 16px;
color: #FFFFFF;
display: flex;
justify-content: center;
align-items: center;
}
image {
border-radius: 4px;
}
.normal-login-container {
width: 100%;
.title {
margin-left: 10px;
}
}
.logo-content {
width: 100%;
font-size: 21px;
text-align: center;
padding-top: 15%;
.login-form-content {
text-align: center;
margin: 20px auto;
margin-top: 15%;
width: 80%;
image {
border-radius: 4px;
}
.input-item {
margin: 20px auto;
background-color: #f5f6f7;
height: 45px;
border-radius: 20px;
.title {
margin-left: 10px;
}
}
.icon {
font-size: 38rpx;
margin-left: 10px;
color: #999;
}
.login-form-content {
text-align: center;
margin: 20px auto;
margin-top: 15%;
width: 80%;
.input {
width: 100%;
font-size: 14px;
line-height: 20px;
text-align: left;
padding-left: 15px;
}
.input-item {
margin: 20px auto;
background-color: #f5f6f7;
height: 45px;
border-radius: 20px;
}
.icon {
font-size: 38rpx;
margin-left: 10px;
color: #999;
}
.login-btn {
margin-top: 40px;
height: 45px;
}
.input {
width: 100%;
font-size: 14px;
line-height: 20px;
text-align: left;
padding-left: 15px;
}
.reg {
margin-top: 15px;
}
}
.xieyi {
color: #333;
margin-top: 20px;
}
.login-btn {
margin-top: 40px;
height: 45px;
}
.login-code {
height: 38px;
float: right;
.reg {
margin-top: 15px;
}
.login-code-img {
height: 38px;
position: absolute;
margin-left: 10px;
width: 200rpx;
}
}
}
}
.xieyi {
color: #333;
margin-top: 20px;
}
</style>
.login-code {
height: 38px;
float: right;
.login-code-img {
height: 38px;
position: absolute;
margin-left: 10px;
width: 200rpx;
}
}
}
}
</style>

View File

@ -1,113 +1,145 @@
import config from '@/config'
import storage from '@/utils/storage'
import constant from '@/utils/constant'
import { login,wxLogin, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import {
changeUserType
} from '@/utils/common.js'
import {
login,
wxLogin,
logout,
getInfo
} from '@/api/login'
import {
getToken,
setToken,
removeToken,
setJSONData,
getStrData
} from '@/utils/auth'
const baseUrl = config.baseUrl
const user = {
state: {
token: getToken(),
name: storage.get(constant.name),
avatar: storage.get(constant.avatar),
roles: storage.get(constant.roles),
permissions: storage.get(constant.permissions)
},
state: {
token: getToken(),
name: storage.get(constant.name),
avatar: storage.get(constant.avatar),
roles: storage.get(constant.roles),
permissions: storage.get(constant.permissions)
},
mutations: {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
storage.set(constant.name, name)
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
storage.set(constant.avatar, avatar)
},
SET_ROLES: (state, roles) => {
state.roles = roles
storage.set(constant.roles, roles)
},
SET_PERMISSIONS: (state, permissions) => {
state.permissions = permissions
storage.set(constant.permissions, permissions)
}
},
mutations: {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
storage.set(constant.name, name)
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
storage.set(constant.avatar, avatar)
},
SET_ROLES: (state, roles) => {
state.roles = roles
storage.set(constant.roles, roles)
},
SET_PERMISSIONS: (state, permissions) => {
state.permissions = permissions
storage.set(constant.permissions, permissions)
}
},
actions: {
// 微信登录
WxLogin({ commit }, wxUserInfo) {
const code = wxUserInfo.code
const encryptedIv = wxUserInfo.encryptedIv
const encryptedData = wxUserInfo.encryptedData
return new Promise((resolve, reject) => {
wxLogin(code, encryptedIv, encryptedData).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// 登录
Login({ commit }, userInfo) {
const username = userInfo.username.trim()
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
actions: {
// 微信登录
WxLogin({
commit
}, wxUserInfo) {
const code = wxUserInfo.code
const encryptedIv = wxUserInfo.encryptedIv
const encryptedData = wxUserInfo.encryptedData
return new Promise((resolve, reject) => {
wxLogin(code, encryptedIv, encryptedData).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// 登录
Login({
commit
}, userInfo) {
const username = userInfo.username.trim()
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// 获取用户信息
GetInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo().then(res => {
const user = res.user
const avatar = (user == null || user.avatar == "" || user.avatar == null) ? require("@/static/images/profile.jpg") : baseUrl + user.avatar
const username = (user == null || user.userName == "" || user.userName == null) ? "" : user.userName
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', username)
commit('SET_AVATAR', avatar)
resolve(res)
}).catch(error => {
reject(error)
})
})
},
// 获取用户信息
GetInfo({
commit,
state
}) {
return new Promise((resolve, reject) => {
getInfo().then(res => {
const user = res.user
const avatar = (user == null || user.avatar == "" || user.avatar == null) ?
require("@/static/images/profile.jpg") : baseUrl + user.avatar
const username = (user == null || user.userName == "" || user.userName ==
null) ? "" : user.userName
if (res.roles && res.roles.length > 0) {
commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions)
} else {
commit('SET_ROLES', ['ROLE_DEFAULT'])
}
//会员权益
setJSONData(constant.userRightsKey, res.rights)
if (!getStrData(constant.userTypeKey)) {
//没有默认身份,默认博主
changeUserType(constant.bz)
}
commit('SET_NAME', username)
commit('SET_AVATAR', avatar)
resolve(res)
}).catch(error => {
reject(error)
})
})
},
// 退出系统
LogOut({ commit, state }) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
commit('SET_PERMISSIONS', [])
removeToken()
storage.clean()
resolve()
}).catch(error => {
reject(error)
})
})
}
}
// 退出系统
LogOut({
commit,
state
}) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
commit('SET_PERMISSIONS', [])
removeToken()
storage.clean()
resolve()
}).catch(error => {
reject(error)
})
})
}
}
}
export default user
export default user

View File

@ -2,33 +2,38 @@ import {
getJSONData,
setJSONData,
removeJSONData,
setStrData
setStrData,
getStrData
} from '@/utils/auth'
// 用户权益code
const UserRightsKey = 'User-Rights'
//用户当前身份code
const UserTypeKey = 'User-Type'
import constant from '@/utils/constant'
/**
* 判断某用户是否有某权益
* @param {Object} code 权益code
*/
export function hasRights(code) {
let userRights = getJSONData(UserRightsKey)
//取用户当前身份
let userType = getStrData(constant.userTypeKey)
let userRights = {}
if (constant.bz == userType) {
//博主
userRights = getJSONData(constant.userRightsKey)['bz']
} else {
//通告主
userRights = getJSONData(constant.userRightsKey)['tgz']
}
//默认无权限
let rtnData = false
if ('' != userRights && userRights.con) {
if (userRights.hasOwnProperty(code)) {
rtnData = userRights[code]
}
return rtnData
}
/**
}/**
* 切换用户当前身份
* @param {Object} value 身份值
*/
export function changeUserType(value) {
setStrData(UserTypeKey, value)
setStrData(constant.userTypeKey, value)
}
/**
@ -113,4 +118,4 @@ export function formatNumberWithUnits(num) {
// 格式化数字,并添加单位
const formattedNum = absNum.toFixed(2).replace(/\.?0+$/, ''); // 保留两位小数并去除末尾的零
return formattedNum + units[unitIndex];
}
}

View File

@ -1,8 +1,15 @@
const constant = {
avatar: 'vuex_avatar',
name: 'vuex_name',
roles: 'vuex_roles',
permissions: 'vuex_permissions'
}
export default constant
avatar: 'vuex_avatar',
name: 'vuex_name',
roles: 'vuex_roles',
permissions: 'vuex_permissions',
//用户权益code
userRightsKey: 'User-Rights',
// 用户当前身份code
userTypeKey: 'User-Type',
//博主
bz: '02',
//通告主
tgz: '01'
}
export default constant