mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-23 03:50:33 +08:00
add dashboard/account
This commit is contained in:
@@ -120,6 +120,31 @@ func init() {
|
|||||||
writeresult(w, codeSuccess, n, messageOk, typeSuccess)
|
writeresult(w, codeSuccess, n, messageOk, typeSuccess)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
apimap["/api/getUsersList"] = &apihandler{"GET", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
token := r.Header.Get("Authorization")
|
||||||
|
ret, err := getUsersList(token)
|
||||||
|
if err != nil {
|
||||||
|
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeresult(w, codeSuccess, &ret, messageOk, typeSuccess)
|
||||||
|
}}
|
||||||
|
|
||||||
|
apimap["/api/isNameExist"] = &apihandler{"GET", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
token := r.Header.Get("Authorization")
|
||||||
|
name := r.URL.Query().Get("username")
|
||||||
|
if name == "" {
|
||||||
|
writeresult(w, codeError, nil, "empty username", typeError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
yes, err := isNameExist(token, name)
|
||||||
|
if err != nil {
|
||||||
|
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeresult(w, codeSuccess, yes, messageOk, typeSuccess)
|
||||||
|
}}
|
||||||
|
|
||||||
apimap["/api/setPassword"] = &apihandler{"POST", func(w http.ResponseWriter, r *http.Request) {
|
apimap["/api/setPassword"] = &apihandler{"POST", func(w http.ResponseWriter, r *http.Request) {
|
||||||
type setpasswordbody struct {
|
type setpasswordbody struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ func (u *UserDatabase) AddUser(user *User, opname string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserInfo ...
|
// UpdateUserInfo ...
|
||||||
func (u *UserDatabase) UpdateUserInfo(id int, nick, avtr, desc string) error {
|
func (u *UserDatabase) UpdateUserInfo(id int, opname, nick, avtr, desc string) error {
|
||||||
user, err := u.GetUserByID(id)
|
user, err := u.GetUserByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -180,7 +180,7 @@ func (u *UserDatabase) UpdateUserInfo(id int, nick, avtr, desc string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return u.SendMessage("更新了个人信息", user.Name, *user.ID)
|
return u.SendMessage("更新了个人信息", opname, *user.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserRole ...
|
// UpdateUserRole ...
|
||||||
@@ -203,7 +203,7 @@ func (u *UserDatabase) UpdateUserRole(id int, nr UserRole, opname string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserPassword ...
|
// UpdateUserPassword ...
|
||||||
func (u *UserDatabase) UpdateUserPassword(id int, npwd string) error {
|
func (u *UserDatabase) UpdateUserPassword(id int, opname, npwd string) error {
|
||||||
if npwd == "" {
|
if npwd == "" {
|
||||||
return ErrEmptyPassword
|
return ErrEmptyPassword
|
||||||
}
|
}
|
||||||
@@ -220,11 +220,11 @@ func (u *UserDatabase) UpdateUserPassword(id int, npwd string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return u.SendMessage("更新了密码", user.Name, *user.ID)
|
return u.SendMessage("更新了密码", opname, *user.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserContact ...
|
// UpdateUserContact ...
|
||||||
func (u *UserDatabase) UpdateUserContact(id int, ncont string) error {
|
func (u *UserDatabase) UpdateUserContact(id int, opname, ncont string) error {
|
||||||
if ncont == "" {
|
if ncont == "" {
|
||||||
return ErrEmptyContact
|
return ErrEmptyContact
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ func (u *UserDatabase) UpdateUserContact(id int, ncont string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return u.SendMessage("更新了联系方式", user.Name, *user.ID)
|
return u.SendMessage("更新了联系方式", opname, *user.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByName avoids sql injection by limiting username to 0-9A-Za-z
|
// GetUserByName avoids sql injection by limiting username to 0-9A-Za-z
|
||||||
@@ -307,7 +307,7 @@ func (u *UserDatabase) GetUsers() (users []User, err error) {
|
|||||||
user.Pswd = ""
|
user.Pswd = ""
|
||||||
users[i] = user
|
users[i] = user
|
||||||
i++
|
i++
|
||||||
if i >= n {
|
if i > n {
|
||||||
return ErrInvalidUsersCount
|
return ErrInvalidUsersCount
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func acceptMessage(token string, id int) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return global.UserDB.UpdateUserPassword(*u.ID, "123456")
|
return global.UserDB.UpdateUserPassword(*u.ID, user.Name, "123456")
|
||||||
default:
|
default:
|
||||||
return errNothingToDo
|
return errNothingToDo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errInvalidToken = errors.New("invalid token")
|
errInvalidToken = errors.New("invalid token")
|
||||||
|
errNoListUsersPermission = errors.New("no list users permission")
|
||||||
)
|
)
|
||||||
|
|
||||||
type getUserInfoResult struct {
|
type getUserInfoResult struct {
|
||||||
@@ -89,6 +90,50 @@ func getUsersCount(token string) (int, error) {
|
|||||||
return global.UserDB.GetUsersCount()
|
return global.UserDB.GetUsersCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type getUsersListResult struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Nick string `json:"nick"`
|
||||||
|
Role string `json:"role"`
|
||||||
|
Date string `json:"date"`
|
||||||
|
Desc string `json:"desc"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUsersList(token string) ([]getUsersListResult, error) {
|
||||||
|
user := usertokens.Get(token)
|
||||||
|
if user == nil {
|
||||||
|
return nil, errInvalidToken
|
||||||
|
}
|
||||||
|
if !user.IsSuper() {
|
||||||
|
return nil, errNoListUsersPermission
|
||||||
|
}
|
||||||
|
us, err := global.UserDB.GetUsers()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret := make([]getUsersListResult, len(us))
|
||||||
|
for i, u := range us {
|
||||||
|
ret[i].ID = *u.ID
|
||||||
|
ret[i].Name = u.Name
|
||||||
|
ret[i].Nick = u.Nick
|
||||||
|
ret[i].Role = u.Role.Nick()
|
||||||
|
ret[i].Date = time.Unix(user.Date, 0).Format(chineseDateLayout)
|
||||||
|
ret[i].Desc = u.Desc
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isNameExist(token, name string) (bool, error) {
|
||||||
|
user := usertokens.Get(token)
|
||||||
|
if user == nil {
|
||||||
|
return false, errInvalidToken
|
||||||
|
}
|
||||||
|
if !user.IsSuper() {
|
||||||
|
return false, errNoListUsersPermission
|
||||||
|
}
|
||||||
|
return global.UserDB.IsNameExists(name), nil
|
||||||
|
}
|
||||||
|
|
||||||
func setUserPassword(id int, token, npwd string) error {
|
func setUserPassword(id int, token, npwd string) error {
|
||||||
user, err := global.UserDB.GetUserByID(id)
|
user, err := global.UserDB.GetUserByID(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -100,7 +145,7 @@ func setUserPassword(id int, token, npwd string) error {
|
|||||||
if token != hex.EncodeToString(h.Sum(make([]byte, 0, 16))) {
|
if token != hex.EncodeToString(h.Sum(make([]byte, 0, 16))) {
|
||||||
return errInvalidToken
|
return errInvalidToken
|
||||||
}
|
}
|
||||||
return global.UserDB.UpdateUserPassword(id, npwd)
|
return global.UserDB.UpdateUserPassword(id, user.Name, npwd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUserContact(id int, token, ncont string) error {
|
func setUserContact(id int, token, ncont string) error {
|
||||||
@@ -114,7 +159,7 @@ func setUserContact(id int, token, ncont string) error {
|
|||||||
if token != hex.EncodeToString(h.Sum(make([]byte, 0, 16))) {
|
if token != hex.EncodeToString(h.Sum(make([]byte, 0, 16))) {
|
||||||
return errInvalidToken
|
return errInvalidToken
|
||||||
}
|
}
|
||||||
return global.UserDB.UpdateUserContact(id, ncont)
|
return global.UserDB.UpdateUserContact(id, user.Name, ncont)
|
||||||
}
|
}
|
||||||
|
|
||||||
// setUserInfo may change the arguments
|
// setUserInfo may change the arguments
|
||||||
@@ -144,7 +189,7 @@ func setUserInfo(id int, nick, desc, avtr *string) error {
|
|||||||
if a == user.Avtr {
|
if a == user.Avtr {
|
||||||
a = ""
|
a = ""
|
||||||
}
|
}
|
||||||
return global.UserDB.UpdateUserInfo(id, n, a, d)
|
return global.UserDB.UpdateUserInfo(id, user.Name, n, a, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetPassword(ip, name, mobile string) error {
|
func resetPassword(ip, name, mobile string) error {
|
||||||
|
|||||||
@@ -23,14 +23,12 @@ export type MenuParams = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AccountListItem {
|
export interface AccountListItem {
|
||||||
id: string
|
id: number
|
||||||
account: string
|
name: string
|
||||||
email: string
|
nick: string
|
||||||
nickname: string
|
|
||||||
role: number
|
role: number
|
||||||
createTime: string
|
date: string
|
||||||
remark: string
|
desc: string
|
||||||
status: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeptListItem {
|
export interface DeptListItem {
|
||||||
@@ -52,12 +50,8 @@ export interface MenuListItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface RoleListItem {
|
export interface RoleListItem {
|
||||||
id: string
|
|
||||||
roleName: string
|
roleName: string
|
||||||
roleValue: string
|
value: string
|
||||||
status: number
|
|
||||||
orderNo: string
|
|
||||||
createTime: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ import {
|
|||||||
AccountParams,
|
AccountParams,
|
||||||
DeptListItem,
|
DeptListItem,
|
||||||
MenuParams,
|
MenuParams,
|
||||||
RoleParams,
|
// RoleParams,
|
||||||
RolePageParams,
|
RolePageParams,
|
||||||
MenuListGetResultModel,
|
MenuListGetResultModel,
|
||||||
DeptListGetResultModel,
|
DeptListGetResultModel,
|
||||||
AccountListGetResultModel,
|
AccountListGetResultModel,
|
||||||
RolePageListGetResultModel,
|
RolePageListGetResultModel,
|
||||||
RoleListGetResultModel,
|
// RoleListGetResultModel,
|
||||||
|
RoleListItem,
|
||||||
} from './model/systemModel'
|
} from './model/systemModel'
|
||||||
import { defHttp } from '/@/utils/http/axios'
|
import { defHttp } from '/@/utils/http/axios'
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ enum Api {
|
|||||||
setRoleStatus = '/system/setRoleStatus',
|
setRoleStatus = '/system/setRoleStatus',
|
||||||
MenuList = '/system/getMenuList',
|
MenuList = '/system/getMenuList',
|
||||||
RolePageList = '/system/getRoleListByPage',
|
RolePageList = '/system/getRoleListByPage',
|
||||||
GetAllRoleList = '/system/getAllRoleList',
|
// GetAllRoleList = '/system/getAllRoleList',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAccountList = (params: AccountParams) =>
|
export const getAccountList = (params: AccountParams) =>
|
||||||
@@ -34,8 +35,22 @@ export const getMenuList = (params?: MenuParams) =>
|
|||||||
export const getRoleListByPage = (params?: RolePageParams) =>
|
export const getRoleListByPage = (params?: RolePageParams) =>
|
||||||
defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params })
|
defHttp.get<RolePageListGetResultModel>({ url: Api.RolePageList, params })
|
||||||
|
|
||||||
export const getAllRoleList = (params?: RoleParams) =>
|
export const getAllRoleList = () => {
|
||||||
defHttp.get<RoleListGetResultModel>({ url: Api.GetAllRoleList, params })
|
return [
|
||||||
|
{
|
||||||
|
roleName: '课程组长',
|
||||||
|
value: 'super',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roleName: '归档代理',
|
||||||
|
value: 'filemgr',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roleName: '课程组员',
|
||||||
|
value: 'user',
|
||||||
|
},
|
||||||
|
] as RoleListItem[]
|
||||||
|
}
|
||||||
|
|
||||||
export const setRoleStatus = (id: number, status: string) =>
|
export const setRoleStatus = (id: number, status: string) =>
|
||||||
defHttp.post({ url: Api.setRoleStatus, params: { id, status } })
|
defHttp.post({ url: Api.setRoleStatus, params: { id, status } })
|
||||||
|
|||||||
@@ -102,3 +102,12 @@ export interface GetUserInfoModel {
|
|||||||
export interface GetLoginSaltModel {
|
export interface GetLoginSaltModel {
|
||||||
salt: string
|
salt: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GetUsersListModel {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
nick: string
|
||||||
|
role: number
|
||||||
|
date: string
|
||||||
|
desc: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
ResetPasswordResultModel,
|
ResetPasswordResultModel,
|
||||||
RegisterResultModel,
|
RegisterResultModel,
|
||||||
GetLoginSaltModel,
|
GetLoginSaltModel,
|
||||||
|
GetUsersListModel,
|
||||||
} from './model/userModel'
|
} from './model/userModel'
|
||||||
|
|
||||||
import { ErrorMessageMode } from '/#/axios'
|
import { ErrorMessageMode } from '/#/axios'
|
||||||
@@ -26,8 +27,8 @@ enum Api {
|
|||||||
Register = '/register',
|
Register = '/register',
|
||||||
GetUserInfo = '/getUserInfo',
|
GetUserInfo = '/getUserInfo',
|
||||||
GetUsersCount = '/getUsersCount',
|
GetUsersCount = '/getUsersCount',
|
||||||
GetPermCode = '/getPermCode',
|
GetUsersList = '/getUsersList',
|
||||||
TestRetry = '/testRetry',
|
IsNameExist = '/isNameExist',
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,23 +142,23 @@ export function getUsersCount() {
|
|||||||
return defHttp.get<number>({ url: Api.GetUsersCount }, { errorMessageMode: 'none' })
|
return defHttp.get<number>({ url: Api.GetUsersCount }, { errorMessageMode: 'none' })
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export function getPermCode() {
|
/**
|
||||||
return defHttp.get<string[]>({ url: Api.GetPermCode })
|
* @description: getUsersList
|
||||||
}*/
|
*/
|
||||||
|
export function getUsersList() {
|
||||||
|
return defHttp.get<GetUsersListModel[]>({ url: Api.GetUsersList }, { errorMessageMode: 'none' })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: isNameExist
|
||||||
|
*/
|
||||||
|
export function isNameExist(username: string) {
|
||||||
|
return defHttp.get<boolean>(
|
||||||
|
{ url: Api.IsNameExist, params: { username } },
|
||||||
|
{ errorMessageMode: 'none' },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function doLogout() {
|
export function doLogout() {
|
||||||
return defHttp.get({ url: Api.Logout }, { errorMessageMode: 'none' })
|
return defHttp.get({ url: Api.Logout }, { errorMessageMode: 'none' })
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export function testRetry() {
|
|
||||||
return defHttp.get(
|
|
||||||
{ url: Api.TestRetry },
|
|
||||||
{
|
|
||||||
retryRequest: {
|
|
||||||
isOpenRetry: true,
|
|
||||||
count: 5,
|
|
||||||
waitTime: 1000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}*/
|
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ export default {
|
|||||||
about: '关于',
|
about: '关于',
|
||||||
workbench: '工作台',
|
workbench: '工作台',
|
||||||
analysis: '分析页',
|
analysis: '分析页',
|
||||||
|
account: '用户管理',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ const menu: MenuModule = {
|
|||||||
path: 'analysis',
|
path: 'analysis',
|
||||||
name: t('routes.dashboard.analysis'),
|
name: t('routes.dashboard.analysis'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'account',
|
||||||
|
name: t('routes.dashboard.account'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'workbench',
|
path: 'workbench',
|
||||||
name: t('routes.dashboard.workbench'),
|
name: t('routes.dashboard.workbench'),
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ const dashboard: AppRouteModule = {
|
|||||||
roles: [RoleEnum.SUPER],
|
roles: [RoleEnum.SUPER],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'account',
|
||||||
|
name: 'Account',
|
||||||
|
component: () => import('/@/views/dashboard/account/index.vue'),
|
||||||
|
meta: {
|
||||||
|
// affix: true,
|
||||||
|
title: t('routes.dashboard.account'),
|
||||||
|
roles: [RoleEnum.SUPER],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'workbench',
|
path: 'workbench',
|
||||||
name: 'Workbench',
|
name: 'Workbench',
|
||||||
|
|||||||
68
frontend/vben/src/views/dashboard/account/AccountModal.vue
Normal file
68
frontend/vben/src/views/dashboard/account/AccountModal.vue
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent, ref, computed, unref } from 'vue'
|
||||||
|
import { BasicModal, useModalInner } from '/@/components/Modal'
|
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||||
|
import { nameFormSchema } from './account.data'
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'AccountModal',
|
||||||
|
components: { BasicModal, BasicForm },
|
||||||
|
emits: ['success', 'register'],
|
||||||
|
setup(_, { emit }) {
|
||||||
|
const isUpdate = ref(true)
|
||||||
|
const rowId = ref('')
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: nameFormSchema,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
actionColOptions: {
|
||||||
|
span: 23,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||||
|
resetFields()
|
||||||
|
setModalProps({ confirmLoading: false })
|
||||||
|
isUpdate.value = !!data?.isUpdate
|
||||||
|
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
rowId.value = data.record.id
|
||||||
|
setFieldsValue({
|
||||||
|
...data.record,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSchema([
|
||||||
|
{
|
||||||
|
field: 'pwd',
|
||||||
|
show: !unref(isUpdate),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增账号' : '编辑账号'))
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
const values = await validate()
|
||||||
|
setModalProps({ confirmLoading: true })
|
||||||
|
// TODO custom api
|
||||||
|
console.log(values)
|
||||||
|
closeModal()
|
||||||
|
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } })
|
||||||
|
} finally {
|
||||||
|
setModalProps({ confirmLoading: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { registerModal, registerForm, getTitle, handleSubmit }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
118
frontend/vben/src/views/dashboard/account/account.data.ts
Normal file
118
frontend/vben/src/views/dashboard/account/account.data.ts
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import { isNameExist } from '/@/api/sys/user'
|
||||||
|
import { BasicColumn } from '/@/components/Table'
|
||||||
|
import { FormSchema } from '/@/components/Table'
|
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [
|
||||||
|
{
|
||||||
|
title: '用户名',
|
||||||
|
dataIndex: 'name',
|
||||||
|
width: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '昵称',
|
||||||
|
dataIndex: 'nick',
|
||||||
|
width: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'date',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '角色',
|
||||||
|
dataIndex: 'role',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '简介',
|
||||||
|
dataIndex: 'desc',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const searchFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
label: '用户名',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 8 },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'nick',
|
||||||
|
label: '昵称',
|
||||||
|
component: 'Input',
|
||||||
|
colProps: { span: 8 },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const nameFormSchema: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'name',
|
||||||
|
label: '用户名',
|
||||||
|
component: 'Input',
|
||||||
|
helpMessage: ['不能输入带有admin的用户名'],
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
message: '请输入用户名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
validator(_, value) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
isNameExist(value)
|
||||||
|
.then((v) => {
|
||||||
|
if (v) resolve()
|
||||||
|
else reject('用户名已存在')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(err.message || '验证失败')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'pwd',
|
||||||
|
label: '密码',
|
||||||
|
component: 'InputPassword',
|
||||||
|
required: true,
|
||||||
|
ifShow: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '角色',
|
||||||
|
field: 'role',
|
||||||
|
component: 'ApiSelect',
|
||||||
|
componentProps: {
|
||||||
|
api: () => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
roleName: '课程组长',
|
||||||
|
value: 'super',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roleName: '归档代理',
|
||||||
|
value: 'filemgr',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
roleName: '课程组员',
|
||||||
|
value: 'user',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
labelField: 'roleName',
|
||||||
|
valueField: 'value',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'nick',
|
||||||
|
label: '昵称',
|
||||||
|
component: 'Input',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '简介',
|
||||||
|
field: 'desc',
|
||||||
|
component: 'InputTextArea',
|
||||||
|
},
|
||||||
|
]
|
||||||
124
frontend/vben/src/views/dashboard/account/index.vue
Normal file
124
frontend/vben/src/views/dashboard/account/index.vue
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<template>
|
||||||
|
<PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
|
||||||
|
<BasicTable @register="registerTable" :searchInfo="searchInfo">
|
||||||
|
<template #toolbar>
|
||||||
|
<a-button type="primary" @click="handleCreate">新增账号</a-button>
|
||||||
|
</template>
|
||||||
|
<template #bodyCell="{ column, record }">
|
||||||
|
<template v-if="column.key === 'action'">
|
||||||
|
<TableAction
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
icon: 'clarity:note-edit-line',
|
||||||
|
tooltip: '编辑用户资料',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'ant-design:delete-outlined',
|
||||||
|
color: 'error',
|
||||||
|
tooltip: '删除此账号',
|
||||||
|
popConfirm: {
|
||||||
|
title:
|
||||||
|
'为确保安全, 删除账号仅仅是禁止了登录, 必要情况下用户仍然可以通过忘记密码的方式找回账号',
|
||||||
|
placement: 'left',
|
||||||
|
confirm: handleDelete.bind(null, record),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<AccountModal @register="registerModal" @success="handleSuccess" />
|
||||||
|
</PageWrapper>
|
||||||
|
</template>
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent, reactive } from 'vue'
|
||||||
|
|
||||||
|
import { BasicTable, useTable, TableAction } from '/@/components/Table'
|
||||||
|
import { getUsersList } from '/@/api/sys/user'
|
||||||
|
import { PageWrapper } from '/@/components/Page'
|
||||||
|
|
||||||
|
import { useModal } from '/@/components/Modal'
|
||||||
|
import AccountModal from './AccountModal.vue'
|
||||||
|
|
||||||
|
import { columns, searchFormSchema } from './account.data'
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'AccountManagement',
|
||||||
|
components: { BasicTable, PageWrapper, AccountModal, TableAction },
|
||||||
|
setup() {
|
||||||
|
const [registerModal, { openModal }] = useModal()
|
||||||
|
const searchInfo = reactive<Recordable>({})
|
||||||
|
const [registerTable, { reload, updateTableDataRecord }] = useTable({
|
||||||
|
title: '账号列表',
|
||||||
|
api: getUsersList,
|
||||||
|
rowKey: 'id',
|
||||||
|
columns,
|
||||||
|
formConfig: {
|
||||||
|
labelWidth: 120,
|
||||||
|
schemas: searchFormSchema,
|
||||||
|
autoSubmitOnEnter: true,
|
||||||
|
},
|
||||||
|
useSearchForm: true,
|
||||||
|
showTableSetting: true,
|
||||||
|
bordered: true,
|
||||||
|
handleSearchInfoFn(info) {
|
||||||
|
console.log('handleSearchInfoFn', info)
|
||||||
|
return info
|
||||||
|
},
|
||||||
|
actionColumn: {
|
||||||
|
width: 120,
|
||||||
|
title: '操作',
|
||||||
|
dataIndex: 'action',
|
||||||
|
// slots: { customRender: 'action' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function handleCreate() {
|
||||||
|
openModal(true, {
|
||||||
|
isUpdate: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleEdit(record: Recordable) {
|
||||||
|
console.log(record)
|
||||||
|
openModal(true, {
|
||||||
|
record,
|
||||||
|
isUpdate: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDelete(record: Recordable) {
|
||||||
|
console.log(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSuccess({ isUpdate, values }) {
|
||||||
|
if (isUpdate) {
|
||||||
|
// 演示不刷新表格直接更新内部数据。
|
||||||
|
// 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
|
||||||
|
const result = updateTableDataRecord(values.id, values)
|
||||||
|
console.log(result)
|
||||||
|
} else {
|
||||||
|
reload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSelect(deptId = '') {
|
||||||
|
searchInfo.deptId = deptId
|
||||||
|
reload()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
registerTable,
|
||||||
|
registerModal,
|
||||||
|
handleCreate,
|
||||||
|
handleEdit,
|
||||||
|
handleDelete,
|
||||||
|
handleSuccess,
|
||||||
|
handleSelect,
|
||||||
|
searchInfo,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
@@ -36,8 +36,8 @@
|
|||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const userinfo = computed(() => userStore.getUserInfo)
|
const userinfo = computed(() => userStore.getUserInfo)
|
||||||
const enterDays = computed(() => {
|
const enterDays = computed(() => {
|
||||||
const date: Date = new Date(new Date().getTime() - userStore.getUserInfo.date * 1000)
|
const date: number = new Date().getTime() - userStore.getUserInfo.date * 1000
|
||||||
return date.getDay()
|
return (date / 1000 / 3600 / 24).toFixed(2)
|
||||||
})
|
})
|
||||||
const userscount = ref(0)
|
const userscount = ref(0)
|
||||||
getUsersCount().then((value: number) => {
|
getUsersCount().then((value: number) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user