index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div>
  3. <k-form-build :value="jsonData" ref="KFB" @submit="handleSubmit" />
  4. <button @click="hide">隐藏</button>
  5. <button @click="show">显示</button>
  6. <button @click="disable">禁用</button>
  7. <button @click="enable">启用</button>
  8. <button @click="getData">提交</button>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. name: "Demo",
  14. data() {
  15. return {
  16. jsonData: {
  17. list: [
  18. {
  19. type: "button",
  20. label: "按钮",
  21. options: {
  22. type: "primary",
  23. handle: "submit",
  24. dynamicFun: "",
  25. hidden: true,
  26. disabled: false
  27. },
  28. key: "button_1619948868332"
  29. },
  30. {
  31. type: "slider",
  32. label: "滑动输入条",
  33. icon: "icon-menu",
  34. options: {
  35. width: "100%",
  36. defaultValue: 0,
  37. disabled: false,
  38. hidden: false,
  39. min: 0,
  40. max: 100,
  41. step: 1,
  42. showInput: false
  43. },
  44. model: "slider_1619948887083",
  45. key: "slider_1619948887083",
  46. help: "",
  47. rules: [{ required: false, message: "必填项" }]
  48. },
  49. {
  50. type: "rate",
  51. label: "评分",
  52. icon: "icon-pingfen_moren",
  53. options: {
  54. defaultValue: 0,
  55. max: 5,
  56. disabled: false,
  57. hidden: false,
  58. allowHalf: false
  59. },
  60. model: "rate_1619948887483",
  61. key: "rate_1619948887483",
  62. help: "",
  63. rules: [{ required: false, message: "必填项" }]
  64. },
  65. {
  66. type: "uploadImg",
  67. label: "上传图片",
  68. icon: "icon-image",
  69. options: {
  70. defaultValue: "[]",
  71. multiple: false,
  72. hidden: false,
  73. disabled: false,
  74. width: "100%",
  75. data: "{}",
  76. limit: 3,
  77. placeholder: "上传",
  78. fileName: "image",
  79. headers: {},
  80. action: "http://cdn.kcz66.com/upload-img.txt",
  81. listType: "picture-card"
  82. },
  83. model: "uploadImg_1619948887819",
  84. key: "uploadImg_1619948887819",
  85. help: "",
  86. rules: [{ required: false, message: "必填项" }]
  87. },
  88. {
  89. type: "card",
  90. label: "卡片布局",
  91. list: [
  92. {
  93. type: "date",
  94. label: "日期选择框",
  95. icon: "icon-calendar",
  96. options: {
  97. width: "100%",
  98. defaultValue: "",
  99. rangeDefaultValue: [],
  100. range: false,
  101. showTime: false,
  102. disabled: false,
  103. hidden: false,
  104. clearable: false,
  105. placeholder: "请选择",
  106. rangePlaceholder: ["开始时间", "结束时间"],
  107. format: "YYYY-MM-DD"
  108. },
  109. model: "date_1619948975172",
  110. key: "date_1619948975172",
  111. help: "",
  112. rules: [{ required: false, message: "必填项" }]
  113. },
  114. {
  115. type: "input",
  116. label: "输入框",
  117. icon: "icon-write",
  118. options: {
  119. type: "text",
  120. width: "100%",
  121. defaultValue: "",
  122. placeholder: "请输入",
  123. clearable: false,
  124. maxLength: null,
  125. hidden: false,
  126. disabled: false
  127. },
  128. model: "input_1619948973892",
  129. key: "input_1619948973892",
  130. help: "",
  131. prefix: "",
  132. suffix: "",
  133. rules: [{ required: false, message: "必填项" }]
  134. },
  135. {
  136. type: "textarea",
  137. label: "文本框",
  138. icon: "icon-edit",
  139. options: {
  140. width: "100%",
  141. minRows: 4,
  142. maxRows: 6,
  143. maxLength: null,
  144. defaultValue: "",
  145. clearable: false,
  146. hidden: false,
  147. disabled: false,
  148. placeholder: "请输入"
  149. },
  150. model: "textarea_1619948974269",
  151. key: "textarea_1619948974269",
  152. help: "",
  153. rules: [{ required: false, message: "必填项" }]
  154. }
  155. ],
  156. key: "card_1619948983395"
  157. },
  158. {
  159. type: "table",
  160. label: "表格布局",
  161. trs: [
  162. {
  163. tds: [
  164. {
  165. colspan: 1,
  166. rowspan: 1,
  167. list: [
  168. {
  169. type: "slider",
  170. label: "滑动输入条",
  171. icon: "icon-menu",
  172. options: {
  173. width: "100%",
  174. defaultValue: 0,
  175. disabled: false,
  176. hidden: false,
  177. min: 0,
  178. max: 100,
  179. step: 1,
  180. showInput: false
  181. },
  182. model: "slider_1619948976300",
  183. key: "slider_1619948976300",
  184. help: "",
  185. rules: [{ required: false, message: "必填项" }]
  186. }
  187. ]
  188. },
  189. {
  190. colspan: 1,
  191. rowspan: 1,
  192. list: [
  193. {
  194. type: "uploadImg",
  195. label: "上传图片",
  196. icon: "icon-image",
  197. options: {
  198. defaultValue: "[]",
  199. multiple: false,
  200. hidden: false,
  201. disabled: false,
  202. width: "100%",
  203. data: "{}",
  204. limit: 3,
  205. placeholder: "上传",
  206. fileName: "image",
  207. headers: {},
  208. action: "http://cdn.kcz66.com/upload-img.txt",
  209. listType: "picture-card"
  210. },
  211. model: "uploadImg_1619948977239",
  212. key: "uploadImg_1619948977239",
  213. help: "",
  214. rules: [{ required: false, message: "必填项" }]
  215. },
  216. {
  217. type: "time",
  218. label: "时间选择框",
  219. icon: "icon-time",
  220. options: {
  221. width: "100%",
  222. defaultValue: "",
  223. disabled: false,
  224. hidden: false,
  225. clearable: false,
  226. placeholder: "请选择",
  227. format: "HH:mm:ss"
  228. },
  229. model: "time_1619948975820",
  230. key: "time_1619948975820",
  231. help: "",
  232. rules: [{ required: false, message: "必填项" }]
  233. }
  234. ]
  235. }
  236. ]
  237. },
  238. {
  239. tds: [
  240. {
  241. colspan: 1,
  242. rowspan: 1,
  243. list: [
  244. {
  245. type: "radio",
  246. label: "单选框",
  247. icon: "icon-danxuan-cuxiantiao",
  248. options: {
  249. disabled: false,
  250. hidden: false,
  251. defaultValue: "",
  252. dynamicKey: "",
  253. dynamic: false,
  254. options: [
  255. { value: "1", label: "选项1" },
  256. { value: "2", label: "选项2" },
  257. { value: "3", label: "选项3" }
  258. ]
  259. },
  260. model: "radio_1619948974588",
  261. key: "radio_1619948974588",
  262. help: "",
  263. rules: [{ required: false, message: "必填项" }]
  264. }
  265. ]
  266. },
  267. {
  268. colspan: 1,
  269. rowspan: 1,
  270. list: [
  271. {
  272. type: "date",
  273. label: "日期选择框",
  274. icon: "icon-calendar",
  275. options: {
  276. width: "100%",
  277. defaultValue: "",
  278. rangeDefaultValue: [],
  279. range: false,
  280. showTime: false,
  281. disabled: false,
  282. hidden: false,
  283. clearable: false,
  284. placeholder: "请选择",
  285. rangePlaceholder: ["开始时间", "结束时间"],
  286. format: "YYYY-MM-DD"
  287. },
  288. model: "date_1619948975548",
  289. key: "date_1619948975548",
  290. help: "",
  291. rules: [{ required: false, message: "必填项" }]
  292. }
  293. ]
  294. }
  295. ]
  296. }
  297. ],
  298. options: {
  299. width: "100%",
  300. bordered: true,
  301. bright: false,
  302. small: true,
  303. customStyle: ""
  304. },
  305. key: "table_1619948992003"
  306. },
  307. {
  308. type: "uploadFile",
  309. label: "上传文件",
  310. icon: "icon-upload",
  311. options: {
  312. defaultValue: "[]",
  313. multiple: false,
  314. disabled: false,
  315. hidden: false,
  316. drag: false,
  317. downloadWay: "a",
  318. dynamicFun: "",
  319. width: "100%",
  320. limit: 3,
  321. data: "{}",
  322. fileName: "file",
  323. headers: {},
  324. action: "http://cdn.kcz66.com/uploadFile.txt",
  325. placeholder: "上传"
  326. },
  327. model: "uploadFile_1619948976948",
  328. key: "uploadFile_1619948976948",
  329. help: "",
  330. rules: [{ required: false, message: "必填项" }]
  331. },
  332. {
  333. type: "cascader",
  334. label: "级联选择器",
  335. icon: "icon-guanlian",
  336. options: {
  337. disabled: false,
  338. hidden: false,
  339. showSearch: false,
  340. placeholder: "请选择",
  341. clearable: false,
  342. dynamicKey: "",
  343. dynamic: true,
  344. options: [
  345. {
  346. value: "1",
  347. label: "选项1",
  348. children: [{ value: "11", label: "选项11" }]
  349. },
  350. {
  351. value: "2",
  352. label: "选项2",
  353. children: [{ value: "22", label: "选项22" }]
  354. }
  355. ]
  356. },
  357. model: "cascader_1619948977724",
  358. key: "cascader_1619948977724",
  359. help: "",
  360. rules: [{ required: false, message: "必填项" }]
  361. },
  362. {
  363. type: "treeSelect",
  364. label: "树选择器",
  365. icon: "icon-tree",
  366. options: {
  367. disabled: false,
  368. multiple: false,
  369. hidden: false,
  370. clearable: false,
  371. showSearch: false,
  372. treeCheckable: false,
  373. placeholder: "请选择",
  374. dynamicKey: "",
  375. dynamic: true,
  376. options: [
  377. {
  378. value: "1",
  379. label: "选项1",
  380. children: [{ value: "11", label: "选项11" }]
  381. },
  382. {
  383. value: "2",
  384. label: "选项2",
  385. children: [{ value: "22", label: "选项22" }]
  386. }
  387. ]
  388. },
  389. model: "treeSelect_1619948978156",
  390. key: "treeSelect_1619948978156",
  391. help: "",
  392. prefix: "",
  393. suffix: "",
  394. rules: [{ required: false, message: "必填项" }]
  395. }
  396. ],
  397. config: {
  398. layout: "horizontal",
  399. labelCol: { xs: 4, sm: 4, md: 4, lg: 4, xl: 4, xxl: 4 },
  400. wrapperCol: { xs: 18, sm: 18, md: 18, lg: 18, xl: 18, xxl: 18 },
  401. hideRequiredMark: false,
  402. customStyle: ""
  403. }
  404. }
  405. };
  406. },
  407. methods: {
  408. handleSubmit(p) {
  409. // 通过表单提交按钮触发,获取promise对象
  410. p()
  411. .then(res => {
  412. // 获取数据成功
  413. alert(JSON.stringify(res));
  414. })
  415. .catch(err => {
  416. console.log(err, "校验失败");
  417. });
  418. },
  419. show() {
  420. this.$refs.KFB.show(["date_1619948975172"]);
  421. },
  422. hide() {
  423. this.$refs.KFB.hide(["date_1619948975172"]);
  424. },
  425. disable() {
  426. this.$refs.KFB.disable(["date_1619948975172"]);
  427. },
  428. enable() {
  429. this.$refs.KFB.enable(["date_1619948975172"]);
  430. },
  431. getData() {
  432. // 通过函数获取数据
  433. this.$refs.KFB.getData()
  434. .then(res => {
  435. // 获取数据成功
  436. alert(JSON.stringify(res));
  437. })
  438. .catch(err => {
  439. console.log(err, "校验失败");
  440. });
  441. }
  442. }
  443. };
  444. </script>