123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- import * as api from './api';
- import {
- dict,
- UserPageQuery,
- AddReq,
- DelReq,
- EditReq,
- compute,
- CreateCrudOptionsProps,
- CreateCrudOptionsRet,
- } from '@fast-crud/fast-crud';
- import { request } from '/@/utils/service';
- import { dictionary } from '/@/utils/dictionary';
- import { successMessage } from '/@/utils/message';
- import { inject, ref } from 'vue';
- import resetPassword from './resetPassword';
- export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProps): CreateCrudOptionsRet {
- const pageRequest = async (query: UserPageQuery) => {
- return await api.GetList(query);
- };
- const editRequest = async ({ form, row }: EditReq) => {
- form.id = row.id;
- return await api.UpdateObj(form);
- };
- const delRequest = async ({ row }: DelReq) => {
- return await api.DelObj(row.id);
- };
- const addRequest = async ({ form }: AddReq) => {
- return await api.AddObj(form);
- };
- const exportRequest = async (query: UserPageQuery) => {
- return await api.exportData(query);
- };
- //权限判定
- const hasPermissions: any = inject('$hasPermissions');
- const { dialogVisible, isShowDialog, resetId } = resetPassword();
- return {
- dialogVisible,
- resetId,
- crudOptions: {
- table: {
- remove: {
- confirmMessage: '是否删除该用户?',
- },
- border: false,
- },
- request: {
- pageRequest,
- addRequest,
- editRequest,
- delRequest,
- },
- actionbar: {
- buttons: {
- add: {
- show: hasPermissions('user:Create'),
- // show:true
- },
- export: {
- text: '导出', //按钮文字
- title: '导出', //鼠标停留显示的信息
- click() {
- return exportRequest(crudExpose!.getSearchFormData());
- },
- },
- },
- },
- rowHandle: {
- //固定右侧
- fixed: 'right',
- width: 200,
- buttons: {
- view: {
- show: false,
- },
- edit: {
- iconRight: 'Edit',
- type: 'text',
- show: hasPermissions('user:Update'),
- },
- remove: {
- iconRight: 'Delete',
- type: 'text',
- show: hasPermissions('user:Delete'),
- },
- custom: {
- text: '重设密码',
- type: 'text',
- show: hasPermissions('user:ResetPassword'),
- tooltip: {
- placement: 'top',
- content: '重设密码',
- },
- //@ts-ignore
- click: (ctx: any) => {
- const { row } = ctx;
- console.log('row', row);
- isShowDialog(row.id);
- },
- },
- },
- },
- columns: {
- _index: {
- title: '序号',
- form: { show: false },
- column: {
- type: 'index',
- align: 'center',
- width: '70px',
- columnSetDisabled: true, //禁止在列设置中选择
- },
- },
- username: {
- title: '账号',
- search: {
- show: true,
- },
- type: 'input',
- column: {
- minWidth: 100, //最小列宽
- },
- form: {
- rules: [
- // 表单校验规则
- {
- required: true,
- message: '账号必填项',
- },
- ],
- component: {
- placeholder: '请输入账号',
- },
- },
- },
- password: {
- title: '密码',
- type: 'input',
- column: {
- show: false,
- },
- editForm: {
- show: false,
- },
- form: {
- rules: [
- // 表单校验规则
- {
- required: true,
- message: '密码必填项',
- },
- ],
- component: {
- span: 12,
- showPassword: true,
- placeholder: '请输入密码',
- },
- // value: vm.systemConfig('base.default_password'),
- },
- /* valueResolve(row, key) {
- if (row.password) {
- row.password = vm.$md5(row.password)
- }
- } */
- },
- name: {
- title: '姓名',
- search: {
- show: true,
- },
- type: 'input',
- column: {
- minWidth: 100, //最小列宽
- },
- form: {
- rules: [
- // 表单校验规则
- {
- required: true,
- message: '姓名必填项',
- },
- ],
- component: {
- span: 12,
- placeholder: '请输入姓名',
- },
- },
- },
- gender: {
- title: '性别',
- type: 'dict-select',
- dict: dict({
- data: dictionary('gender'),
- }),
- column: {
- minWidth: 50, //最小列宽
- },
- form: {
- value: 1,
- component: {
- span: 12,
- },
- },
- component: { props: { color: 'auto' } }, // 自动染色
- },
- dept: {
- title: '部门',
- search: {
- disabled: true,
- },
- type: 'dict-tree',
- dict: dict({
- isTree: true,
- url: '/api/system/dept/all_dept/',
- value: 'id',
- label: 'name',
- getData: async ({ url }: { url: string }) => {
- return request({
- url: url,
- }).then((ret: any) => {
- return ret.data;
- });
- },
- }),
- column: {
- minWidth: 100, //最小列宽
- },
- form: {
- rules: [
- // 表单校验规则
- {
- required: true,
- message: '必填项',
- },
- ],
- component: {
- filterable: true,
- placeholder: '请选择',
- props: {
- props: {
- value: 'id',
- label: 'name',
- },
- },
- },
- },
- },
- role: {
- title: '角色',
- search: {
- disabled: true,
- },
- type: 'dict-select',
- dict: dict({
- url: '/api/system/role/',
- value: 'id',
- label: 'name',
- isTree: true,
- getData: async ({ url }: { url: string }) => {
- return request({
- url: url,
- params: {
- page: 1,
- limit: 10,
- },
- }).then((ret: any) => {
- return ret.data;
- });
- },
- }),
- column: {
- minWidth: 100, //最小列宽
- },
- form: {
- rules: [
- // 表单校验规则
- {
- required: true,
- message: '必填项',
- },
- ],
- component: {
- multiple: true,
- filterable: true,
- placeholder: '请选择角色',
- },
- },
- },
- mobile: {
- title: '手机号码',
- search: {
- show: true,
- },
- type: 'input',
- column: {
- minWidth: 120, //最小列宽
- },
- form: {
- rules: [
- {
- max: 20,
- message: '请输入正确的手机号码',
- trigger: 'blur',
- },
- {
- pattern: /^1[3-9]\d{9}$/,
- message: '请输入正确的手机号码',
- },
- ],
- component: {
- placeholder: '请输入手机号码',
- },
- },
- },
- email: {
- title: '邮箱',
- column: {
- width: 260,
- },
- form: {
- rules: [
- {
- type: 'email',
- message: '请输入正确的邮箱地址',
- trigger: ['blur', 'change'],
- },
- ],
- component: {
- placeholder: '请输入邮箱',
- },
- },
- },
- user_type: {
- title: '用户类型',
- search: {
- show: true,
- },
- type: 'dict-select',
- dict: dict({
- data: dictionary('user_type'),
- }),
- column: {
- minWidth: 100, //最小列宽
- },
- form: {
- show: false,
- value: 0,
- component: {
- span: 12,
- },
- },
- },
- is_active: {
- title: '锁定',
- search: {
- show: true,
- },
- type: 'dict-radio',
- column: {
- component: {
- name: 'fs-dict-switch',
- activeText: '',
- inactiveText: '',
- style: '--el-switch-on-color: var(--el-color-primary); --el-switch-off-color: #dcdfe6',
- onChange: compute((context) => {
- return () => {
- api.UpdateObj(context.row).then((res: APIResponseData) => {
- successMessage(res.msg as string);
- });
- };
- }),
- },
- },
- dict: dict({
- data: dictionary('button_status_bool'),
- }),
- },
- avatar: {
- title: '头像',
- type: 'avatar-cropper',
- column: {
- show: false,
- },
- form: {
- show: false,
- },
- },
- },
- },
- };
- };
|