Basic.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <script lang="ts" setup>
  2. import type { BasicForm } from '@/types/form'
  3. import { ElInput } from 'element-plus'
  4. const formData = reactive<any>({})
  5. const formConfig = reactive<BasicForm>({
  6. span: 24,
  7. props: {
  8. labelPosition: 'right'
  9. },
  10. formItems: [
  11. {
  12. label: '用户名',
  13. value: '',
  14. name: 'name',
  15. type: 'input',
  16. rules: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
  17. },
  18. {
  19. label: '密码',
  20. value: '',
  21. name: 'password',
  22. type: 'custom',
  23. notFormItem: true,
  24. slots: [
  25. {
  26. name: 'default',
  27. alias: 'password'
  28. }
  29. ],
  30. rules: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  31. },
  32. {
  33. label: '区域',
  34. value: '',
  35. name: 'area',
  36. type: 'area'
  37. },
  38. {
  39. label: '手机号',
  40. value: '',
  41. name: 'phone',
  42. type: 'input',
  43. props: {
  44. maxlength: 11
  45. }
  46. },
  47. {
  48. label: '开关',
  49. value: true,
  50. name: 'ss',
  51. type: 'switch',
  52. props: {}
  53. },
  54. {
  55. label: '字典',
  56. value: '',
  57. name: 'field1',
  58. type: 'dict',
  59. props: {
  60. type: 'task_from',
  61. clearable: true,
  62. multiple: true
  63. }
  64. },
  65. {
  66. label: '字段名',
  67. value: '',
  68. name: 'field2',
  69. type: 'input',
  70. slots: [
  71. {
  72. name: 'prepend',
  73. alias: 'prepend1'
  74. },
  75. {
  76. name: 'append',
  77. alias: 'append1'
  78. }
  79. ]
  80. },
  81. {
  82. label: '字段名',
  83. value: '',
  84. name: 'field3',
  85. type: 'cascader',
  86. props: {
  87. options: [
  88. {
  89. value: 'guide',
  90. label: 'Guide',
  91. children: [
  92. {
  93. value: 'disciplines',
  94. label: 'Disciplines',
  95. children: [
  96. {
  97. value: 'consistency',
  98. label: 'Consistency'
  99. },
  100. {
  101. value: 'feedback',
  102. label: 'Feedback'
  103. },
  104. {
  105. value: 'efficiency',
  106. label: 'Efficiency'
  107. },
  108. {
  109. value: 'controllability',
  110. label: 'Controllability'
  111. }
  112. ]
  113. },
  114. {
  115. value: 'navigation',
  116. label: 'Navigation',
  117. children: [
  118. {
  119. value: 'side nav',
  120. label: 'Side Navigation'
  121. },
  122. {
  123. value: 'top nav',
  124. label: 'Top Navigation'
  125. }
  126. ]
  127. }
  128. ]
  129. },
  130. {
  131. value: 'resource',
  132. label: 'Resource',
  133. children: [
  134. {
  135. value: 'axure',
  136. label: 'Axure Components'
  137. },
  138. {
  139. value: 'sketch',
  140. label: 'Sketch Templates'
  141. },
  142. {
  143. value: 'docs',
  144. label: 'Design Documentation'
  145. }
  146. ]
  147. }
  148. ]
  149. },
  150. slots: [
  151. {
  152. name: 'default',
  153. alias: 'cDefault'
  154. }
  155. ],
  156. events: {
  157. change(item: any) {
  158. formData.name = 'c'
  159. formConfig.formItems[1].hidden = true
  160. }
  161. }
  162. },
  163. {
  164. label: '树选择',
  165. value: '',
  166. name: 'tree',
  167. type: 'tree-select',
  168. props: {
  169. data: [
  170. {
  171. value: '1',
  172. label: 'Level one 1',
  173. children: [
  174. {
  175. value: '1-1',
  176. label: 'Level two 1-1',
  177. children: [
  178. {
  179. value: '1-1-1',
  180. label: 'Level three 1-1-1'
  181. }
  182. ]
  183. }
  184. ]
  185. },
  186. {
  187. value: '2',
  188. label: 'Level one 2',
  189. children: [
  190. {
  191. value: '2-1',
  192. label: 'Level two 2-1',
  193. children: [
  194. {
  195. value: '2-1-1',
  196. label: 'Level three 2-1-1'
  197. }
  198. ]
  199. },
  200. {
  201. value: '2-2',
  202. label: 'Level two 2-2',
  203. children: [
  204. {
  205. value: '2-2-1',
  206. label: 'Level three 2-2-1'
  207. }
  208. ]
  209. }
  210. ]
  211. }
  212. ]
  213. }
  214. },
  215. {
  216. label: '图片',
  217. value: '',
  218. name: 'image',
  219. type: 'image-upload'
  220. },
  221. {
  222. label: '文件',
  223. value: [],
  224. name: 'file',
  225. type: 'upload',
  226. props: {
  227. multiple: true,
  228. 'on-success': (res: any) => {
  229. console.log(res)
  230. }
  231. },
  232. slots: [
  233. {
  234. name: 'default',
  235. alias: 'file'
  236. }
  237. ]
  238. },
  239. {
  240. label: '自定义',
  241. value: '',
  242. name: 'custom',
  243. type: 'custom',
  244. notFormItem: true,
  245. slots: [
  246. {
  247. name: 'default',
  248. alias: 'customDefault'
  249. }
  250. ]
  251. }
  252. ]
  253. })
  254. const create = (data: any) => {
  255. console.log(data)
  256. }
  257. const update = (data: any) => {
  258. console.log(data)
  259. }
  260. const proFormRef = ref<any>()
  261. const handleSave = () => {
  262. proFormRef.value.submit()
  263. }
  264. const inputValue = ref('')
  265. const dynamicTags = ref(['Tag 1', 'Tag 2', 'Tag 3'])
  266. const inputVisible = ref(false)
  267. const InputRef = ref<InstanceType<typeof ElInput>>()
  268. const handleClose = (tag: string) => {
  269. dynamicTags.value.splice(dynamicTags.value.indexOf(tag), 1)
  270. }
  271. const showInput = () => {
  272. inputVisible.value = true
  273. nextTick(() => {
  274. InputRef.value!.input!.focus()
  275. })
  276. }
  277. const handleInputConfirm = () => {
  278. if (inputValue.value) {
  279. dynamicTags.value.push(inputValue.value)
  280. }
  281. inputVisible.value = false
  282. inputValue.value = ''
  283. }
  284. </script>
  285. <template>
  286. <div class="h-full bg-white p-16px pt-50px flex justify-center overflow-auto">
  287. <div class="w-500px">
  288. <pro-form :formConfig="formConfig" :formData="formData" :create="create" :update="update" ref="proFormRef">
  289. <template #prepend> testt </template>
  290. <template #prepend1> test1 </template>
  291. <template #append> testt </template>
  292. <template #append1> test1 </template>
  293. <template #cDefault="{ node, data }">
  294. <span>{{ data.label }}</span>
  295. <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
  296. </template>
  297. <template #file>
  298. <el-button type="primary">上传</el-button>
  299. </template>
  300. <template #password>
  301. <el-input type="password" name="password" v-model="formData.password"></el-input>
  302. <el-text type="info">密码需包含大写字母、小写字母、数字</el-text>
  303. </template>
  304. <template #customDefault>
  305. <el-space wrap>
  306. <el-tag
  307. v-for="tag in dynamicTags"
  308. :key="tag"
  309. size="small"
  310. closable
  311. :disable-transitions="false"
  312. @close="handleClose(tag)"
  313. >
  314. {{ tag }}
  315. </el-tag>
  316. <el-input
  317. v-if="inputVisible"
  318. ref="InputRef"
  319. v-model="inputValue"
  320. class="ml-1 w-20"
  321. size="small"
  322. @keyup.enter="handleInputConfirm"
  323. @blur="handleInputConfirm"
  324. />
  325. <el-button v-else class="button-new-tag ml-1" size="small" @click="showInput"> + New Tag </el-button>
  326. </el-space>
  327. </template>
  328. </pro-form>
  329. <div class="text-center">
  330. <el-button type="primary" @click="handleSave">保存</el-button>
  331. </div>
  332. </div>
  333. </div>
  334. </template>
  335. <style lang="scss" scoped></style>