Home.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <button @click="toggleDark()">
  3. <i inline-block align-middle i="dark:carbon-moon carbon-sun" />
  4. <span class="ml-2">{{ isDark ? 'Dark' : 'Light' }}</span>
  5. </button>
  6. <fm-making-form ref="makingForm" clearable upload preview generate-code generate-json
  7. :custom-fields="customFields"
  8. :global-config="globalConfig"
  9. :field-config="fieldConfig"
  10. name="v3sampledev"
  11. :cache="true"
  12. :json-templates="jsonTemplates"
  13. :init-from-template="false"
  14. :field-models="fieldModels"
  15. style="height: 700px;"
  16. use-antd-form
  17. use-vant-form
  18. >
  19. <template #widgetconfig="{type, data, customProps}">
  20. <el-form-item v-if="type === 'button'" label="Loading">
  21. <el-switch v-model="customProps.loading"></el-switch>
  22. </el-form-item>
  23. <el-form-item v-if="type === 'custom' && data.el=== 'custom-width-height'" label="Tip">
  24. <el-input v-model="customProps.tip"></el-input>
  25. </el-form-item>
  26. </template>
  27. </fm-making-form>
  28. </template>
  29. <script>
  30. import { useDark, useToggle } from '@vueuse/core'
  31. import json0 from './json0.js'
  32. import json1 from './json1.js'
  33. import json2 from './json2.js'
  34. import json3 from './json3.js'
  35. import json4 from './json4.js'
  36. import json5 from './json5.js'
  37. import json6 from './json6.js'
  38. import json7 from './json7.js'
  39. import json8 from './json8.js'
  40. import json9 from './json9.js'
  41. import json10 from './json10.js'
  42. import json11 from './json11.js'
  43. import { theme } from 'ant-design-vue'
  44. import { provide, ref, nextTick } from 'vue'
  45. export default {
  46. setup () {
  47. const isDark = useDark()
  48. const themeAlgorithm = ref(theme.defaultAlgorithm)
  49. provide('themeAlgorithm', themeAlgorithm)
  50. provide('isDark', isDark)
  51. nextTick(() => {
  52. if (isDark.value) {
  53. themeAlgorithm.value = theme.darkAlgorithm
  54. } else {
  55. themeAlgorithm.value = theme.defaultAlgorithm
  56. }
  57. })
  58. const toggleDark = () => {
  59. useToggle(isDark)()
  60. if (isDark.value) {
  61. themeAlgorithm.value = theme.darkAlgorithm
  62. } else {
  63. themeAlgorithm.value = theme.defaultAlgorithm
  64. }
  65. }
  66. return {
  67. isDark,
  68. toggleDark,
  69. theme
  70. }
  71. },
  72. data() {
  73. return {
  74. customFields: [
  75. {
  76. name: '自定义组件',
  77. el: 'custom-width-height',
  78. icon: '<svg fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M13.5 16.875h3.375m0 0h3.375m-3.375 0V13.5m0 3.375v3.375M6 10.5h2.25a2.25 2.25 0 002.25-2.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v2.25A2.25 2.25 0 006 10.5zm0 9.75h2.25A2.25 2.25 0 0010.5 18v-2.25a2.25 2.25 0 00-2.25-2.25H6a2.25 2.25 0 00-2.25 2.25V18A2.25 2.25 0 006 20.25zm9.75-9.75H18a2.25 2.25 0 002.25-2.25V6A2.25 2.25 0 0018 3.75h-2.25A2.25 2.25 0 0013.5 6v2.25a2.25 2.25 0 002.25 2.25z"></path></svg>',
  79. options: {
  80. defaultValue: {},
  81. labelWidth: 0,
  82. isLabelWidth: false,
  83. hidden: false,
  84. disabled: false,
  85. dataBind: true,
  86. required: false,
  87. validator: '',
  88. extendProps: {},
  89. customProps: {}
  90. },
  91. events: {
  92. onChange: '',
  93. onTest: '',
  94. }
  95. },{
  96. name: '图表示例',
  97. el: 'custom-chart',
  98. options: {
  99. defaultValue: [
  100. { year: '1951 年', sales: 38 },
  101. { year: '1952 年', sales: 52 },
  102. { year: '1956 年', sales: 61 },
  103. { year: '1957 年', sales: 145 },
  104. { year: '1958 年', sales: 48 },
  105. { year: '1959 年', sales: 38 },
  106. { year: '1960 年', sales: 38 },
  107. { year: '1962 年', sales: 38 },
  108. ],
  109. customClass: '',
  110. labelWidth: 100,
  111. isLabelWidth: false,
  112. hidden: false,
  113. dataBind: true,
  114. required: false,
  115. validator: '',
  116. customProps: {}
  117. }
  118. },{
  119. name: 'VantField',
  120. el: 'custom-vant-field',
  121. options: {
  122. defaultValue: '',
  123. hideLabel: true,
  124. hidden: false,
  125. dataBind: true,
  126. required: false,
  127. validator: '',
  128. placeholder: '请输入文本',
  129. disabled: false,
  130. extendProps: {
  131. label: '文本',
  132. },
  133. }
  134. },{
  135. name: 'VantCalendar',
  136. el: 'custom-vant-calendar',
  137. options: {
  138. defaultValue: '',
  139. hideLabel: true,
  140. hidden: false,
  141. dataBind: true,
  142. disabled: false,
  143. required: false,
  144. validator: '',
  145. extendProps: {
  146. },
  147. }
  148. },{
  149. name: '分页数据列表',
  150. el: 'custom-pagination-table',
  151. options: {
  152. defaultValue: [],
  153. labelWidth: 0,
  154. isLabelWidth: false,
  155. hidden: false,
  156. dataBind: true,
  157. validator: '',
  158. extendProps: {
  159. columns: []
  160. }
  161. },
  162. events: {
  163. onChange: '',
  164. onLoad: ''
  165. }
  166. }
  167. ],
  168. globalConfig: {
  169. // styleSheets: '.a .el-form-item__label{color: red;}',
  170. ui: 'element',
  171. dataSource: [
  172. {
  173. key: 'upload',
  174. name: 'Get Upload Token',
  175. url: 'https://tools-server.making.link/api/uptoken',
  176. method: "GET",
  177. auto: true,
  178. responseFunc: 'return res.uptoken;',
  179. },
  180. {
  181. key: 'getoptions',
  182. name: 'Get Options',
  183. url: 'https://tools-server.making.link/api/new/options',
  184. method: 'GET',
  185. auto: true,
  186. responseFunc: 'return res.data;',
  187. }
  188. ]
  189. },
  190. fieldConfig: [
  191. {
  192. type: 'fileupload',
  193. options: {
  194. domain: 'https://tcdn.form.making.link/',
  195. action: 'https://tools-server.making.link/api/transfer',
  196. }
  197. },
  198. {
  199. type: 'imgupload',
  200. options: {
  201. domain: 'https://tcdn.form.making.link/',
  202. action: 'https://tools-server.making.link/api/transfer',
  203. }
  204. },
  205. {
  206. type: 'select',
  207. options: {
  208. options: [
  209. {value: '1111'},
  210. {value: '2222'},
  211. {value: '3333'}
  212. ]
  213. }
  214. }
  215. ],
  216. jsonTemplates: [
  217. {
  218. title: '空白表单',
  219. enTitle: 'Empty form',
  220. json: json0,
  221. url: '/images/json00.png'
  222. },
  223. {
  224. title: '基础表单',
  225. enTitle: 'Basic form',
  226. json: json1,
  227. url: '/images/json1.png'
  228. },
  229. {
  230. title: '快速注册表单',
  231. enTitle: 'Quick Sign-up Form',
  232. json: json2,
  233. url: '/images/json2.png'
  234. },
  235. {
  236. title: '表格应用 - 人员履历表',
  237. enTitle: 'Table form',
  238. json: json3,
  239. url: '/images/json3.png'
  240. },
  241. {
  242. title: '步骤表单',
  243. enTitle: 'Step form',
  244. json: json4,
  245. url: '/images/json4.png'
  246. },
  247. {
  248. title: '数据源应用 - 主子表省市区联动',
  249. enTitle: 'Data source application',
  250. json: json5,
  251. url: '/images/json5.png'
  252. },
  253. {
  254. title: '动态值 - 数据统计',
  255. enTitle: 'Event application',
  256. json: json6,
  257. url: '/images/json6.png'
  258. },
  259. {
  260. title: '响应式表单',
  261. enTitle: 'Reactive form',
  262. json: json7,
  263. url: '/images/json7.png'
  264. },
  265. {
  266. title: '复杂表格 - 动态增减表单项',
  267. enTitle: 'Complex forms',
  268. json: json8,
  269. url: '/images/json8.png'
  270. },
  271. {
  272. title: '可查询的分页数据列表',
  273. enTitle: 'Searchable paging data list',
  274. json: json9,
  275. url: '/images/json9.png'
  276. },
  277. {
  278. title: '中后台数据增删改查',
  279. enTitle: 'CRUD',
  280. json: json10,
  281. url: '/images/json10.png'
  282. },
  283. {
  284. title: '用户弹框选择',
  285. enTitle: 'The user select from the box',
  286. json: json11,
  287. url: '/images/json11.png'
  288. }
  289. ],
  290. fieldModels: [],
  291. }
  292. },
  293. mounted () {
  294. }
  295. }
  296. </script>