index.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. export interface Rules {
  2. trigger: string
  3. enum: string
  4. len?: number
  5. max?: number
  6. message: string
  7. min?: number
  8. pattern: string
  9. required: boolean
  10. type: string
  11. }
  12. export interface WidgetForm {
  13. list: any[]
  14. config: {
  15. size: '' | 'default' | 'small' | 'large'
  16. hideRequiredAsterisk: boolean
  17. labelWidth: number
  18. labelPosition: 'top' | 'right' | 'left'
  19. }
  20. }
  21. const rules: Rules = {
  22. trigger: 'blur',
  23. enum: '',
  24. len: undefined,
  25. max: undefined,
  26. message: '',
  27. min: undefined,
  28. pattern: '',
  29. required: false,
  30. type: 'any',
  31. }
  32. export const getWidgetForm = (): WidgetForm => ({
  33. list: [],
  34. config: {
  35. size: 'default',
  36. hideRequiredAsterisk: false,
  37. labelWidth: 100,
  38. labelPosition: 'right',
  39. },
  40. })
  41. export const basicComponents = [
  42. {
  43. label: '单行文本',
  44. type: 'input' as const,
  45. options: {
  46. width: '100%',
  47. defaultValue: '',
  48. placeholder: '',
  49. maxlength: null,
  50. prefix: '',
  51. suffix: '',
  52. prepend: '',
  53. append: '',
  54. disabled: false,
  55. clearable: false,
  56. readonly: false,
  57. rules,
  58. },
  59. },
  60. {
  61. label: '密码框',
  62. type: 'password' as const,
  63. options: {
  64. width: '100%',
  65. defaultValue: '',
  66. placeholder: '',
  67. maxlength: null,
  68. prefix: '',
  69. suffix: '',
  70. prepend: '',
  71. append: '',
  72. showPassword: true,
  73. disabled: false,
  74. clearable: false,
  75. readonly: false,
  76. rules,
  77. },
  78. },
  79. {
  80. label: '多行文本',
  81. type: 'textarea' as const,
  82. options: {
  83. width: '100%',
  84. defaultValue: '',
  85. placeholder: '',
  86. maxlength: null,
  87. rows: 4,
  88. autosize: false,
  89. showWordLimit: false,
  90. disabled: false,
  91. clearable: false,
  92. readonly: false,
  93. rules,
  94. },
  95. },
  96. {
  97. label: '计数器',
  98. type: 'number' as const,
  99. options: {
  100. width: '',
  101. defaultValue: 0,
  102. min: 0,
  103. max: 100,
  104. step: 1,
  105. disabled: false,
  106. rules,
  107. },
  108. },
  109. {
  110. label: '单选框组',
  111. type: 'radio' as const,
  112. options: {
  113. defaultValue: '',
  114. width: '',
  115. inline: true,
  116. remote: false,
  117. showLabel: true,
  118. remoteFunc:
  119. 'https://raw.githubusercontent.com/fuchengwei/vue-form-create/master/mock/mock.json',
  120. options: [
  121. {
  122. value: 'Option 1',
  123. label: 'Option 1',
  124. },
  125. {
  126. value: 'Option 2',
  127. label: 'Option 2',
  128. },
  129. {
  130. value: 'Option 3',
  131. label: 'Option 3',
  132. },
  133. ],
  134. remoteOptions: [],
  135. props: {
  136. value: 'value',
  137. label: 'label',
  138. },
  139. disabled: false,
  140. rules,
  141. },
  142. },
  143. {
  144. label: '多选框组',
  145. type: 'checkbox' as const,
  146. options: {
  147. defaultValue: [],
  148. width: '',
  149. inline: true,
  150. remote: false,
  151. showLabel: true,
  152. remoteFunc:
  153. 'https://raw.githubusercontent.com/fuchengwei/vue-form-create/master/mock/mock.json',
  154. options: [
  155. {
  156. label: 'Option 1',
  157. value: 'Option 1',
  158. },
  159. {
  160. label: 'Option 2',
  161. value: 'Option 2',
  162. },
  163. {
  164. label: 'Option 3',
  165. value: 'Option 3',
  166. },
  167. ],
  168. remoteOptions: [],
  169. props: {
  170. value: 'value',
  171. label: 'label',
  172. },
  173. disabled: false,
  174. rules,
  175. },
  176. },
  177. {
  178. label: '时间选择器',
  179. type: 'time' as const,
  180. options: {
  181. defaultValue: '',
  182. width: '',
  183. placeholder: '请选择时间',
  184. format: 'HH:mm:ss',
  185. valueFormat: 'HH:mm:ss',
  186. readonly: false,
  187. editable: true,
  188. clearable: true,
  189. disabled: false,
  190. rules,
  191. },
  192. },
  193. {
  194. label: '日期选择器',
  195. type: 'date' as const,
  196. options: {
  197. defaultValue: '',
  198. width: '',
  199. placeholder: '请选择时间',
  200. format: 'YYYY-MM-DD',
  201. readonly: false,
  202. editable: true,
  203. clearable: true,
  204. disabled: false,
  205. rules,
  206. },
  207. },
  208. {
  209. label: '评分',
  210. type: 'rate' as const,
  211. options: {
  212. defaultValue: 0,
  213. max: 5,
  214. allowHalf: false,
  215. disabled: false,
  216. rules,
  217. },
  218. },
  219. {
  220. label: '下拉选择框',
  221. type: 'select' as const,
  222. options: {
  223. defaultValue: '',
  224. width: '200px',
  225. multiple: false,
  226. placeholder: '',
  227. remote: false,
  228. showLabel: true,
  229. filterable: false,
  230. clearable: false,
  231. disabled: false,
  232. props: {
  233. label: 'label',
  234. value: 'value',
  235. },
  236. options: [
  237. {
  238. label: 'Option 1',
  239. value: 'Option 1',
  240. },
  241. {
  242. label: 'Option 2',
  243. value: 'Option 2',
  244. },
  245. {
  246. label: 'Option 3',
  247. value: 'Option 3',
  248. },
  249. ],
  250. remoteOptions: [],
  251. remoteFunc:
  252. 'https://raw.githubusercontent.com/fuchengwei/vue-form-create/master/mock/mock.json',
  253. rules,
  254. },
  255. },
  256. {
  257. label: '开关',
  258. type: 'switch' as const,
  259. options: {
  260. defaultValue: false,
  261. disabled: false,
  262. activeText: '',
  263. inactiveText: '',
  264. rules,
  265. },
  266. },
  267. {
  268. label: '滑块',
  269. type: 'slider' as const,
  270. options: {
  271. defaultValue: 0,
  272. width: '',
  273. min: 0,
  274. max: 100,
  275. step: 1,
  276. disabled: false,
  277. range: false,
  278. rules,
  279. },
  280. },
  281. {
  282. label: '文字',
  283. type: 'text' as const,
  284. options: {
  285. defaultValue: 'This is a text',
  286. },
  287. },
  288. ]
  289. export const basicFields = (basicComponents).map(i => i.type)
  290. export const advanceComponents = [
  291. {
  292. label: '图片',
  293. type: 'img-upload' as const,
  294. options: {
  295. defaultValue: [],
  296. name: 'file',
  297. action: 'http://example.com/upload',
  298. method: 'post',
  299. listType: 'text',
  300. accept: 'image/*',
  301. limit: 1,
  302. multiple: false,
  303. disabled: true,
  304. rules,
  305. },
  306. },
  307. {
  308. label: '下载',
  309. type: 'download' as const,
  310. labelWidth: 'auto',
  311. options: {
  312. defaultValue: '',
  313. name: 'file',
  314. },
  315. },
  316. {
  317. label: '级联选择器',
  318. type: 'cascader' as const,
  319. options: {
  320. defaultValue: [],
  321. width: '200px',
  322. placeholder: '',
  323. disabled: false,
  324. clearable: false,
  325. filterable: false,
  326. remote: true,
  327. remoteOptions: [],
  328. props: {
  329. label: 'label',
  330. value: 'value',
  331. children: 'children',
  332. },
  333. remoteFunc:
  334. 'https://raw.githubusercontent.com/fuchengwei/vue-form-create/master/mock/mock.json',
  335. rules,
  336. },
  337. },
  338. ]
  339. export const advanceFields = (advanceComponents).map(i => i.type)
  340. export const layoutComponents = [
  341. {
  342. label: '栅格布局',
  343. type: 'grid',
  344. columns: [
  345. {
  346. span: 12,
  347. list: [],
  348. },
  349. {
  350. span: 12,
  351. list: [],
  352. },
  353. ],
  354. options: {
  355. gutter: 0,
  356. align: 'initial',
  357. },
  358. },
  359. {
  360. label: '数据表格',
  361. type: 'table',
  362. columns: [
  363. { label: '名称', prop: 'name' },
  364. { label: '创建时间', prop: 'createTime' },
  365. ],
  366. options: {
  367. defaultValue: [],
  368. disabled: false,
  369. size: '',
  370. align: 'center',
  371. },
  372. },
  373. {
  374. label: '分割线',
  375. type: 'divider',
  376. options: {},
  377. },
  378. ]
  379. export const layoutFields = (layoutComponents).map(i => i.type)