data.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. import { BasicColumn } from '/@/components/Table';
  2. import { FormSchema } from '/@/components/Form/index';
  3. import { h } from 'vue';
  4. import moment from 'moment';
  5. import Input from './customComponents/Input.vue';
  6. import InputTextArea from './customComponents/InputTextArea.vue';
  7. import InputNumber from './customComponents/InputNumber.vue';
  8. import ArrayCom from './customComponents/ArrayCom.vue';
  9. import Select from './customComponents/Select.vue';
  10. import MultipleSelect from './customComponents/MultipleSelect.vue';
  11. import Checkbox from './customComponents/Checkbox.vue';
  12. import Radio from './customComponents/Radio.vue';
  13. import DatePicker from './customComponents/DatePicker.vue';
  14. import TimePicker from './customComponents/TimePicker.vue';
  15. import Switch from './customComponents/Switch.vue';
  16. import UploadImage from './customComponents/UploadImage.vue';
  17. import UploadFile from './customComponents/UploadFile.vue';
  18. import { configNameExist } from '/@/api/sys/general';
  19. import { getConfigGroup } from '/@/api/sys/general';
  20. export const columns: BasicColumn[] = [
  21. {
  22. title: '变量标题',
  23. align: 'left',
  24. dataIndex: 'title',
  25. width: 100,
  26. },
  27. {
  28. title: '变量值',
  29. align: 'left',
  30. dataIndex: 'value',
  31. width: 550,
  32. customRender: ({ record }) => {
  33. switch (record.type) {
  34. case 'string':
  35. const onchange = (val) => {
  36. record.value = val;
  37. console.log(`record`, record);
  38. };
  39. return h(Input, {
  40. value: record.value,
  41. tip: record.tip,
  42. errMsg: record.errMsg || '',
  43. rules: record.rule.split(',') || [],
  44. style: { width: '100%' },
  45. onChange: onchange,
  46. });
  47. case 'number':
  48. const onNumberChange = (val) => {
  49. record.value = val;
  50. };
  51. return h(InputNumber, {
  52. value: record.value,
  53. tip: record.tip,
  54. errMsg: record.errMsg || '',
  55. rules: record.rule.split(',') || [],
  56. style: { width: '100%' },
  57. onChange: onNumberChange,
  58. });
  59. case 'select':
  60. const onSelectChange = (val) => {
  61. record.value = val;
  62. };
  63. // const options: any[] = [];
  64. // record.content.map((item, i) => {
  65. // options.push({ label: item, value: i });
  66. // });
  67. return h(Select, {
  68. value: record.value,
  69. options: record.content,
  70. tip: record.tip,
  71. mode: 'SECRET_COMBOBOX_MODE_DO_NOT_USE',
  72. placeholder: '没有选中任何项',
  73. onChange: onSelectChange,
  74. });
  75. case 'selects':
  76. const onMultipleChange = (val) => {
  77. record.value = val;
  78. };
  79. return h(MultipleSelect, {
  80. value: record.value,
  81. options: record.content,
  82. tip: record.tip,
  83. placeholder: '没有选中任何项',
  84. onChange: onMultipleChange,
  85. });
  86. case 'date':
  87. const onDatePickerChange = (val) => {
  88. record.value = val;
  89. };
  90. if (record.value !== '') {
  91. record.value = moment(record.value).format('YYYY-MM-DD');
  92. }
  93. return h(DatePicker, {
  94. placeholder: '没有选择日期',
  95. value: record.value,
  96. tip: record.tip,
  97. onChange: onDatePickerChange,
  98. });
  99. case 'time':
  100. const onTimePickerChange = (val) => {
  101. console.log(`val`, val);
  102. record.value = val;
  103. };
  104. return h(TimePicker, {
  105. placeholder: '没有选择时间',
  106. value: record.value,
  107. tip: record.tip,
  108. onChange: onTimePickerChange,
  109. });
  110. case 'text':
  111. const onTextAreaChange = (val) => {
  112. record.value = val;
  113. };
  114. return h(InputTextArea, {
  115. value: record.value,
  116. tip: record.tip,
  117. errMsg: record.errMsg || '',
  118. rules: record.rules || [],
  119. style: { width: '100%' },
  120. onChange: onTextAreaChange,
  121. });
  122. case 'switch':
  123. const onSwitchChange = (val) => {
  124. record.value = val;
  125. };
  126. return h(Switch, {
  127. checked: record.value,
  128. tip: record.tip,
  129. onChange: onSwitchChange,
  130. });
  131. case 'checkbox':
  132. const onCheckboxChange = (val) => {
  133. record.value = val;
  134. };
  135. return h(Checkbox, {
  136. value: record.value,
  137. options: record.content,
  138. tip: record.tip,
  139. onChange: onCheckboxChange,
  140. });
  141. case 'radio':
  142. const onRadioChange = (val) => {
  143. record.value = val;
  144. };
  145. return h(Radio, {
  146. value: record.value,
  147. options: record.content,
  148. tip: record.tip,
  149. onChange: onRadioChange,
  150. });
  151. case 'array':
  152. const onArrayChange = (val) => {
  153. console.log(`父组件获取到的参数 =======》`, val);
  154. record.value = val;
  155. };
  156. return h(ArrayCom, {
  157. value: record.value,
  158. // options: record.content,
  159. // style: { width: '65%' },
  160. onChange: onArrayChange,
  161. });
  162. case 'image':
  163. const onImageChange = (val) => {
  164. console.log(`img获取到的参数 =======》`, val);
  165. record.value = val;
  166. };
  167. return h(UploadImage, {
  168. value: record.value,
  169. type: 'image',
  170. tip: record.tip,
  171. options: record.content,
  172. style: { width: '65%' },
  173. onChange: onImageChange,
  174. });
  175. case 'images':
  176. const onImagesChange = (val) => {
  177. console.log(`imgs获取到的参数 =======》`, val);
  178. record.value = val;
  179. };
  180. return h(UploadImage, {
  181. value: record.value,
  182. type: 'images',
  183. tip: record.tip,
  184. options: record.content,
  185. style: { width: '65%' },
  186. onChange: onImagesChange,
  187. });
  188. case 'file':
  189. const onFileChange = (val) => {
  190. console.log(`file获取到的参数 =======》`, val);
  191. record.value = val;
  192. };
  193. return h(UploadFile, {
  194. value: record.value,
  195. type: 'file',
  196. tip: record.tip,
  197. options: record.content,
  198. style: { width: '65%' },
  199. onChange: onFileChange,
  200. });
  201. case 'files':
  202. const onFilesChange = (val) => {
  203. console.log(`files获取到的参数 =======》`, val);
  204. record.value = val;
  205. };
  206. return h(UploadFile, {
  207. value: record.value,
  208. type: 'files',
  209. tip: record.tip,
  210. options: record.content,
  211. style: { width: '65%' },
  212. onChange: onFilesChange,
  213. });
  214. }
  215. },
  216. },
  217. {
  218. title: '变量名',
  219. align: 'left',
  220. dataIndex: 'name',
  221. width: 120,
  222. },
  223. ];
  224. export const schemas: FormSchema[] = [
  225. {
  226. field: 'type',
  227. component: 'Select',
  228. label: '类型',
  229. colProps: {
  230. span: 20,
  231. },
  232. defaultValue: 'string',
  233. componentProps: {
  234. options: [
  235. {
  236. label: '字符',
  237. value: 'string',
  238. },
  239. {
  240. label: '文本',
  241. value: 'text',
  242. },
  243. {
  244. label: '编辑器',
  245. value: 'editor',
  246. },
  247. {
  248. label: '数字',
  249. value: 'number',
  250. },
  251. {
  252. label: '日期',
  253. value: 'date',
  254. },
  255. {
  256. label: '时间',
  257. value: 'time',
  258. },
  259. {
  260. label: '列表',
  261. value: 'select',
  262. },
  263. {
  264. label: '列表多选',
  265. value: 'selects',
  266. },
  267. {
  268. label: '图片',
  269. value: 'image',
  270. },
  271. {
  272. label: '图片(多)',
  273. value: 'images',
  274. },
  275. {
  276. label: '文件',
  277. value: 'file',
  278. },
  279. {
  280. label: '文件(多)',
  281. value: 'files',
  282. },
  283. {
  284. label: '开关',
  285. value: 'switch',
  286. },
  287. {
  288. label: '复选',
  289. value: 'checkbox',
  290. },
  291. {
  292. label: '单选',
  293. value: 'radio',
  294. },
  295. {
  296. label: '数组',
  297. value: 'array',
  298. },
  299. {
  300. label: '自定义',
  301. value: 'custom',
  302. },
  303. ],
  304. },
  305. },
  306. {
  307. field: 'group',
  308. component: 'GroupApiSelect',
  309. label: '分组',
  310. colProps: {
  311. span: 20,
  312. },
  313. defaultValue: 'basic',
  314. componentProps: {
  315. api: getConfigGroup,
  316. },
  317. },
  318. {
  319. field: 'name',
  320. component: 'Input',
  321. label: '变量名',
  322. colProps: {
  323. span: 20,
  324. },
  325. rules: [
  326. {
  327. required: true,
  328. validator: async (_, value: any) => {
  329. let dealValue = '';
  330. if (value) {
  331. dealValue = value.replace(/\s*/g, '');
  332. }
  333. if (dealValue === '') {
  334. return Promise.reject('请输入变量名');
  335. }
  336. if (value.length < 3 || value.lenght > 30) {
  337. return Promise.reject('请填写3到30个字符');
  338. }
  339. const isExit = await configNameExist({ name: value });
  340. if (isExit.bool) {
  341. return Promise.reject('变量名已经存在');
  342. }
  343. },
  344. trigger: 'blur',
  345. },
  346. ],
  347. },
  348. {
  349. field: 'title',
  350. component: 'Input',
  351. label: '变量标题',
  352. colProps: {
  353. span: 20,
  354. },
  355. rules: [{ required: true, trigger: 'blur' }],
  356. },
  357. {
  358. field: 'value',
  359. component: 'Input',
  360. label: '变量值',
  361. defaultValue: '',
  362. colProps: {
  363. span: 20,
  364. },
  365. },
  366. {
  367. field: 'content',
  368. component: 'InputTextArea',
  369. label: '数据列表',
  370. colProps: {
  371. span: 20,
  372. },
  373. defaultValue: `label1|value1\nlabel2|value2`,
  374. componentProps: {
  375. placeholder: 'label1|value1\nlabel2|value2',
  376. },
  377. required: true,
  378. show: ({ values }) => {
  379. if (
  380. values.type === 'radio' ||
  381. values.type === 'checkbox' ||
  382. values.type === 'selects' ||
  383. values.type === 'select'
  384. ) {
  385. return true;
  386. }
  387. return false;
  388. },
  389. },
  390. {
  391. field: 'tip',
  392. component: 'Input',
  393. label: '提示信息',
  394. defaultValue: '',
  395. colProps: {
  396. span: 20,
  397. },
  398. },
  399. {
  400. field: 'rule',
  401. component: 'Select',
  402. label: '校验规则',
  403. colProps: {
  404. span: 20,
  405. },
  406. componentProps: {
  407. mode: 'multiple',
  408. options: [
  409. {
  410. label: '必选(required)',
  411. value: 'required',
  412. key: 'required',
  413. },
  414. {
  415. label: '数字(digits)',
  416. value: 'digits',
  417. key: 'digits',
  418. },
  419. {
  420. label: '字母(letters)',
  421. value: 'letters',
  422. key: 'letters',
  423. },
  424. {
  425. label: '日期(time)',
  426. value: 'time',
  427. key: 'time',
  428. },
  429. {
  430. label: '邮箱(email)',
  431. value: 'email',
  432. key: 'email',
  433. },
  434. {
  435. label: '网址(url)',
  436. value: 'url',
  437. key: 'url',
  438. },
  439. {
  440. label: 'QQ号(qq)',
  441. value: 'qq',
  442. key: 'qq',
  443. },
  444. {
  445. label: '身份证(IDcard)',
  446. value: 'IDcard',
  447. key: 'IDcard',
  448. },
  449. {
  450. label: '座机电话(tel)',
  451. value: 'tel',
  452. key: 'tel',
  453. },
  454. {
  455. label: '手机(mobile)',
  456. value: 'mobile',
  457. key: 'mobile',
  458. },
  459. {
  460. label: '邮编(zipcode)',
  461. value: 'zipcode',
  462. key: 'zipcode',
  463. },
  464. {
  465. label: '中文(chinese)',
  466. value: 'chinese',
  467. key: 'chinese',
  468. },
  469. {
  470. label: '用户名(username)',
  471. value: 'username',
  472. key: 'username',
  473. },
  474. {
  475. label: '密码(password)',
  476. value: 'password',
  477. key: 'password',
  478. },
  479. ],
  480. },
  481. },
  482. {
  483. field: 'extend',
  484. component: 'InputTextArea',
  485. label: '扩展属性',
  486. defaultValue: '',
  487. colProps: {
  488. span: 20,
  489. },
  490. },
  491. ];