property.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <el-form label-width="80px" :model="formData" :rules="rules">
  3. <el-form-item label="公告图标" prop="iconUrl">
  4. <UploadImg v-model="formData.iconUrl" height="48px">
  5. <template #tip>建议尺寸:24 * 24</template>
  6. </UploadImg>
  7. </el-form-item>
  8. <el-form-item label="背景颜色" prop="backgroundColor">
  9. <ColorInput v-model="formData.backgroundColor" />
  10. </el-form-item>
  11. <el-form-item label="文字颜色" prop="文字颜色">
  12. <ColorInput v-model="formData.textColor" />
  13. </el-form-item>
  14. <el-text tag="p"> 公告内容 </el-text>
  15. <el-text type="info" size="small"> 拖动左上角的小圆点可以调整热词顺序 </el-text>
  16. <template v-if="formData.contents.length">
  17. <VueDraggable
  18. :list="formData.contents"
  19. item-key="index"
  20. handle=".drag-icon"
  21. :forceFallback="true"
  22. :animation="200"
  23. class="m-t-8px"
  24. >
  25. <template #item="{ element, index }">
  26. <div class="mb-4px flex flex-row gap-4px rounded bg-gray-100 p-8px">
  27. <div class="flex flex-col items-start justify-between">
  28. <Icon icon="ic:round-drag-indicator" class="drag-icon cursor-move" />
  29. <Icon
  30. icon="ep:delete"
  31. class="cursor-pointer text-red-5"
  32. @click="handleDeleteContent(index)"
  33. v-if="formData.contents.length > 1"
  34. />
  35. </div>
  36. <div class="w-full flex flex-col gap-8px">
  37. <el-input v-model="element.text" placeholder="请输入公告" />
  38. <el-input v-model="element.url" placeholder="请输入链接" />
  39. </div>
  40. </div>
  41. </template>
  42. </VueDraggable>
  43. </template>
  44. <el-form-item label-width="0">
  45. <el-button @click="handleAddContent" type="primary" plain class="m-t-8px w-full">
  46. 添加内容
  47. </el-button>
  48. </el-form-item>
  49. </el-form>
  50. </template>
  51. <script setup lang="ts">
  52. import { NoticeBarProperty, NoticeContentProperty } from './config'
  53. import { usePropertyForm } from '@/components/DiyEditor/util'
  54. import VueDraggable from 'vuedraggable'
  55. // 通知栏属性面板
  56. defineOptions({ name: 'NoticeBarProperty' })
  57. // 表单校验
  58. const rules = {
  59. content: [{ required: true, message: '请输入公告', trigger: 'blur' }]
  60. }
  61. const props = defineProps<{ modelValue: NoticeBarProperty }>()
  62. const emit = defineEmits(['update:modelValue'])
  63. const { formData } = usePropertyForm(props.modelValue, emit)
  64. /* 添加公告 */
  65. const handleAddContent = () => {
  66. formData.value.contents.push({} as NoticeContentProperty)
  67. }
  68. /* 删除公告 */
  69. const handleDeleteContent = (index: number) => {
  70. formData.value.contents.splice(index, 1)
  71. }
  72. </script>
  73. <style scoped lang="scss"></style>