App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <script setup lang="ts">
  2. import { reactive, ref, onMounted } from 'vue'
  3. import { ElConfigProvider, ElIcon } from 'element-plus'
  4. import zhCn from 'element-plus/lib/locale/lang/zh-cn'
  5. // import en from 'element-plus/lib/locale/lang/en'
  6. import { VFrom } from '@/components/Form'
  7. import Calendar from '~icons/ep/calendar'
  8. import { useI18n } from '@/hooks/web/useI18n'
  9. const { t } = useI18n()
  10. const restaurants = ref<Recordable[]>([])
  11. const querySearch = (queryString: string, cb: Fn) => {
  12. const results = queryString
  13. ? restaurants.value.filter(createFilter(queryString))
  14. : restaurants.value
  15. // call callback function to return suggestions
  16. cb(results)
  17. }
  18. const createFilter = (queryString: string) => {
  19. return (restaurant: Recordable) => {
  20. return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
  21. }
  22. }
  23. const loadAll = () => {
  24. return [
  25. { value: 'vue', link: 'https://github.com/vuejs/vue' },
  26. { value: 'element', link: 'https://github.com/ElemeFE/element' },
  27. { value: 'cooking', link: 'https://github.com/ElemeFE/cooking' },
  28. { value: 'mint-ui', link: 'https://github.com/ElemeFE/mint-ui' },
  29. { value: 'vuex', link: 'https://github.com/vuejs/vuex' },
  30. { value: 'vue-router', link: 'https://github.com/vuejs/vue-router' },
  31. { value: 'babel', link: 'https://github.com/babel/babel' }
  32. ]
  33. }
  34. const handleSelect = (item: Recordable) => {
  35. console.log(item)
  36. }
  37. onMounted(() => {
  38. restaurants.value = loadAll()
  39. })
  40. const schema = reactive<VFormSchema[]>([
  41. {
  42. field: 'field1',
  43. label: t('formDemo.input'),
  44. component: 'Divider'
  45. },
  46. {
  47. field: 'field2',
  48. label: t('formDemo.default'),
  49. component: 'Input'
  50. },
  51. {
  52. field: 'field3',
  53. label: `${t('formDemo.icon')}1`,
  54. component: 'Input',
  55. componentProps: {
  56. suffixIcon: Calendar,
  57. prefixIcon: Calendar
  58. }
  59. },
  60. {
  61. field: 'field4',
  62. label: `${t('formDemo.icon')}2`,
  63. component: 'Input',
  64. componentProps: {
  65. slots: {
  66. suffix: true,
  67. prefix: true
  68. }
  69. }
  70. },
  71. {
  72. field: 'field5',
  73. label: t('formDemo.mixed'),
  74. component: 'Input',
  75. componentProps: {
  76. slots: {
  77. prepend: true,
  78. append: true
  79. }
  80. }
  81. },
  82. {
  83. field: 'field6',
  84. label: t('formDemo.textarea'),
  85. component: 'Input',
  86. componentProps: {
  87. type: 'textarea',
  88. rows: 1
  89. }
  90. },
  91. {
  92. field: 'field7',
  93. label: t('formDemo.autocomplete'),
  94. component: 'Divider'
  95. },
  96. {
  97. field: 'field8',
  98. label: t('formDemo.default'),
  99. component: 'Autocomplete',
  100. componentProps: {
  101. fetchSuggestions: querySearch,
  102. onSelect: handleSelect
  103. }
  104. },
  105. {
  106. field: 'field9',
  107. label: t('formDemo.slot'),
  108. component: 'Autocomplete',
  109. componentProps: {
  110. fetchSuggestions: querySearch,
  111. onSelect: handleSelect,
  112. slots: {
  113. default: true
  114. }
  115. }
  116. },
  117. {
  118. field: 'field10',
  119. component: 'Divider',
  120. componentProps: {
  121. text: t('formDemo.inputNumber')
  122. }
  123. },
  124. {
  125. field: 'field11',
  126. label: t('formDemo.default'),
  127. component: 'InputNumber'
  128. },
  129. {
  130. field: 'field11',
  131. label: t('formDemo.position'),
  132. component: 'InputNumber',
  133. componentProps: {
  134. controlsPosition: 'right'
  135. }
  136. },
  137. {
  138. field: 'field12',
  139. label: t('formDemo.select'),
  140. component: 'Divider'
  141. },
  142. {
  143. field: 'field13',
  144. label: t('formDemo.default'),
  145. component: 'Select',
  146. options: [
  147. {
  148. label: '选项1',
  149. value: '1'
  150. },
  151. {
  152. label: '选项2',
  153. value: '2'
  154. }
  155. ]
  156. },
  157. {
  158. field: 'field14',
  159. label: t('formDemo.slot'),
  160. component: 'Select',
  161. options: [
  162. {
  163. label: '选项1',
  164. value: '1'
  165. },
  166. {
  167. label: '选项2',
  168. value: '2'
  169. }
  170. ],
  171. optionsSlot: true
  172. },
  173. {
  174. field: 'field15',
  175. label: t('formDemo.group'),
  176. component: 'Select',
  177. options: [
  178. {
  179. label: '选项1',
  180. options: [
  181. {
  182. label: '选项1-1',
  183. value: '1-1'
  184. },
  185. {
  186. label: '选项1-2',
  187. value: '1-2'
  188. }
  189. ]
  190. },
  191. {
  192. label: '选项2',
  193. options: [
  194. {
  195. label: '选项2-1',
  196. value: '2-1'
  197. },
  198. {
  199. label: '选项2-2',
  200. value: '2-2'
  201. }
  202. ]
  203. }
  204. ]
  205. },
  206. {
  207. field: 'field16',
  208. label: `${t('formDemo.group')}${t('formDemo.slot')}`,
  209. component: 'Select',
  210. options: [
  211. {
  212. label: '选项1',
  213. options: [
  214. {
  215. label: '选项1-1',
  216. value: '1-1'
  217. },
  218. {
  219. label: '选项1-2',
  220. value: '1-2'
  221. }
  222. ]
  223. },
  224. {
  225. label: '选项2',
  226. options: [
  227. {
  228. label: '选项2-1',
  229. value: '2-1'
  230. },
  231. {
  232. label: '选项2-2',
  233. value: '2-2'
  234. }
  235. ]
  236. }
  237. ],
  238. optionsSlot: true
  239. }
  240. ])
  241. </script>
  242. <template>
  243. <ElConfigProvider :locale="zhCn">
  244. <VFrom :schema="schema">
  245. <template #field4-prefix>
  246. <ElIcon class="el-input__icon"><Calendar /></ElIcon>
  247. </template>
  248. <template #field4-suffix>
  249. <ElIcon class="el-input__icon"><Calendar /></ElIcon>
  250. </template>
  251. <template #field5-prepend> Http:// </template>
  252. <template #field5-append> .com </template>
  253. <template #field9-default="{ item }">
  254. <div class="value">{{ item.value }}</div>
  255. <span class="link">{{ item.link }}</span>
  256. </template>
  257. <template #field14-option="item">
  258. <span style="float: left">{{ item.label }}</span>
  259. <span style="float: right; font-size: 13px; color: var(--el-text-color-secondary)">{{
  260. item.value
  261. }}</span>
  262. </template>
  263. <template #field16-option="item">
  264. <span style="float: left">{{ item.label }}</span>
  265. <span style="float: right; font-size: 13px; color: var(--el-text-color-secondary)">{{
  266. item.value
  267. }}</span>
  268. </template>
  269. </VFrom>
  270. </ElConfigProvider>
  271. </template>