index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <CollapseContainer
  3. class="sys-container"
  4. title="系统配置"
  5. :canExpan="false"
  6. helpMessage="可以在此增改系统的变量和分组,也可以自定义分组和变量"
  7. >
  8. <a-button type="default" class="mr-2" @click="onBasicConfig"> 基础配置 </a-button>
  9. <a-button type="default" class="mr-2" @click="onBasicConfig"> 邮件配置 </a-button>
  10. <a-button type="default" class="mr-2" @click="onBasicConfig"> 字典配置 </a-button>
  11. <a-button type="default" class="mr-2" @click="onBasicConfig"> 会员配置 </a-button>
  12. <a-button
  13. preIcon="bx:bx-plus-medical"
  14. @mouseenter="showTip"
  15. @mouseleave="hideTip"
  16. @click="addConfig"
  17. class="mr-2"
  18. />
  19. <span v-if="tipShow" class="tip">点击添加新的配置</span>
  20. <BasicTable ref="tableRef" :canResize="true" v-if="tableShow" @register="registerTable" />
  21. <BasicForm
  22. class="config-form"
  23. v-if="formShow"
  24. @register="registerForm"
  25. @submit="handleSubmit"
  26. />
  27. <div v-if="tableShow" class="actions">
  28. <a-button class="mr-2" type="default" @click="onBasicConfig">
  29. {{ t('common.resetText') }}
  30. </a-button>
  31. <a-button class="mr-2" type="primary" @click="onSubmit">
  32. {{ t('common.submitText') }}
  33. </a-button>
  34. </div>
  35. </CollapseContainer>
  36. </template>
  37. <script lang="ts">
  38. import { defineComponent, reactive, ref, toRefs, unref } from 'vue';
  39. import { CollapseContainer } from '/@/components/Container/index';
  40. import { BasicForm, useForm } from '/@/components/Form/index';
  41. import { schemas } from './data';
  42. import { useI18n } from '/@/hooks/web/useI18n';
  43. import { adapt } from '/@/utils/adapt';
  44. import { validateType } from './validTools';
  45. import {
  46. BasicTable,
  47. useTable,
  48. // TableAction,
  49. // BasicColumn,
  50. // ActionItem,
  51. // EditRecordRow,
  52. TableActionType,
  53. } from '/@/components/Table';
  54. import { columns } from './data';
  55. export default defineComponent({
  56. components: { CollapseContainer, BasicTable, BasicForm },
  57. setup() {
  58. const { t } = useI18n();
  59. const tableHeight = adapt().tableHeight;
  60. const state = reactive({
  61. tipShow: false,
  62. tableShow: true,
  63. formShow: false,
  64. });
  65. const tableRef = ref<Nullable<TableActionType>>(null);
  66. const [registerTable] = useTable({
  67. columns: columns,
  68. maxHeight: tableHeight,
  69. dataSource: [
  70. {
  71. title: 'helloWorld',
  72. name: 'helloworld',
  73. value: 'helloWorld',
  74. type: 'Input',
  75. tip: '我是helloworld字段的提示',
  76. rules: [],
  77. },
  78. {
  79. title: 'test',
  80. name: 'test',
  81. value: 'test',
  82. type: 'Input',
  83. tip: '我是test字段的提示',
  84. rules: ['require', 'url'],
  85. },
  86. {
  87. title: 'hello1',
  88. name: 'hello1',
  89. value: 'hello1',
  90. type: 'Select',
  91. tip: 'hello select',
  92. option: [{ value: 'hello1' }, { value: 'world' }, { value: 'java' }],
  93. },
  94. {
  95. title: 'hello1',
  96. name: 'hello1',
  97. value: ['hello1'],
  98. type: 'MultipleSelect',
  99. tip: 'MultipleSelect',
  100. option: [{ value: 'hello1' }, { value: 'world' }, { value: 'java' }],
  101. },
  102. {
  103. title: 'hello1',
  104. name: 'hello1',
  105. value: 'Orange',
  106. type: 'Radio',
  107. option: [
  108. { label: 'Apple', value: 'Apple' },
  109. { label: 'Pear', value: 'Pear' },
  110. { label: 'Orange', value: 'Orange' },
  111. ],
  112. },
  113. {
  114. title: 'hello1',
  115. name: 'hello1',
  116. value: ['Apple', 'Orange'],
  117. type: 'Checkbox',
  118. option: [
  119. { label: 'Apple', value: 'Apple' },
  120. { label: 'Pear', value: 'Pear' },
  121. { label: 'Orange', value: 'Orange' },
  122. ],
  123. },
  124. {
  125. title: 'hello2',
  126. name: 'hello2',
  127. value: '2021-10-25',
  128. type: 'DatePicker',
  129. tip: '日期选择',
  130. },
  131. {
  132. title: 'time',
  133. name: 'timename',
  134. value: '11:12:25',
  135. type: 'TimePicker',
  136. tip: '时间选择',
  137. },
  138. {
  139. title: 'hello3',
  140. name: 'hello3',
  141. value: 10,
  142. type: 'InputNumber',
  143. tip: '我是test字段的提示',
  144. rules: ['require', 'qq'],
  145. },
  146. {
  147. title: 'hello4',
  148. name: 'hello4',
  149. value: 'InputTextAreasdafasdf',
  150. type: 'InputTextArea',
  151. tip: '我是InputTextArea字段的提示123456789112',
  152. rules: ['require', 'email'],
  153. },
  154. {
  155. title: 'hello4',
  156. name: 'hello4',
  157. value: true,
  158. type: 'Switch',
  159. },
  160. {
  161. title: 'hello4',
  162. name: 'hello4',
  163. value: true,
  164. type: 'ArrayCom',
  165. },
  166. ],
  167. showIndexColumn: false,
  168. pagination: false,
  169. });
  170. const [
  171. registerForm,
  172. // { validateFields, clearValidate, getFieldsValue, resetFields, setFieldsValue },
  173. ] = useForm({
  174. labelWidth: 120,
  175. schemas,
  176. actionColOptions: {
  177. span: 24,
  178. },
  179. showActionButtonGroup: true,
  180. });
  181. function getTableAction() {
  182. // 获取组件
  183. const tableAction = unref(tableRef);
  184. if (!tableAction) {
  185. throw new Error('tableAction is null');
  186. }
  187. return tableAction;
  188. }
  189. function showTip() {
  190. state.tipShow = true;
  191. }
  192. function hideTip() {
  193. state.tipShow = false;
  194. }
  195. function onBasicConfig() {
  196. state.tableShow = true;
  197. state.formShow = false;
  198. }
  199. function addConfig() {
  200. state.tableShow = false;
  201. state.formShow = true;
  202. }
  203. function onSubmit() {
  204. console.log('==========onSubmit=========');
  205. const data = getTableAction().getDataSource();
  206. let flag = true;
  207. data.map((item) => {
  208. if (item.rules && item.rules.length) {
  209. console.log(`item`, item.rules);
  210. const res = validateType(item.rules, item.value);
  211. item.errMsg = res.errMsg;
  212. flag = res.isValid;
  213. }
  214. });
  215. if (flag) {
  216. console.log('=======全部校验通过========');
  217. }
  218. }
  219. function handleSubmit(e) {
  220. console.log('=======values =======');
  221. console.log(`e`, e);
  222. }
  223. return {
  224. t,
  225. tableRef,
  226. registerTable,
  227. registerForm,
  228. showTip,
  229. hideTip,
  230. onBasicConfig,
  231. addConfig,
  232. onSubmit,
  233. handleSubmit,
  234. ...toRefs(state),
  235. };
  236. },
  237. });
  238. </script>
  239. <style>
  240. .sys-container {
  241. position: relative;
  242. }
  243. .vben-collapse-container__body > .mr-2 {
  244. margin-top: 5px;
  245. font-weight: 550 !important;
  246. }
  247. .tip {
  248. position: absolute;
  249. top: 30px;
  250. padding: 3px 6px;
  251. color: #fff;
  252. background-color: black;
  253. border-radius: 3px;
  254. }
  255. .config-form {
  256. margin-top: 10px;
  257. }
  258. .ant-form-item-children {
  259. display: flex;
  260. justify-content: center;
  261. }
  262. .actions {
  263. display: flex;
  264. justify-content: center;
  265. }
  266. </style>