wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { deepCopy } from '@/utils/utils'
import DeUpload from '@/components/visualization/common/DeUpload.vue'
const { t } = useI18n()
const loading = ref(false)
 
const rules = {
  name: [
    {
      required: true,
      message: t('commons.input_content'),
      trigger: 'change'
    },
    {
      max: 50,
      message: t('commons.char_can_not_more_50'),
      trigger: 'change'
    }
  ],
  coverUrl: [
    {
      required: true,
      message: t('components.upload_a_cover'),
      trigger: 'change'
    }
  ]
}
const subject = ref()
const subjectDialogShow = ref(false)
const optType = ref('new')
 
const resetForm = () => {
  subject.value.clearValidate()
  subjectDialogShow.value = false
}
const subjectForm = ref(null)
const title = computed(() =>
  optType.value === 'new' ? t('components.a_new_theme') : t('components.edit_theme')
)
 
const optInit = (subjectItem, opt) => {
  optType.value = opt
  subjectDialogShow.value = true
  subjectForm.value = deepCopy(subjectItem)
}
 
const saveSubject = () => {
  subject.value.validate(result => {
    if (result) {
      emits('finish', subjectForm.value)
    }
  })
}
 
defineExpose({
  optInit,
  resetForm
})
 
const emits = defineEmits(['finish'])
const onImgChange = imgUrl => {
  subjectForm.value.coverUrl = imgUrl
}
</script>
 
<template>
  <el-dialog
    v-loading="loading"
    :title="title"
    v-model="subjectDialogShow"
    width="400px"
    :before-close="resetForm"
  >
    <el-form
      label-position="top"
      require-asterisk-position="right"
      ref="subject"
      :model="subjectForm"
      :rules="rules"
    >
      <el-form-item class="form-item" prop="name">
        <template #label>
          <label class="m-label"> {{ t('common.name') }} </label>
        </template>
        <el-input v-model="subjectForm.name" />
      </el-form-item>
      <el-form-item class="form-item" prop="coverUrl">
        <template #label>
          <label class="m-label"> {{ t('components.cover') }} </label>
        </template>
        <de-upload themes="light" :img-url="subjectForm.coverUrl" @onImgChange="onImgChange" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button secondary @click="resetForm()">{{ t('common.cancel') }}</el-button>
      <el-button type="primary" @click="saveSubject()">{{ t('chart.confirm') }}</el-button>
    </template>
  </el-dialog>
</template>
 
<style lang="less" scoped>
:deep(.ed-dialog__header) {
  text-align: left;
}
.m-label {
  color: #1f2329;
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: 14px;
  display: inline-block;
}
.form-item {
  margin-bottom: 16px;
  :deep(.ed-form-item__label) {
    line-height: 14px !important;
  }
 
  :deep(.ed-input__inner) {
    font-size: 14px !important;
  }
 
  :deep(.ed-form-item__error) {
    top: 88%;
  }
  .ed-input {
    --ed-input-height: 32px !important;
  }
 
  &:last-child {
    margin-bottom: 0;
  }
 
  :deep(.avatar-uploader-container) {
    margin-bottom: 0px;
  }
}
</style>