From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/mall/product/spu/form/DescriptionForm.vue | 81 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/src/views/mall/product/spu/form/DescriptionForm.vue b/src/views/mall/product/spu/form/DescriptionForm.vue
new file mode 100644
index 0000000..63bc9d8
--- /dev/null
+++ b/src/views/mall/product/spu/form/DescriptionForm.vue
@@ -0,0 +1,81 @@
+<!-- 鍟嗗搧鍙戝竷 - 鍟嗗搧璇︽儏 -->
+<template>
+ <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px" :disabled="isDetail">
+ <!--瀵屾枃鏈紪杈戝櫒缁勪欢-->
+ <el-form-item label="鍟嗗搧璇︽儏" prop="description">
+ <Editor :readonly="isDetail" v-model:modelValue="formData.description" />
+ </el-form-item>
+ </el-form>
+</template>
+<script lang="ts" setup>
+import type { Spu } from '@/api/mall/product/spu'
+import { Editor } from '@/components/Editor'
+import { PropType } from 'vue'
+import { propTypes } from '@/utils/propTypes'
+import { copyValueToTarget } from '@/utils'
+
+defineOptions({ name: 'ProductDescriptionForm' })
+
+const message = useMessage() // 娑堟伅寮圭獥
+
+const props = defineProps({
+ propFormData: {
+ type: Object as PropType<Spu>,
+ default: () => {}
+ },
+ activeName: propTypes.string.def(''),
+ isDetail: propTypes.bool.def(false) // 鏄惁浣滀负璇︽儏缁勪欢
+})
+const formRef = ref() // 琛ㄥ崟Ref
+const formData = ref<Spu>({
+ description: '' // 鍟嗗搧璇︽儏
+})
+// 琛ㄥ崟瑙勫垯
+const rules = reactive({
+ description: [required]
+})
+
+/** 瀵屾枃鏈紪杈戝櫒濡傛灉杈撳叆杩囧啀娓呯┖浼氭湁娈嬬暀锛岄渶鍐嶉噸缃竴娆� */
+watch(
+ () => formData.value.description,
+ (newValue) => {
+ if ('<p><br></p>' === newValue) {
+ formData.value.description = ''
+ }
+ },
+ {
+ deep: true,
+ immediate: true
+ }
+)
+
+/** 灏嗕紶杩涙潵鐨勫�艰祴鍊肩粰 formData */
+watch(
+ () => props.propFormData,
+ (data) => {
+ if (!data) return
+ // fix锛氫笁涓〃鍗曠粍浠剁洃鍚祴鍊煎繀椤讳娇鐢� copyValueToTarget 浣跨敤 formData.value = data 浼氱洃鍚潪甯稿娆�
+ copyValueToTarget(formData.value, data)
+ },
+ {
+ // fix: 鍘绘帀娣卞害鐩戝惉鍙湁瀵硅薄寮曠敤鍙戠敓鏀瑰彉鐨勬椂鍊欐墠鎵ц,瑙e喅鏀逛竴鍔ㄥ鐨勯棶棰�
+ immediate: true
+ }
+)
+
+/** 琛ㄥ崟鏍¢獙 */
+const emit = defineEmits(['update:activeName'])
+const validate = async () => {
+ if (!formRef) return
+ try {
+ await unref(formRef)?.validate()
+ // 鏍¢獙閫氳繃鏇存柊鏁版嵁
+ Object.assign(props.propFormData, formData.value)
+ } catch (e) {
+ message.error('銆愬晢鍝佽鎯呫�戜笉瀹屽杽锛岃濉啓鐩稿叧淇℃伅')
+ emit('update:activeName', 'description')
+ throw e // 鐩殑鎴柇涔嬪悗鐨勬牎楠�
+ }
+}
+defineExpose({ validate })
+</script>
--
Gitblit v1.8.0