切换角色

salary
qsh 6 months ago
parent 8adaf72682
commit 34b4f84293
  1. 4
      src/api/login/index.ts
  2. 2
      src/config/axios/service.ts
  3. 7
      src/layout/components/Message/src/Message.vue
  4. 6
      src/layout/components/RoleSelect/index.vue
  5. 8
      src/layout/components/UserInfo/src/UserInfo.vue
  6. 28
      src/store/modules/user.ts
  7. 25
      src/views/Basic/Dept/DeptForm.vue
  8. 6
      src/views/Basic/Role/Comp/RoleEmployee.vue
  9. 39
      src/views/Basic/User/UserForm.vue
  10. 2
      src/views/Error/403.vue
  11. 2
      src/views/Error/404.vue
  12. 2
      src/views/Error/500.vue
  13. 103
      src/views/MiniMall/MallSet/Comp/DialogSupplier.vue
  14. 34
      src/views/MiniMall/MallSet/Comp/GeneralSet.vue
  15. 95
      src/views/MiniMall/MallSet/Comp/SupplierSet.vue
  16. 8
      src/views/MiniMall/MallSet/index.vue
  17. 4
      src/views/Profile/components/ProfileUser.vue

@ -35,8 +35,8 @@ export const loginOut = () => {
} }
// 获取用户权限信息 // 获取用户权限信息
export const getInfo = (data) => { export const getInfo = (params) => {
return request.get({ url: '/admin-api/system/auth/get-permission-info', data }) return request.get({ url: '/admin-api/system/auth/get-permission-info', params })
} }
//获取登录验证码 //获取登录验证码

@ -190,8 +190,6 @@ service.interceptors.response.use(
t('sys.api.errMsg901') + t('sys.api.errMsg901') +
'</div>' + '</div>' +
'<div> &nbsp; </div>' + '<div> &nbsp; </div>' +
'<div>参考 https://doc.iocoder.cn/ 教程</div>' +
'<div> &nbsp; </div>' +
'<div>5 分钟搭建本地环境</div>' '<div>5 分钟搭建本地环境</div>'
}) })
return Promise.reject(new Error(msg)) return Promise.reject(new Error(msg))

@ -29,14 +29,19 @@ const goMyList = () => {
} }
// ========== ========= // ========== =========
const msgInterval = ref<any>(null)
onMounted(() => { onMounted(() => {
// //
getUnreadCount() getUnreadCount()
// //
setInterval(() => { msgInterval.value = setInterval(() => {
getUnreadCount() getUnreadCount()
}, 1000 * 60 * 2) }, 1000 * 60 * 2)
}) })
onUnmounted(() => {
clearInterval(msgInterval.value)
})
</script> </script>
<template> <template>
<div class="message"> <div class="message">

@ -13,10 +13,12 @@ const userStore = useUserStore()
const options = computed(() => { const options = computed(() => {
return userStore.getRoles return userStore.getRoles
}) })
const roleId = ref(1) const roleId = ref(userStore.getUser.currentRole)
function handleChangeRole(val) { function handleChangeRole(val) {
getInfo({ params: { roleId: val } }) getInfo({ roleId: val }).then(() => {
userStore.refresh()
})
} }
</script> </script>

@ -52,13 +52,7 @@ const toProfile = async () => {
<ElDropdown :class="prefixCls" trigger="click"> <ElDropdown :class="prefixCls" trigger="click">
<div class="flex items-center"> <div class="flex items-center">
<img :src="avatar" alt="" class="w-[calc(var(--logo-height)-25px)] rounded-[50%]" /> <img :src="avatar" alt="" class="w-[calc(var(--logo-height)-25px)] rounded-[50%]" />
<span <span class="<lg:hidden text-14px pl-[5px] text-[var(--top-header-text-color)]">
v-if="userName"
class="<lg:hidden text-14px pl-[5px] text-[var(--top-header-text-color)]"
>
莳松科技管理员
</span>
<span v-else class="<lg:hidden text-14px pl-[5px] text-[var(--top-header-text-color)]">
{{ userName }} {{ userName }}
</span> </span>
</div> </div>

@ -1,6 +1,15 @@
import { store } from '../index' import { store } from '../index'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { getAccessToken, removeToken } from '@/utils/auth' import {
getAccessToken,
removeToken,
setToken,
getRefreshToken,
getTenantId,
getAppId,
setTenantId,
setAppId
} from '@/utils/auth'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { getInfo, loginOut } from '@/api/login' import { getInfo, loginOut } from '@/api/login'
@ -51,7 +60,7 @@ export const useUserStore = defineStore('admin-user', {
} }
let userInfo = wsCache.get(CACHE_KEY.USER) let userInfo = wsCache.get(CACHE_KEY.USER)
if (!userInfo) { if (!userInfo) {
userInfo = await getInfo() userInfo = await getInfo({})
} }
this.permissions = userInfo.permissions this.permissions = userInfo.permissions
this.roles = userInfo.roles this.roles = userInfo.roles
@ -75,6 +84,21 @@ export const useUserStore = defineStore('admin-user', {
avatar: '', avatar: '',
nickname: '' nickname: ''
} }
},
refresh() {
const token = getAccessToken()
const refreshToken = getRefreshToken()
const tenantId = getTenantId()
const appId = getAppId()
wsCache.clear()
this.resetState()
setTenantId(tenantId)
setAppId(appId)
setToken({
accessToken: token, // 访问令牌
refreshToken: refreshToken // 刷新令牌
})
window.location.href = ''
} }
} }
}) })

