123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- import { BasicColumn } from '/@/components/Table';
- import { FormSchema } from '/@/components/Form/index';
- import { h } from 'vue';
- import moment from 'moment';
- import Input from './customComponents/Input.vue';
- import InputTextArea from './customComponents/InputTextArea.vue';
- import InputNumber from './customComponents/InputNumber.vue';
- import ArrayCom from './customComponents/ArrayCom.vue';
- import Select from './customComponents/Select.vue';
- import MultipleSelect from './customComponents/MultipleSelect.vue';
- import Checkbox from './customComponents/Checkbox.vue';
- import Radio from './customComponents/Radio.vue';
- import DatePicker from './customComponents/DatePicker.vue';
- import TimePicker from './customComponents/TimePicker.vue';
- import Switch from './customComponents/Switch.vue';
- import UploadImage from './customComponents/UploadImage.vue';
- import UploadFile from './customComponents/UploadFile.vue';
- import { configNameExist } from '/@/api/sys/general';
- import { getConfigGroup } from '/@/api/sys/general';
- export const columns: BasicColumn[] = [
- {
- title: '变量标题',
- align: 'left',
- dataIndex: 'title',
- width: 100,
- },
- {
- title: '变量值',
- align: 'left',
- dataIndex: 'value',
- width: 550,
- customRender: ({ record }) => {
- switch (record.type) {
- case 'string':
- const onchange = (val) => {
- record.value = val;
- console.log(`record`, record);
- };
- return h(Input, {
- value: record.value,
- tip: record.tip,
- errMsg: record.errMsg || '',
- rules: record.rule.split(',') || [],
- style: { width: '100%' },
- onChange: onchange,
- });
- case 'number':
- const onNumberChange = (val) => {
- record.value = val;
- };
- return h(InputNumber, {
- value: record.value,
- tip: record.tip,
- errMsg: record.errMsg || '',
- rules: record.rule.split(',') || [],
- style: { width: '100%' },
- onChange: onNumberChange,
- });
- case 'select':
- const onSelectChange = (val) => {
- record.value = val;
- };
- // const options: any[] = [];
- // record.content.map((item, i) => {
- // options.push({ label: item, value: i });
- // });
- return h(Select, {
- value: record.value,
- options: record.content,
- tip: record.tip,
- mode: 'SECRET_COMBOBOX_MODE_DO_NOT_USE',
- placeholder: '没有选中任何项',
- onChange: onSelectChange,
- });
- case 'selects':
- const onMultipleChange = (val) => {
- record.value = val;
- };
- return h(MultipleSelect, {
- value: record.value,
- options: record.content,
- tip: record.tip,
- placeholder: '没有选中任何项',
- onChange: onMultipleChange,
- });
- case 'date':
- const onDatePickerChange = (val) => {
- record.value = val;
- };
- if (record.value !== '') {
- record.value = moment(record.value).format('YYYY-MM-DD');
- }
- return h(DatePicker, {
- placeholder: '没有选择日期',
- value: record.value,
- tip: record.tip,
- onChange: onDatePickerChange,
- });
- case 'time':
- const onTimePickerChange = (val) => {
- console.log(`val`, val);
- record.value = val;
- };
- return h(TimePicker, {
- placeholder: '没有选择时间',
- value: record.value,
- tip: record.tip,
- onChange: onTimePickerChange,
- });
- case 'text':
- const onTextAreaChange = (val) => {
- record.value = val;
- };
- return h(InputTextArea, {
- value: record.value,
- tip: record.tip,
- errMsg: record.errMsg || '',
- rules: record.rules || [],
- style: { width: '100%' },
- onChange: onTextAreaChange,
- });
- case 'switch':
- const onSwitchChange = (val) => {
- record.value = val;
- };
- return h(Switch, {
- checked: record.value,
- tip: record.tip,
- onChange: onSwitchChange,
- });
- case 'checkbox':
- const onCheckboxChange = (val) => {
- record.value = val;
- };
- return h(Checkbox, {
- value: record.value,
- options: record.content,
- tip: record.tip,
- onChange: onCheckboxChange,
- });
- case 'radio':
- const onRadioChange = (val) => {
- record.value = val;
- };
- return h(Radio, {
- value: record.value,
- options: record.content,
- tip: record.tip,
- onChange: onRadioChange,
- });
- case 'array':
- const onArrayChange = (val) => {
- console.log(`父组件获取到的参数 =======》`, val);
- record.value = val;
- };
- return h(ArrayCom, {
- value: record.value,
- // options: record.content,
- // style: { width: '65%' },
- onChange: onArrayChange,
- });
- case 'image':
- const onImageChange = (val) => {
- console.log(`img获取到的参数 =======》`, val);
- record.value = val;
- };
- return h(UploadImage, {
- value: record.value,
- type: 'image',
- tip: record.tip,
- options: record.content,
- style: { width: '65%' },
- onChange: onImageChange,
- });
- case 'images':
- const onImagesChange = (val) => {
- console.log(`imgs获取到的参数 =======》`, val);
- record.value = val;
- };
- return h(UploadImage, {
- value: record.value,
- type: 'images',
- tip: record.tip,
- options: record.content,
- style: { width: '65%' },
- onChange: onImagesChange,
- });
- case 'file':
- const onFileChange = (val) => {
- console.log(`file获取到的参数 =======》`, val);
- record.value = val;
- };
- return h(UploadFile, {
- value: record.value,
- type: 'file',
- tip: record.tip,
- options: record.content,
- style: { width: '65%' },
- onChange: onFileChange,
- });
- case 'files':
- const onFilesChange = (val) => {
- console.log(`files获取到的参数 =======》`, val);
- record.value = val;
- };
- return h(UploadFile, {
- value: record.value,
- type: 'files',
- tip: record.tip,
- options: record.content,
- style: { width: '65%' },
- onChange: onFilesChange,
- });
- }
- },
- },
- {
- title: '变量名',
- align: 'left',
- dataIndex: 'name',
- width: 120,
- },
- ];
- export const schemas: FormSchema[] = [
- {
- field: 'type',
- component: 'Select',
- label: '类型',
- colProps: {
- span: 20,
- },
- defaultValue: 'string',
- componentProps: {
- options: [
- {
- label: '字符',
- value: 'string',
- },
- {
- label: '文本',
- value: 'text',
- },
- {
- label: '编辑器',
- value: 'editor',
- },
- {
- label: '数字',
- value: 'number',
- },
- {
- label: '日期',
- value: 'date',
- },
- {
- label: '时间',
- value: 'time',
- },
- {
- label: '列表',
- value: 'select',
- },
- {
- label: '列表多选',
- value: 'selects',
- },
- {
- label: '图片',
- value: 'image',
- },
- {
- label: '图片(多)',
- value: 'images',
- },
- {
- label: '文件',
- value: 'file',
- },
- {
- label: '文件(多)',
- value: 'files',
- },
- {
- label: '开关',
- value: 'switch',
- },
- {
- label: '复选',
- value: 'checkbox',
- },
- {
- label: '单选',
- value: 'radio',
- },
- {
- label: '数组',
- value: 'array',
- },
- {
- label: '自定义',
- value: 'custom',
- },
- ],
- },
- },
- {
- field: 'group',
- component: 'GroupApiSelect',
- label: '分组',
- colProps: {
- span: 20,
- },
- defaultValue: 'basic',
- componentProps: {
- api: getConfigGroup,
- },
- },
- {
- field: 'name',
- component: 'Input',
- label: '变量名',
- colProps: {
- span: 20,
- },
- rules: [
- {
- required: true,
- validator: async (_, value: any) => {
- let dealValue = '';
- if (value) {
- dealValue = value.replace(/\s*/g, '');
- }
- if (dealValue === '') {
- return Promise.reject('请输入变量名');
- }
- if (value.length < 3 || value.lenght > 30) {
- return Promise.reject('请填写3到30个字符');
- }
- const isExit = await configNameExist({ name: value });
- if (isExit.bool) {
- return Promise.reject('变量名已经存在');
- }
- },
- trigger: 'blur',
- },
- ],
- },
- {
- field: 'title',
- component: 'Input',
- label: '变量标题',
- colProps: {
- span: 20,
- },
- rules: [{ required: true, trigger: 'blur' }],
- },
- {
- field: 'value',
- component: 'Input',
- label: '变量值',
- defaultValue: '',
- colProps: {
- span: 20,
- },
- },
- {
- field: 'content',
- component: 'InputTextArea',
- label: '数据列表',
- colProps: {
- span: 20,
- },
- defaultValue: `label1|value1\nlabel2|value2`,
- componentProps: {
- placeholder: 'label1|value1\nlabel2|value2',
- },
- required: true,
- show: ({ values }) => {
- if (
- values.type === 'radio' ||
- values.type === 'checkbox' ||
- values.type === 'selects' ||
- values.type === 'select'
- ) {
- return true;
- }
- return false;
- },
- },
- {
- field: 'tip',
- component: 'Input',
- label: '提示信息',
- defaultValue: '',
- colProps: {
- span: 20,
- },
- },
- {
- field: 'rule',
- component: 'Select',
- label: '校验规则',
- colProps: {
- span: 20,
- },
- componentProps: {
- mode: 'multiple',
- options: [
- {
- label: '必选(required)',
- value: 'required',
- key: 'required',
- },
- {
- label: '数字(digits)',
- value: 'digits',
- key: 'digits',
- },
- {
- label: '字母(letters)',
- value: 'letters',
- key: 'letters',
- },
- {
- label: '日期(time)',
- value: 'time',
- key: 'time',
- },
- {
- label: '邮箱(email)',
- value: 'email',
- key: 'email',
- },
- {
- label: '网址(url)',
- value: 'url',
- key: 'url',
- },
- {
- label: 'QQ号(qq)',
- value: 'qq',
- key: 'qq',
- },
- {
- label: '身份证(IDcard)',
- value: 'IDcard',
- key: 'IDcard',
- },
- {
- label: '座机电话(tel)',
- value: 'tel',
- key: 'tel',
- },
- {
- label: '手机(mobile)',
- value: 'mobile',
- key: 'mobile',
- },
- {
- label: '邮编(zipcode)',
- value: 'zipcode',
- key: 'zipcode',
- },
- {
- label: '中文(chinese)',
- value: 'chinese',
- key: 'chinese',
- },
- {
- label: '用户名(username)',
- value: 'username',
- key: 'username',
- },
- {
- label: '密码(password)',
- value: 'password',
- key: 'password',
- },
- ],
- },
- },
- {
- field: 'extend',
- component: 'InputTextArea',
- label: '扩展属性',
- defaultValue: '',
- colProps: {
- span: 20,
- },
- },
- ];
|