WidgetFormItem.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <script lang="ts" setup>
  2. import Draggable from 'vuedraggable'
  3. import { cloneWidget } from '@/components/ComponentGroup.vue'
  4. const { element, index, list, ...props } = defineProps<{
  5. list: any
  6. element: any
  7. index: number
  8. selectWidget: any
  9. }>()
  10. defineEmits(['itemClick', 'delete', 'update:selectWidget'])
  11. let selectWidget = $(useVModel(props, 'selectWidget'))
  12. const handleCopyClick = () => {
  13. list.splice(index + 1, 0, cloneWidget(list[index]))
  14. selectWidget = list[index + 1]
  15. }
  16. const handleDeleteClick = () => {
  17. list.splice(index, 1)
  18. selectWidget = list[list.length === index ? (index - 1) : index]
  19. }
  20. </script>
  21. <template>
  22. <div
  23. class="widget-view"
  24. :class="{ active: selectWidget?.key === element.key ,col:element.type === 'grid'}"
  25. :style="element.type === 'grid'?`gap: ${element.options.gutter}px; align-items: ${element.options.align};`:''"
  26. @click.stop="selectWidget=element"
  27. >
  28. <template v-if="element.type === 'grid'">
  29. <Draggable
  30. v-for="(col, key) of element.columns"
  31. :key="key"
  32. class="bg-white min-h-12 border border-dashed border-gray-300"
  33. :style="`grid-column: span ${col.span}`"
  34. item-key="key"
  35. handle="[cursor-move]"
  36. :animation="200"
  37. group="form-design"
  38. :no-transition-on-drag="true"
  39. :list="col.list"
  40. @add="selectWidget=col.list[$event.newIndex]"
  41. >
  42. <template #item="{ element: colElement, index: colIndex }">
  43. <WidgetFormItem
  44. v-model:selectWidget="selectWidget"
  45. :element="colElement"
  46. :list="col.list"
  47. :index="colIndex"
  48. />
  49. </template>
  50. </Draggable>
  51. </template>
  52. <el-table
  53. v-else-if="element.type === 'table'"
  54. class="w-0 flex-1"
  55. border
  56. :data="element.options.defaultValue"
  57. >
  58. <el-table-column
  59. v-for="i in element.columns"
  60. :key="i.prop"
  61. :header-align="element.options.align"
  62. :align="element.options.align"
  63. v-bind="i"
  64. />
  65. </el-table>
  66. <el-divider v-else-if="element.type === 'divider'" class="pb-0" :data="element.options.defaultValue" content-position="left">
  67. {{ element.label }}
  68. </el-divider>
  69. <el-form-item
  70. v-else-if="element"
  71. :key="element.key"
  72. :label="element.label"
  73. :label-width="element.labelWidth"
  74. :rules="element.options.rules"
  75. >
  76. <template v-if="element.type === 'input'">
  77. <el-input
  78. readonly
  79. :model-value="element.options.defaultValue"
  80. :style="{ width: element.options.width }"
  81. :placeholder="element.options.placeholder"
  82. :maxlength="parseInt(element.options.maxlength)"
  83. :clearable="element.options.clearable"
  84. :disabled="element.options.disabled"
  85. >
  86. <template v-if="element.options.prefix" #prefix>
  87. {{ element.options.prefix }}
  88. </template>
  89. <template v-if="element.options.suffix" #suffix>
  90. {{ element.options.suffix }}
  91. </template>
  92. <template v-if="element.options.prepend" #prepend>
  93. {{ element.options.prepend }}
  94. </template>
  95. <template v-if="element.options.append" #append>
  96. {{ element.options.append }}
  97. </template>
  98. </el-input>
  99. </template>
  100. <template v-if="element.type === 'password'">
  101. <el-input
  102. readonly
  103. :model-value="element.options.defaultValue"
  104. :style="{ width: element.options.width }"
  105. :placeholder="element.options.placeholder"
  106. :maxlength="parseInt(element.options.maxlength)"
  107. :clearable="element.options.clearable"
  108. :disabled="element.options.disabled"
  109. :show-password="element.options.showPassword"
  110. >
  111. <template v-if="element.options.prefix" #prefix>
  112. {{ element.options.prefix }}
  113. </template>
  114. <template v-if="element.options.suffix" #suffix>
  115. {{ element.options.suffix }}
  116. </template>
  117. <template v-if="element.options.prepend" #prepend>
  118. {{ element.options.prepend }}
  119. </template>
  120. <template v-if="element.options.append" #append>
  121. {{ element.options.append }}
  122. </template>
  123. </el-input>
  124. </template>
  125. <template v-if="element.type === 'textarea'">
  126. <el-input
  127. type="textarea"
  128. resize="none"
  129. readonly
  130. :rows="element.options.rows"
  131. :model-value="element.options.defaultValue"
  132. :style="{ width: element.options.width }"
  133. :placeholder="element.options.placeholder"
  134. :maxlength="parseInt(element.options.maxlength)"
  135. :show-word-limit="element.options.showWordLimit"
  136. :autosize="element.options.autosize"
  137. :clearable="element.options.clearable"
  138. :disabled="element.options.disabled"
  139. />
  140. </template>
  141. <template v-if="element.type === 'number'">
  142. <el-input-number
  143. :model-value="element.options.defaultValue"
  144. :style="{ width: element.options.width }"
  145. :max="element.options.max"
  146. :min="element.options.min"
  147. :disabled="element.options.disabled"
  148. />
  149. </template>
  150. <template v-if="element.type === 'radio'">
  151. <el-radio-group
  152. :model-value="element.options.defaultValue"
  153. :style="{ width: element.options.width }"
  154. :disabled="element.options.disabled"
  155. >
  156. <el-radio
  157. v-for="item of element.options.options"
  158. :key="item.value"
  159. :label="item.value"
  160. :style="{
  161. display: element.options.inline ? 'inline-block' : 'block'
  162. }"
  163. >
  164. {{ element.options.showLabel ? item.label : item.value }}
  165. </el-radio>
  166. </el-radio-group>
  167. </template>
  168. <template v-if="element.type === 'checkbox'">
  169. <el-checkbox-group
  170. :model-value="element.options.defaultValue"
  171. :style="{ width: element.options.width }"
  172. :disabled="element.options.disabled"
  173. >
  174. <el-checkbox
  175. v-for="item of element.options.options"
  176. :key="item.value"
  177. :label="item.value"
  178. :style="{
  179. display: element.options.inline ? 'inline-block' : 'block'
  180. }"
  181. >
  182. {{ element.options.showLabel ? item.label : item.value }}
  183. </el-checkbox>
  184. </el-checkbox-group>
  185. </template>
  186. <template v-if="element.type === 'time'">
  187. <el-time-picker
  188. :model-value="element.options.defaultValue"
  189. :placeholder="element.options.placeholder"
  190. :readonly="element.options.readonly"
  191. :editable="element.options.editable"
  192. :clearable="element.options.clearable"
  193. :format="element.options.format"
  194. :disabled="element.options.disabled"
  195. :style="{ width: element.options.width }"
  196. />
  197. </template>
  198. <template v-if="element.type === 'date'">
  199. <el-date-picker
  200. :model-value="element.options.defaultValue"
  201. :placeholder="element.options.placeholder"
  202. :readonly="element.options.readonly"
  203. :editable="element.options.editable"
  204. :clearable="element.options.clearable"
  205. :format="element.options.format"
  206. :disabled="element.options.disabled"
  207. :style="{ width: element.options.width }"
  208. />
  209. </template>
  210. <template v-if="element.type === 'rate'">
  211. <el-rate
  212. :model-value="element.options.defaultValue"
  213. :max="element.options.max"
  214. :allow-half="element.options.allowHalf"
  215. :disabled="element.options.disabled"
  216. />
  217. </template>
  218. <template v-if="element.type === 'select'">
  219. <el-select
  220. :model-value="element.options.defaultValue"
  221. :multiple="element.options.multiple"
  222. :placeholder="element.options.placeholder"
  223. :clearable="element.options.clearable"
  224. :filterable="element.options.filterable"
  225. :disabled="element.options.disabled"
  226. :style="{ width: element.options.width }"
  227. >
  228. <el-option
  229. v-for="item of element.options.options"
  230. :key="item.value"
  231. :value="item.value"
  232. :label="element.options.showLabel ? item.label : item.value"
  233. />
  234. </el-select>
  235. </template>
  236. <template v-if="element.type === 'switch'">
  237. <el-switch
  238. :model-value="element.options.defaultValue"
  239. :active-text="element.options.activeText"
  240. :inactive-text="element.options.inactiveText"
  241. :disabled="element.options.disabled"
  242. />
  243. </template>
  244. <template v-if="element.type === 'slider'">
  245. <el-slider
  246. :model-value="element.options.defaultValue"
  247. :min="element.options.min"
  248. :max="element.options.max"
  249. :step="element.options.step"
  250. :range="element.options.range"
  251. :disabled="element.options.disabled"
  252. :style="{ width: element.options.width }"
  253. />
  254. </template>
  255. <template v-if="element.type == 'text'">
  256. <span>{{ element.options.defaultValue }}</span>
  257. </template>
  258. <template v-if="element.type === 'img-upload'">
  259. <el-upload
  260. :name="element.options.file"
  261. :action="element.options.action"
  262. :accept="element.options.accept"
  263. :list-type="element.options.listType"
  264. :multiple="element.options.multiple"
  265. :limit="element.options.limit"
  266. :disabled="element.options.disabled"
  267. >
  268. <template v-if="element.options.listType === 'picture-card'">
  269. <el-image
  270. v-if="element.options.defaultValue?.length"
  271. style="width: 100%; height: 100%;"
  272. :preview-src-list="[
  273. '/api/sys/common/static/' + element.options.defaultValue
  274. ]"
  275. :src="'/api/sys/common/static/' + element.options.defaultValue"
  276. />
  277. <i v-else class="custom:insert" />
  278. </template>
  279. <el-button v-else>
  280. <i icon-class="custom:img-upload" style="margin-right: 10px;" />
  281. 点击上传
  282. </el-button>
  283. </el-upload>
  284. </template>
  285. <template v-if="element.type === 'download'">
  286. <el-button type="text" style="margin-top: -4px;">
  287. 下载
  288. </el-button>
  289. </template>
  290. <template v-if="element.type === 'cascader'">
  291. <el-cascader
  292. :model-value="element.options.defaultValue"
  293. :options="element.options.remoteOptions"
  294. :placeholder="element.options.placeholder"
  295. :filterable="element.options.filterable"
  296. :clearable="element.options.clearable"
  297. :disabled="element.options.disabled"
  298. :style="{ width: element.options.width }"
  299. />
  300. </template>
  301. </el-form-item>
  302. <template v-if="selectWidget?.key === element.key">
  303. <div absolute z-10 left-0 top="-.5" bg-blue-500 text-white p=".5 l-0 t-0" cursor-move :class="{'bg-yellow-500':element.type === 'grid'}">
  304. <i class="eva:move-outline" text-lg />
  305. </div>
  306. <div absolute z-10 right-0 bottom="-0.5" bg-blue-500 flex gap-1 p="1 r-.5" text-white cursor-pointer :class="{'bg-yellow-500':element.type === 'grid'}">
  307. <i class="fa6-regular:clone" @click.stop="handleCopyClick()" />
  308. <i class="fa6-regular:trash-can" @click.stop="handleDeleteClick()" />
  309. </div>
  310. </template>
  311. </div>
  312. </template>