@ -49,6 +49,13 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20">
<el-col :span="12" :offset="0">
<el-form-item label="排序" prop="sort">
<el-input-number v-model="formData.sort" :min="0" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="24" :offset="0"> <el-col :span="24" :offset="0">
<el-form-item label="状态" prop="remark"> <el-form-item label="状态" prop="remark">
@ -78,16 +85,14 @@ const formLoading = ref(false) // 表单的加载中:1)修改时的数据加
const formType = ref('') // create - update - const formType = ref('') // create - update -
const formData = ref({ const formData = ref({
id: undefined, id: undefined,
title: '',
parentId: undefined, parentId: undefined,
name: undefined, name: undefined,
sort: undefined, sort: 1,
leaderUserId: undefined, leaderUserId: undefined,
phone: undefined, status: CommonStatusEnum.ENABLE,
email: undefined, remark: undefined
status: CommonStatusEnum.ENABLE
}) })
const formRules = reactive({ const formRules = reactive<any>({
parentId: [{ required: true, message: '上级部门不能为空', trigger: 'blur' }], parentId: [{ required: true, message: '上级部门不能为空', trigger: 'blur' }],
name: [{ required: true, message: '部门名称不能为空', trigger: 'blur' }], name: [{ required: true, message: '部门名称不能为空', trigger: 'blur' }],
sort: [{ required: true, message: '显示排序不能为空', trigger: 'blur' }], sort: [{ required: true, message: '显示排序不能为空', trigger: 'blur' }],
@ -153,14 +158,12 @@ const submitForm = async () => {
const resetForm = () => { const resetForm = () => {
formData.value = { formData.value = {
id: undefined, id: undefined,
title: '',
parentId: undefined, parentId: undefined,
name: undefined, name: undefined,
sort: undefined, sort: 1,
leaderUserId: undefined, leaderUserId: undefined,
phone: undefined, status: CommonStatusEnum.ENABLE,
email: undefined, remark: undefined
status: CommonStatusEnum.ENABLE
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }

@ -42,10 +42,10 @@ const pageSize = ref(20)
const currentPage = ref(1) const currentPage = ref(1)
const columns = ref([ const columns = ref([
{ prop: 'nickname', label: '姓名' }, { prop: 'name', label: '姓名', width: '200px' },
{ prop: 'mobile', label: '手机号' }, { prop: 'mobile', label: '手机号', width: '150px' },
{ prop: 'deptName', label: '部门' }, { prop: 'deptName', label: '部门' },
{ prop: '', label: '角色', width: '300px' } { prop: 'roles', label: '角色' }
]) ])
async function getList() { async function getList() {

@ -1,5 +1,5 @@
<template> <template>
<Dialog v-model="dialogVisible" :title="dialogTitle"> <Dialog v-model="dialogVisible" :title="dialogTitle" style="width: 800px">
<el-form <el-form
ref="formRef" ref="formRef"
v-loading="formLoading" v-loading="formLoading"
@ -37,7 +37,14 @@
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="角色" prop="role"> <el-form-item label="角色" prop="role">
<el-select v-model="formData.roleIds" multiple placeholder="请选择角色"> <el-select
v-model="formData.roleIds"
multiple
collapse-tags
collapse-tags-tooltip
:max-collapse-tags="2"
placeholder="请选择角色"
>
<el-option <el-option
v-for="item in roleOptions" v-for="item in roleOptions"
:key="item.id" :key="item.id"
@ -77,6 +84,20 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20">
<el-col :span="12" :offset="0">
<el-form-item label="入职日期" prop="hireDate">
<el-date-picker
v-model="formData.hireDate"
type="date"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
placeholder="选择日期时间"
style="width: 100%"
/>
</el-form-item>
</el-col>
</el-row>
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="备注"> <el-form-item label="备注">
@ -94,6 +115,8 @@
<script lang="ts" name="SystemUserForm" setup> <script lang="ts" name="SystemUserForm" setup>
import { CommonStatusEnum } from '@/utils/constants' import { CommonStatusEnum } from '@/utils/constants'
import { defaultProps, handleTree } from '@/utils/tree' import { defaultProps, handleTree } from '@/utils/tree'
import { formatDate } from '@/utils/formatTime'
import * as RoleApi from '@/api/system/role' import * as RoleApi from '@/api/system/role'
import * as DeptApi from '@/api/system/dept' import * as DeptApi from '@/api/system/dept'
import * as UserApi from '@/api/system/user' import * as UserApi from '@/api/system/user'
@ -116,9 +139,10 @@ const formData = ref({
sex: 1, sex: 1,
remark: '', remark: '',
status: CommonStatusEnum.ENABLE, status: CommonStatusEnum.ENABLE,
roleIds: [] roleIds: [],
hireDate: ''
}) })
const formRules = { const formRules = ref<any>({
username: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }], username: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }],
nickname: [{ required: true, message: '用户昵称不能为空', trigger: 'blur' }], nickname: [{ required: true, message: '用户昵称不能为空', trigger: 'blur' }],
password: [{ required: true, message: '用户密码不能为空', trigger: 'blur' }], password: [{ required: true, message: '用户密码不能为空', trigger: 'blur' }],
@ -136,10 +160,10 @@ const formRules = {
trigger: 'blur' trigger: 'blur'
} }
] ]
} })
const formRef = ref() // Ref const formRef = ref() // Ref
const deptList = ref<Tree[]>([]) // const deptList = ref<Tree[]>([]) //
const roleOptions = ref([]) const roleOptions = ref<any>([])
/** 打开弹窗 */ /** 打开弹窗 */
const open = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
@ -202,7 +226,8 @@ const resetForm = () => {
sex: 1, sex: 1,
remark: '', remark: '',
status: CommonStatusEnum.ENABLE, status: CommonStatusEnum.ENABLE,
roleIds: [] roleIds: [],
hireDate: formatDate(new Date(), 'YYYY-MM-DD')
} }
formRef.value?.resetFields() formRef.value?.resetFields()
} }

