page: 📄 角色相关内容CURD和部分代码生成器修改
This commit is contained in:
parent
bf0d3f9c66
commit
7871ff9dbe
70
src/App.vue
70
src/App.vue
|
@ -1,21 +1,21 @@
|
|||
<template>
|
||||
<el-config-provider :locale="currentLocale">
|
||||
<router-view />
|
||||
<ReDialog />
|
||||
</el-config-provider>
|
||||
<el-config-provider :locale="currentLocale">
|
||||
<router-view />
|
||||
<ReDialog />
|
||||
</el-config-provider>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ElConfigProvider } from "element-plus";
|
||||
import { computed, onMounted } from "vue";
|
||||
import { ReDialog } from "@/components/BaseDialog";
|
||||
import en from "element-plus/es/locale/lang/en";
|
||||
import zhCn from "element-plus/es/locale/lang/zh-cn";
|
||||
import plusEn from "plus-pro-components/es/locale/lang/en";
|
||||
import plusZhCn from "plus-pro-components/es/locale/lang/zh-cn";
|
||||
import { useNav } from "@/layout/hooks/useNav";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { userI18nStore } from "@/store/i18n/i18n";
|
||||
import { ElConfigProvider } from 'element-plus';
|
||||
import { computed, onMounted } from 'vue';
|
||||
import { ReDialog } from '@/components/BaseDialog';
|
||||
import en from 'element-plus/es/locale/lang/en';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
import plusEn from 'plus-pro-components/es/locale/lang/en';
|
||||
import plusZhCn from 'plus-pro-components/es/locale/lang/zh-cn';
|
||||
import { useNav } from '@/layout/hooks/useNav';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { userI18nStore } from '@/store/i18n/i18n';
|
||||
|
||||
const i18nStore = userI18nStore();
|
||||
const i18n = useI18n();
|
||||
|
@ -25,36 +25,36 @@ const { $storage } = useNav();
|
|||
* * 设置多语言内容
|
||||
*/
|
||||
const setI18n = async () => {
|
||||
await i18nStore.fetchI18n();
|
||||
const languageData = JSON.parse(localStorage.getItem("i18nStore") as any);
|
||||
// 初始化设置多语言内容
|
||||
const locale = $storage.locale.locale;
|
||||
// 如果本地没有语言版本,设置为服务端默认内容
|
||||
if (locale == "" || locale == null || !locale) {
|
||||
const local = languageData.i18n.local;
|
||||
i18n.locale.value = local;
|
||||
$storage.locale = { locale: local };
|
||||
i18n.mergeLocaleMessage(local, languageData.i18n[local]);
|
||||
return;
|
||||
}
|
||||
await i18nStore.fetchI18n();
|
||||
const languageData = JSON.parse(localStorage.getItem('i18nStore') as any);
|
||||
// 初始化设置多语言内容
|
||||
const locale = $storage.locale.locale;
|
||||
// 如果本地没有语言版本,设置为服务端默认内容
|
||||
if (locale == '' || locale == null || !locale) {
|
||||
const local = languageData.i18n.local;
|
||||
i18n.locale.value = local;
|
||||
$storage.locale = { locale: local };
|
||||
i18n.mergeLocaleMessage(local, languageData.i18n[local]);
|
||||
return;
|
||||
}
|
||||
|
||||
i18n.locale.value = locale;
|
||||
$storage.locale = { locale };
|
||||
i18nStore.i18n.local = locale;
|
||||
i18n.mergeLocaleMessage(locale, languageData.i18n[locale]);
|
||||
i18n.locale.value = locale;
|
||||
$storage.locale = { locale };
|
||||
i18nStore.i18n.local = locale;
|
||||
i18n.mergeLocaleMessage(locale, languageData.i18n[locale]);
|
||||
};
|
||||
|
||||
/**
|
||||
* * 当前语言类别
|
||||
*/
|
||||
const currentLocale = computed(() => {
|
||||
const languageData = JSON.parse(localStorage.getItem("i18nStore") as any);
|
||||
const local = languageData ? languageData.i18n.local : {};
|
||||
return local === "zh" ? { ...zhCn, ...plusZhCn } : { ...plusEn, ...en };
|
||||
const languageData = JSON.parse(localStorage.getItem('i18nStore') as any);
|
||||
const local = languageData ? languageData.i18n.local : {};
|
||||
return local === 'zh' ? { ...zhCn, ...plusZhCn } : { ...plusEn, ...en };
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
// 设置多语言
|
||||
setI18n();
|
||||
// 设置多语言
|
||||
setI18n();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -2,7 +2,7 @@ import Axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|||
import type { PureHttpError, PureHttpRequestConfig, PureHttpResponse, RequestMethods } from './types';
|
||||
import NProgress from '../../utils/progress';
|
||||
import { formatToken, getToken } from '@/utils/auth';
|
||||
import { useUserStoreHook } from '@/store/modules/user';
|
||||
import { useUserStoreHook } from '@/store/system/user';
|
||||
import { defaultMockConfig } from '@/api/service/config';
|
||||
|
||||
class PureHttp {
|
||||
|
|
|
@ -2,7 +2,7 @@ import Axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|||
import type { PureHttpError, PureHttpRequestConfig, PureHttpResponse, RequestMethods } from './types';
|
||||
import NProgress from '@/utils/progress';
|
||||
import { formatToken, getToken, removeToken } from '@/utils/auth';
|
||||
import { useUserStoreHook } from '@/store/modules/user';
|
||||
import { useUserStoreHook } from '@/store/system/user';
|
||||
import { message } from '@/utils/message';
|
||||
import { router } from '@/store/utils';
|
||||
import { defaultConfig, whiteList } from '@/api/service/config';
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import { http } from '@/api/service/request';
|
||||
import type { BaseResult, ResultTable } from '@/api/service/types';
|
||||
|
||||
/**
|
||||
* 角色---获取角色列表
|
||||
*/
|
||||
export const fetchGetRoleList = (data: any) => {
|
||||
return http.request<BaseResult<ResultTable>>('get', `role/getRoleList/${data.currentPage}/${data.pageSize}`, { params: data });
|
||||
};
|
||||
|
||||
/**
|
||||
* 角色---添加角色
|
||||
*/
|
||||
export const fetchAddRole = (data: any) => {
|
||||
return http.request<BaseResult<object>>('post', 'role/addRole', { data });
|
||||
};
|
||||
|
||||
/**
|
||||
* 角色---更新角色
|
||||
*/
|
||||
export const fetchUpdateRole = (data: any) => {
|
||||
return http.request<BaseResult<object>>('put', 'role/updateRole', { data });
|
||||
};
|
||||
|
||||
/**
|
||||
* 角色---删除角色
|
||||
*/
|
||||
export const fetchDeleteRole = (data: any) => {
|
||||
return http.request<BaseResult<object>>('delete', 'role/deleteRole', { data });
|
||||
};
|
|
@ -9,7 +9,7 @@ import type { routeMetaType } from '../types';
|
|||
import { remainingPaths, router } from '@/router';
|
||||
import { computed, type CSSProperties } from 'vue';
|
||||
import { useAppStoreHook } from '@/store/modules/app';
|
||||
import { useUserStoreHook } from '@/store/modules/user';
|
||||
import { useUserStoreHook } from '@/store/system/user';
|
||||
import { isAllEmpty, useGlobal } from '@pureadmin/utils';
|
||||
import { useEpThemeStoreHook } from '@/store/epTheme';
|
||||
import { usePermissionStoreHook } from '@/store/permission';
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { fetchAddRole, fetchDeleteRole, fetchGetRoleList, fetchUpdateRole } from '@/api/v1/role';
|
||||
import { pageSizes } from '@/enums/baseConstant';
|
||||
import { storeMessage } from '@/utils/message';
|
||||
import { storePagination } from '@/store/useStorePagination';
|
||||
|
||||
/**
|
||||
* 角色 Store
|
||||
*/
|
||||
export const useRoleStore = defineStore('roleStore', {
|
||||
state() {
|
||||
return {
|
||||
// 角色列表
|
||||
datalist: [],
|
||||
// 查询表单
|
||||
form: {
|
||||
// 角色代码
|
||||
roleCode: undefined,
|
||||
// 描述
|
||||
description: undefined,
|
||||
},
|
||||
// 分页查询结果
|
||||
pagination: {
|
||||
currentPage: 1,
|
||||
pageSize: 150,
|
||||
total: 100,
|
||||
pageSizes,
|
||||
},
|
||||
// 加载
|
||||
loading: false,
|
||||
};
|
||||
},
|
||||
getters: {},
|
||||
actions: {
|
||||
/**
|
||||
* * 获取角色
|
||||
*/
|
||||
async getRoleList() {
|
||||
// 整理请求参数
|
||||
const data = { ...this.pagination, ...this.form };
|
||||
delete data.pageSizes;
|
||||
delete data.total;
|
||||
delete data.background;
|
||||
|
||||
// 获取角色列表
|
||||
const result = await fetchGetRoleList(data);
|
||||
|
||||
// 公共页面函数hook
|
||||
const pagination = storePagination.bind(this);
|
||||
return pagination(result);
|
||||
},
|
||||
|
||||
/**
|
||||
* * 添加角色
|
||||
*/
|
||||
async addRole(data: any) {
|
||||
const result = await fetchAddRole(data);
|
||||
return storeMessage(result);
|
||||
},
|
||||
|
||||
/**
|
||||
* * 修改角色
|
||||
*/
|
||||
async updateRole(data: any) {
|
||||
const result = await fetchUpdateRole(data);
|
||||
return storeMessage(result);
|
||||
},
|
||||
|
||||
/**
|
||||
* * 删除角色
|
||||
*/
|
||||
async deleteRole(data: any) {
|
||||
const result = await fetchDeleteRole(data);
|
||||
return storeMessage(result);
|
||||
},
|
||||
},
|
||||
});
|
|
@ -33,8 +33,6 @@ export const useUserStore = defineStore({
|
|||
setToken(result.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
message(result.message, { type: 'error' });
|
||||
return false;
|
||||
},
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import Cookies from 'js-cookie';
|
||||
import { useUserStore, useUserStoreHook } from '@/store/modules/user';
|
||||
import { useUserStore, useUserStoreHook } from '@/store/system/user';
|
||||
import { isIncludeAllChildren, isString, storageLocal } from '@pureadmin/utils';
|
||||
|
||||
export interface DataInfo<T> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { userI18nStore } from '@/store/i18n/i18n';
|
||||
import { deleteIds, onAdd, onDelete, onDeleteBatch, onSearch, onUpdate } from '@/views/i18n/i18n-setting/utils/hook';
|
||||
import { deleteIds, onAdd, onDelete, onDeleteBatch, onSearch, onUpdate } from '@/views/i18n/i18n-setting/utils/hooks';
|
||||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
|
|
|
@ -6,7 +6,7 @@ import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
|||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import PureTable from '@pureadmin/table';
|
||||
import { userI18nTypeStore } from '@/store/i18n/i18nType';
|
||||
import { onAdd, onDelete, onSearch, onUpdate } from '@/views/i18n/i18n-type-setting/utils/hook';
|
||||
import { onAdd, onDelete, onSearch, onUpdate } from '@/views/i18n/i18n-type-setting/utils/hooks';
|
||||
import Delete from '@iconify-icons/ep/delete';
|
||||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import TableIsDefaultTag from '@/components/TableBar/src/TableIsDefaultTag.vue';
|
||||
|
|
|
@ -6,7 +6,7 @@ import Lock from '@iconify-icons/ri/lock-fill';
|
|||
import { onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { useUserStore } from '@/store/system/user';
|
||||
import { message } from '@/utils/message';
|
||||
import { getTopMenu, initRouter } from '@/router/utils';
|
||||
import Motion from './utils/motion';
|
||||
|
|
|
@ -6,11 +6,11 @@ import Delete from '@iconify-icons/ep/delete';
|
|||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import Refresh from '@iconify-icons/ep/refresh';
|
||||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import { handleDelete, onAdd, onSearch, onUpdate, resetForm } from '@/views/system/menu/utils/hook';
|
||||
import { handleDelete, onAdd, onSearch, onUpdate, resetForm } from '@/views/system/menu/utils/hooks';
|
||||
import form from '@/views/system/menu/form.vue';
|
||||
import PureTable from '@pureadmin/table';
|
||||
import { columns } from '@/views/system/menu/utils/columns';
|
||||
import { userRouterStore } from '@/store/modules/router';
|
||||
import { userRouterStore } from '@/store/system/router';
|
||||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
|
||||
const formRef = ref();
|
||||
|
|
|
@ -2,7 +2,7 @@ import { h, reactive } from 'vue';
|
|||
import type { FormRules } from 'element-plus';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { isAllEmpty } from '@pureadmin/utils';
|
||||
import { getMenuType } from '@/views/system/menu/utils/hook';
|
||||
import { getMenuType } from '@/views/system/menu/utils/hooks';
|
||||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
|
||||
export const columns: TableColumnList = [
|
||||
|
|
|
@ -5,7 +5,7 @@ import { h, reactive, ref } from 'vue';
|
|||
import type { FormItemProps } from './types';
|
||||
|
||||
import { cloneDeep, deviceDetection } from '@pureadmin/utils';
|
||||
import { userRouterStore } from '@/store/modules/router';
|
||||
import { userRouterStore } from '@/store/system/router';
|
||||
|
||||
const routerStore = userRouterStore();
|
||||
export const form = reactive({
|
||||
|
@ -72,9 +72,9 @@ export function onAdd(parentId: any = 0) {
|
|||
},
|
||||
width: '45%',
|
||||
draggable: true,
|
||||
closeOnClickModal: false,
|
||||
fullscreen: deviceDetection(),
|
||||
fullscreenIcon: true,
|
||||
closeOnClickModal: false,
|
||||
contentRenderer: () => h(editForm, { ref: formRef }),
|
||||
beforeSure: (done, { options }) => {
|
||||
const menuFormRef = formRef.value.menuFormRef;
|
|
@ -5,13 +5,13 @@ import PureTableBar from '@/components/TableBar/src/bar';
|
|||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import PureTable from '@pureadmin/table';
|
||||
import { onAdd, onDelete, onSearch, onUpdate } from '@/views/system/menuIcon/utils/hook';
|
||||
import { onAdd, onDelete, onSearch, onUpdate } from '@/views/system/menuIcon/utils/hooks';
|
||||
import Delete from '@iconify-icons/ep/delete';
|
||||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import Refresh from '@iconify-icons/ep/refresh';
|
||||
import { selectUserinfo } from '@/components/Table/Userinfo/columns';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { useMenuIconStore } from '@/store/modules/menuIcon';
|
||||
import { useMenuIconStore } from '@/store/system/menuIcon';
|
||||
|
||||
const tableRef = ref();
|
||||
const formRef = ref();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { deviceDetection } from '@pureadmin/utils';
|
||||
import { addDialog } from '@/components/BaseDialog/index';
|
||||
import MenuIconDialog from '@/views/system/menuIcon/menu-icon-dialog.vue';
|
||||
import { useMenuIconStore } from '@/store/modules/menuIcon';
|
||||
import { useMenuIconStore } from '@/store/system/menuIcon';
|
||||
import { h, ref } from 'vue';
|
||||
import { messageBox } from '@/utils/message';
|
||||
import type { FormItemProps } from '@/views/system/menuIcon/utils/types';
|
|
@ -0,0 +1,92 @@
|
|||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { columns } from '@/views/system/role/utils/columns';
|
||||
import PureTableBar from '@/components/TableBar/src/bar';
|
||||
import AddFill from '@iconify-icons/ri/add-circle-line';
|
||||
import PureTable from '@pureadmin/table';
|
||||
import { onAdd, onDelete, onSearch, onUpdate } from '@/views/system/role/utils/hooks';
|
||||
import Delete from '@iconify-icons/ep/delete';
|
||||
import EditPen from '@iconify-icons/ep/edit-pen';
|
||||
import Refresh from '@iconify-icons/ep/refresh';
|
||||
import { selectUserinfo } from '@/components/Table/Userinfo/columns';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
import { useRoleStore } from '@/store/system/role.ts';
|
||||
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
||||
|
||||
const tableRef = ref();
|
||||
const formRef = ref();
|
||||
const roleStore = useRoleStore();
|
||||
|
||||
const resetForm = async formEl => {
|
||||
if (!formEl) return;
|
||||
formEl.resetFields();
|
||||
await onSearch();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onSearch();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="main">
|
||||
<el-form ref="formRef" :inline="true" :model="roleStore.form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto">
|
||||
<el-form-item :label="$t('role_roleCode')" prop="roleCode">
|
||||
<el-input v-model="roleStore.form.roleCode" :placeholder="`${$t('input')}${$t('role_roleCode')}`" class="!w-[180px]" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('role_description')" prop="description">
|
||||
<el-input v-model="roleStore.form.description" :placeholder="`${$t('input')}${$t('role_description')}`" class="!w-[180px]" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button :icon="useRenderIcon('ri:search-line')" :loading="roleStore.loading" type="primary" @click="onSearch"> {{ $t('search') }} </el-button>
|
||||
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)"> {{ $t('buttons.reset') }}</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<PureTableBar :columns="columns" title="角色" @fullscreen="tableRef.setAdaptive()" @refresh="onSearch">
|
||||
<template #buttons>
|
||||
<el-button :icon="useRenderIcon(AddFill)" type="primary" @click="onAdd"> 添加角色</el-button>
|
||||
</template>
|
||||
|
||||
<template v-slot="{ size, dynamicColumns }">
|
||||
<pure-table
|
||||
ref="tableRef"
|
||||
:adaptiveConfig="{ offsetBottom: 45 }"
|
||||
:columns="dynamicColumns"
|
||||
:data="roleStore.datalist"
|
||||
:header-cell-style="{ background: 'var(--el-fill-color-light)', color: 'var(--el-text-color-primary)' }"
|
||||
:loading="roleStore.loading"
|
||||
:size="size"
|
||||
adaptive
|
||||
align-whole="center"
|
||||
border
|
||||
highlight-current-row
|
||||
row-key="id"
|
||||
showOverflowTooltip
|
||||
table-layout="auto"
|
||||
>
|
||||
<template #createUser="{ row }">
|
||||
<el-button link type="primary" @click="selectUserinfo(row.createUser)">{{ $t('table.createUser') }} </el-button>
|
||||
</template>
|
||||
|
||||
<template #updateUser="{ row }">
|
||||
<el-button link type="primary" @click="selectUserinfo(row.updateUser)">{{ $t('table.updateUser') }} </el-button>
|
||||
</template>
|
||||
|
||||
<template #operation="{ row }">
|
||||
<el-button :icon="useRenderIcon(EditPen)" :size="size" class="reset-margin" link type="primary" @click="onUpdate(row)"> {{ $t('modify') }} </el-button>
|
||||
<el-button :icon="useRenderIcon(AddFill)" :size="size" class="reset-margin" link type="primary" @click="onAdd"> {{ $t('add_new') }} </el-button>
|
||||
<!-- TODO 待完成 -->
|
||||
<el-popconfirm :title="`是否确认删除 ${row.typeName}数据`" @confirm="onDelete(row)">
|
||||
<template #reference>
|
||||
<el-button :icon="useRenderIcon(Delete)" :size="size" class="reset-margin" link type="primary">
|
||||
{{ $t('delete') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</template>
|
||||
</pure-table>
|
||||
</template>
|
||||
</PureTableBar>
|
||||
</div>
|
||||
</template>
|
|
@ -0,0 +1,32 @@
|
|||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { FormInstance } from 'element-plus';
|
||||
import { rules } from '@/views/system/role/utils/columns';
|
||||
import { FormProps } from '@/views/system/role/utils/types';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
|
||||
const props = withDefaults(defineProps<FormProps>(), {
|
||||
formInline: () => ({
|
||||
// 角色代码
|
||||
roleCode: undefined,
|
||||
// 描述
|
||||
description: undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
const formRef = ref<FormInstance>();
|
||||
const form = ref(props.formInline);
|
||||
|
||||
defineExpose({ formRef });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="auto">
|
||||
<el-form-item :label="$t('role_roleCode')" prop="roleCode">
|
||||
<el-input v-model="form.roleCode" autocomplete="off" type="text" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('role_description')" prop="description">
|
||||
<el-input v-model="form.description" autocomplete="off" type="text" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
|
@ -0,0 +1,26 @@
|
|||
import { reactive } from 'vue';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
|
||||
// 表格列
|
||||
export const columns: TableColumnList = [
|
||||
{ type: 'index', index: (index: number) => index + 1 },
|
||||
// { type: 'selection', align: 'left' },
|
||||
{ label: $t('id'), prop: 'id' },
|
||||
// 角色代码
|
||||
{ label: $t('role_roleCode'), prop: 'roleCode' },
|
||||
// 描述
|
||||
{ label: $t('role_description'), prop: 'description' },
|
||||
{ label: $t('table.updateTime'), prop: 'updateTime', sortable: true },
|
||||
{ label: $t('table.createTime'), prop: 'createTime', sortable: true },
|
||||
{ label: $t('table.createUser'), prop: 'createUser', slot: 'createUser' },
|
||||
{ label: $t('table.updateUser'), prop: 'updateUser', slot: 'updateUser' },
|
||||
{ label: $t('table.operation'), fixed: 'right', width: 210, slot: 'operation' },
|
||||
];
|
||||
|
||||
// 添加规则
|
||||
export const rules = reactive({
|
||||
// 角色代码
|
||||
roleCode: [{ required: true, message: `${$t('input')}${$t('role_roleCode')}`, trigger: 'blur' }],
|
||||
// 描述
|
||||
description: [{ required: true, message: `${$t('input')}${$t('role_description')}`, trigger: 'blur' }],
|
||||
});
|
|
@ -0,0 +1,105 @@
|
|||
import { deviceDetection } from '@pureadmin/utils';
|
||||
import { addDialog } from '@/components/BaseDialog/index';
|
||||
import RoleDialog from '@/views/system/role/role-dialog.vue';
|
||||
import { useRoleStore } from '@/store/system/role';
|
||||
import { h, ref } from 'vue';
|
||||
import { messageBox } from '@/utils/message';
|
||||
import type { FormItemProps } from '@/views/system/role/utils/types';
|
||||
import { $t } from '@/plugins/i18n';
|
||||
|
||||
export const formRef = ref();
|
||||
const roleStore = useRoleStore();
|
||||
|
||||
/**
|
||||
* * 搜索初始化角色
|
||||
*/
|
||||
export async function onSearch() {
|
||||
roleStore.loading = true;
|
||||
await roleStore.getRoleList();
|
||||
roleStore.loading = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 添加角色
|
||||
*/
|
||||
export function onAdd() {
|
||||
addDialog({
|
||||
title: `${$t('add_new')}${$t('role')}`,
|
||||
width: '30%',
|
||||
props: {
|
||||
formInline: {
|
||||
roleCode: undefined,
|
||||
description: undefined,
|
||||
},
|
||||
},
|
||||
draggable: true,
|
||||
fullscreen: deviceDetection(),
|
||||
fullscreenIcon: true,
|
||||
closeOnClickModal: false,
|
||||
contentRenderer: () => h(RoleDialog, { ref: formRef }),
|
||||
beforeSure: (done, { options }) => {
|
||||
const form = options.props.formInline as FormItemProps;
|
||||
formRef.value.formRef.validate(async (valid: any) => {
|
||||
if (!valid) return;
|
||||
|
||||
const result = await roleStore.addRole(form);
|
||||
if (!result) return;
|
||||
done();
|
||||
await onSearch();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* * 更新角色
|
||||
* @param row
|
||||
*/
|
||||
export function onUpdate(row: any) {
|
||||
addDialog({
|
||||
title: `${$t('modify')}${$t('role')}`,
|
||||
width: '30%',
|
||||
props: {
|
||||
formInline: {
|
||||
roleCode: row.roleCode,
|
||||
description: row.description,
|
||||
},
|
||||
},
|
||||
draggable: true,
|
||||
fullscreen: deviceDetection(),
|
||||
fullscreenIcon: true,
|
||||
closeOnClickModal: false,
|
||||
contentRenderer: () => h(RoleDialog, { ref: formRef }),
|
||||
beforeSure: (done, { options }) => {
|
||||
const form = options.props.formInline as FormItemProps;
|
||||
formRef.value.formRef.validate(async (valid: any) => {
|
||||
if (!valid) return;
|
||||
|
||||
const result = await roleStore.updateRole({ ...form, id: row.id });
|
||||
if (!result) return;
|
||||
done();
|
||||
await onSearch();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* * 删除角色
|
||||
*/
|
||||
export const onDelete = async (row: any) => {
|
||||
const id = row.id;
|
||||
|
||||
// 是否确认删除
|
||||
const result = await messageBox({
|
||||
title: $t('confirm_delete'),
|
||||
showMessage: false,
|
||||
confirmMessage: undefined,
|
||||
cancelMessage: $t('cancel_delete'),
|
||||
});
|
||||
if (!result) return;
|
||||
|
||||
// 删除数据
|
||||
await roleStore.deleteRole([id]);
|
||||
await onSearch();
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
// 添加或者修改表单元素
|
||||
export interface FormItemProps {
|
||||
// 角色代码
|
||||
roleCode: string;
|
||||
// 描述
|
||||
description: string;
|
||||
}
|
||||
|
||||
// 添加或修改表单Props
|
||||
export interface FormProps {
|
||||
formInline: FormItemProps;
|
||||
}
|
Loading…
Reference in New Issue