@ -1,5 +1,5 @@
<template> <template>
<Error type="403" @error-click="push('/')" /> <Error type="403" @error-click="push('/Home/index')" />
</template> </template>
<script lang="ts" name="Error403" setup> <script lang="ts" name="Error403" setup>
const { push } = useRouter() const { push } = useRouter()

@ -1,5 +1,5 @@
<template> <template>
<Error @error-click="push('/')" /> <Error @error-click="push('/Home/index')" />
</template> </template>
<script lang="ts" name="Error404" setup> <script lang="ts" name="Error404" setup>
const { push } = useRouter() const { push } = useRouter()

@ -1,5 +1,5 @@
<template> <template>
<Error type="500" @error-click="push('/')" /> <Error type="500" @error-click="push('/Home/index')" />
</template> </template>
<script lang="ts" name="Error500" setup> <script lang="ts" name="Error500" setup>
const { push } = useRouter() const { push } = useRouter()

@ -0,0 +1,103 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" width="800px">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
:rules="formRules"
label-width="80px"
>
<el-form-item label="名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入供应商名称" />
</el-form-item>
<el-form-item label="排序" prop="orderNum">
<el-input v-model="formData.orderNum" placeholder="请输入排序" type="number" :min="0" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input
type="textarea"
v-model="formData.remark"
placeholder="请输入备注"
:autosize="{ minRows: 4, maxRows: 8 }"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script name="DialogSupplier" setup>
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
name: '',
orderNum: 1,
remark: ''
})
const formRules = reactive({
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type, info) => {
dialogVisible.value = true
dialogTitle.value = type == 'update' ? '修改供应商' : '新增供应商'
formType.value = type
resetForm()
//
if (info.id) {
formLoading.value = true
try {
formData.value = { ...info }
// formData.value = await UserApi.getUser(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef.value) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
// const data = formData.value as unknown as UserApi.UserVO
if (formType.value === 'create') {
// await UserApi.createUser(data)
message.success(t('common.createSuccess'))
} else {
// await UserApi.updateUser(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
name: '',
orderNum: 1,
remark: ''
}
formRef.value?.resetFields()
}
</script>

@ -0,0 +1,34 @@
<template>
<el-form :model="form" ref="formRef" label-width="auto">
<el-form-item label="采购申请自动通过">
<el-radio-group v-model="form.autoAuditPurchase">
<el-radio :label="0"> </el-radio>
<el-radio :label="1"> </el-radio>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">保存</el-button>
<el-button @click="getData">刷新</el-button>
</el-form-item>
</el-form>
</template>
<script setup name="BasicSettingMall">
const message = useMessage()
const form = ref({
autoAuditPurchase: 0
})
function getData() {
form.value = {
autoAuditPurchase: 1
}
}
function onSubmit() {
message.success('保存成功')
}
</script>
<style lang="scss" scoped></style>

@ -0,0 +1,95 @@
<template>
<div>
<el-form ref="queryForm" :model="searchForm" label-width="0" inline>
<el-form-item>
<el-input
v-model="searchForm.name"
placeholder="请输入名称"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery">搜索</el-button>
<el-button @click="resetQuery">重置</el-button>
<el-button type="primary" @click="openForm('create', null)">新增</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="tableList">
<el-table-column prop="name" label="供应商名称" />
<el-table-column prop="orderNum" label="排序" width="100px" />
<el-table-column prop="remark" label="备注" />
<el-table-column label="创建时间" prop="createTime" width="180px" />
<el-table-column label="创建人" prop="createUser" width="150px" />
<el-table-column label="操作">
<template #default="scope">
<el-button type="primary" text @click="openForm('update', scope.row)">修改</el-button>
<el-button type="danger" text @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<Pagination
v-model:limit="searchForm.pageSize"
v-model:page="searchForm.pageNum"
:total="total"
@pagination="handleQuery"
/>
<DialogSupplier ref="brandDialog" @success="handleQuery" />
</div>
</template>
<script setup name="SupplierSet">
import DialogSupplier from './DialogSupplier.vue'
const searchForm = ref({
pageNum: 1,
pageSize: 20
})
const total = ref(0)
const brandDialog = ref()
const tableList = ref([])
const loading = ref(false)
function handleQuery() {
searchForm.value.pageNum = 1
getList()
}
function resetQuery() {
searchForm.value = {
name: '',
pageSize: 20,
pageNum: 1
}
getList()
}
function getList() {
tableList.value = [
{
id: 1,
name: '测试'
}
]
}
function openForm(type, info) {
brandDialog.value.open(type, info)
}
async function handleDelete(row) {
try {
console.log(row)
//
await message.delConfirm()
//
// await UserApi.deleteUser(row.id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
</script>
<style lang="scss" scoped></style>

@ -9,6 +9,12 @@
<el-tab-pane label="品牌设置" :name="2"> <el-tab-pane label="品牌设置" :name="2">
<BrandSet /> <BrandSet />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="供应商设置" :name="3">
<SupplierSet />
</el-tab-pane>
<el-tab-pane label="常规设置" :name="4">
<GeneralSet />
</el-tab-pane>
<el-tab-pane label="消息通知" :name="9"> <el-tab-pane label="消息通知" :name="9">
<MsgSend /> <MsgSend />
</el-tab-pane> </el-tab-pane>
@ -16,10 +22,12 @@
</template> </template>
<script setup> <script setup>
import GeneralSet from './Comp/GeneralSet.vue'
import FieldProduct from './Comp/FieldProduct.vue' import FieldProduct from './Comp/FieldProduct.vue'
import MsgSend from './Comp/MsgSend.vue' import MsgSend from './Comp/MsgSend.vue'
import CategorySet from './Comp/CategorySet.vue' import CategorySet from './Comp/CategorySet.vue'
import BrandSet from './Comp/BrandSet.vue' import BrandSet from './Comp/BrandSet.vue'
import SupplierSet from './Comp/SupplierSet.vue'
const tabIndex = ref(0) const tabIndex = ref(0)
</script> </script>

@ -24,13 +24,13 @@
{{ t('profile.user.dept') }} {{ t('profile.user.dept') }}
<div v-if="userInfo?.dept" class="pull-right">{{ userInfo?.dept.name }}</div> <div v-if="userInfo?.dept" class="pull-right">{{ userInfo?.dept.name }}</div>
</li> </li>
<li class="list-group-item"> <!-- <li class="list-group-item">
<Icon class="mr-5px" icon="ep:suitcase" /> <Icon class="mr-5px" icon="ep:suitcase" />
{{ t('profile.user.posts') }} {{ t('profile.user.posts') }}
<div v-if="userInfo?.posts" class="pull-right"> <div v-if="userInfo?.posts" class="pull-right">
{{ userInfo?.posts.map((post) => post.name).join(',') }} {{ userInfo?.posts.map((post) => post.name).join(',') }}
</div> </div>
</li> </li> -->
<li class="list-group-item"> <li class="list-group-item">
<Icon class="mr-5px" icon="icon-park-outline:peoples" /> <Icon class="mr-5px" icon="icon-park-outline:peoples" />
{{ t('profile.user.roles') }} {{ t('profile.user.roles') }}

Loading…
Cancel
Save