From fe90a52e90e41e6916988c50caa3c63540d588d3 Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期四, 16 十月 2025 15:35:09 +0800
Subject: [PATCH] 修改模板
---
seller/src/views/order/order/editTemplateModal.vue | 157 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 144 insertions(+), 13 deletions(-)
diff --git a/seller/src/views/order/order/editTemplateModal.vue b/seller/src/views/order/order/editTemplateModal.vue
index 31b172d..6ed906c 100644
--- a/seller/src/views/order/order/editTemplateModal.vue
+++ b/seller/src/views/order/order/editTemplateModal.vue
@@ -86,12 +86,12 @@
</div>
<!-- 璋冭瘯淇℃伅 -->
-<!-- <details style="margin-top: 20px; border: 1px solid #eee; padding: 10px;">-->
-<!-- <summary>璋冭瘯淇℃伅</summary>-->
-<!-- <pre>{{ JSON.stringify(templateData, null, 2) }}</pre>-->
-<!-- <p>閫変腑鐨勫浘鐗嘔D: {{ selectedImageId }}</p>-->
-<!-- <p>琛ㄥ崟鍊�: {{ JSON.stringify(formValues, null, 2) }}</p>-->
-<!-- </details>-->
+<!-- <details style="margin-top: 20px; border: 1px solid #eee; padding: 10px;">
+ <summary>璋冭瘯淇℃伅</summary>
+ <pre>{{ JSON.stringify(templateData, null, 2) }}</pre>
+ <p>閫変腑鐨勫浘鐗嘔D: {{ selectedImageId }}</p>
+ <p>琛ㄥ崟鍊�: {{ JSON.stringify(formValues, null, 2) }}</p>
+ </details>-->
</Form>
<div v-else>
@@ -124,6 +124,11 @@
orderSn: {
type: String,
default: ""
+ },
+ // 娣诲姞userCheckTemplates灞炴��
+ userCheckTemplates: {
+ type: Array,
+ default: () => []
}
},
data() {
@@ -136,6 +141,7 @@
},
formValues: {},
selectedImageId: null,
+ selectedImageUrl: null, // 娣诲姞閫変腑鍥剧墖URL鐨勫瓨鍌�
currentUploadFieldId: null // 褰撳墠姝e湪涓婁紶鐨勫瓧娈礗D
};
},
@@ -152,6 +158,10 @@
},
visible(val) {
this.$emit("input", val);
+ // 褰撳脊绐楀叧闂椂锛岄噸缃�変腑鐨勫浘鐗嘦RL
+ if (!val) {
+ this.selectedImageUrl = null;
+ }
}
},
methods: {
@@ -187,10 +197,15 @@
// 鍒濆鍖栭�変腑鐨勫浘鐗嘔D
this.selectedImageId = null;
+ // 澶勭悊妯℃澘鑷畾涔夋爣棰樺瓧娈电殑鍥炴樉
if (res.data.templateConstomizeTitles) {
res.data.templateConstomizeTitles.forEach(item => {
- // 鍥炴樉宸叉湁鐨勫��
- if (item.value) {
+ // 鍥炴樉宸叉湁鐨勫�� - 浠巙serCheckTemplates涓幏鍙栧搴攕ubId鐨勫��
+ const userTemplate = this.getUserTemplateBySubId(item.id);
+ if (userTemplate && userTemplate.content !== undefined && userTemplate.content !== null) {
+ this.$set(this.formValues, item.id, userTemplate.content);
+ } else if (item.value !== undefined && item.value !== null) {
+ // 濡傛灉娌℃湁鎵惧埌userCheckTemplates涓殑鍊硷紝鍒欎娇鐢ㄦā鏉块粯璁ゅ��
this.$set(this.formValues, item.id, item.value);
} else {
// 鍒濆鍖栬〃鍗曞�硷紙濡傛灉娌℃湁榛樿鍊硷級
@@ -199,14 +214,42 @@
});
}
- // 濡傛灉鏈夋ā鏉垮浘鐗囷紝璁剧疆榛樿閫変腑鐨勫浘鐗�
+ // 澶勭悊妯℃澘鍥剧墖鐨勫洖鏄�
if (res.data.templateImgs && res.data.templateImgs.length > 0) {
// 濡傛灉宸叉湁閫変腑鐨勫浘鐗嘔D锛屽垯浣跨敤璇D锛屽惁鍒欓粯璁ら�変腑绗竴寮�
if (res.data.chooseImageId) {
this.selectedImageId = res.data.chooseImageId;
+ // 鏌ユ壘閫変腑鍥剧墖鐨刄RL骞朵繚瀛�
+ const selectedImage = res.data.templateImgs.find(img => img.id === res.data.chooseImageId);
+ if (selectedImage) {
+ // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+ this.selectedImageUrl = this.processImageUrl(selectedImage.imgUrl || '');
+ }
} else {
- this.selectedImageId = res.data.templateImgs[0].id;
+ // 灏濊瘯浠巙serCheckTemplates涓幏鍙栭�変腑鐨勫浘鐗�
+ const userTemplate = this.getUserTemplateByType('IMAGE');
+ if (userTemplate && userTemplate.chooseImg) {
+ // 鏌ユ壘瀵瑰簲鐨勫浘鐗嘔D
+ const matchedImage = res.data.templateImgs.find(img => img.imgUrl === userTemplate.chooseImg);
+ if (matchedImage) {
+ this.selectedImageId = matchedImage.id;
+ // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+ this.selectedImageUrl = this.processImageUrl(matchedImage.imgUrl || '');
+ } else {
+ this.selectedImageId = res.data.templateImgs[0].id;
+ // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+ this.selectedImageUrl = this.processImageUrl(res.data.templateImgs[0].imgUrl || '');
+ }
+ } else {
+ this.selectedImageId = res.data.templateImgs[0].id;
+ // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+ this.selectedImageUrl = this.processImageUrl(res.data.templateImgs[0].imgUrl || '');
+ }
}
+ } else {
+ // 濡傛灉娌℃湁妯℃澘鍥剧墖锛屾竻绌洪�変腑鐘舵��
+ this.selectedImageId = null;
+ this.selectedImageUrl = null;
}
console.log("澶勭悊鍚庣殑鏁版嵁:", {
@@ -225,6 +268,25 @@
}
},
+ // 鏍规嵁subId鑾峰彇userCheckTemplates涓殑瀵瑰簲椤�
+ getUserTemplateBySubId(subId) {
+ // 浠巔rops涓幏鍙杣serCheckTemplates鏁版嵁
+ if (this.userCheckTemplates && this.userCheckTemplates.length > 0) {
+ // 鏌ユ壘subId鍖归厤鐨勯」
+ return this.userCheckTemplates.find(template => template.subId === subId);
+ }
+ return null;
+ },
+
+ // 鏍规嵁绫诲瀷鑾峰彇userCheckTemplates涓殑瀵瑰簲椤�
+ getUserTemplateByType(contentType) {
+ if (this.userCheckTemplates && this.userCheckTemplates.length > 0) {
+ // 鏌ユ壘contentType鍖归厤鐨勯」
+ return this.userCheckTemplates.find(template => template.contentType === contentType);
+ }
+ return null;
+ },
+
// 鑾峰彇鍥剧墖URL
getImageUrl(fileKey) {
// 纭繚fileKey鏄瓧绗︿覆绫诲瀷
@@ -239,6 +301,21 @@
return fileKey;
}
+ // 濡傛灉鏈塭ndpoint閰嶇疆锛屼娇鐢╡ndpoint鎷兼帴URL
+ if (this.$root.endpoint) {
+ // 纭繚fileKey涓嶄互/寮�澶达紝endpoint涓嶄互/缁撳熬
+ const cleanEndpoint = this.$root.endpoint.replace(/\/$/, '');
+ const cleanFileKey = fileKey.replace(/^\//, '');
+ return `${cleanEndpoint}/${cleanFileKey}`;
+ }
+
+ // 濡傛灉鏄浉瀵硅矾寰勬垨鍏朵粬鏍煎紡锛屽皾璇曢�氳繃getFilePreviewUrl鑾峰彇瀹屾暣URL
+ try {
+ return getFilePreviewUrl(fileKey);
+ } catch (error) {
+ console.warn('getFilePreviewUrl failed for fileKey:', fileKey, error);
+ }
+
// 鍚﹀垯杩斿洖fileKey锛岃缁勪欢鑷繁澶勭悊
return fileKey;
},
@@ -246,6 +323,19 @@
// 閫夋嫨鍥剧墖
selectImage(imageId) {
this.selectedImageId = imageId;
+
+ // 鏌ユ壘閫変腑鍥剧墖鐨刄RL骞朵繚瀛�
+ if (this.templateData && this.templateData.templateImgs) {
+ const selectedImage = this.templateData.templateImgs.find(img => img.id === imageId);
+ if (selectedImage) {
+ // 淇敼杩欓噷锛氬鐞嗗浘鐗嘦RL锛屽彧淇濆瓨鐩稿璺緞
+ this.selectedImageUrl = this.processImageUrl(selectedImage.imgUrl || '');
+ } else {
+ this.selectedImageUrl = '';
+ }
+ } else {
+ this.selectedImageUrl = '';
+ }
},
// 涓婁紶鍥剧墖
@@ -283,7 +373,7 @@
console.log('涓婁紶鏂囦欢杩斿洖缁撴灉:', res); // 娣诲姞璋冭瘯鏃ュ織
if (res.code === 200) {
// 涓婁紶鎴愬姛锛岃缃〃鍗曞��
- // 纭繚res.data鏄瓧绗︿覆绫诲瀷
+ // 淇敼杩欓噷锛氬彧淇濆瓨鏂囦欢鍚嶆垨鐩稿璺緞锛岃�屼笉鏄畬鏁磋矾寰�
let fileKey = '';
if (typeof res.data === 'string') {
fileKey = res.data;
@@ -299,8 +389,25 @@
fileKey = String(fileKey);
}
+ // 淇敼杩欓噷锛氬鐞嗘枃浠惰矾寰勶紝鍙繚鐣欐枃浠跺悕閮ㄥ垎
+ // 濡傛灉鏄畬鏁碪RL锛屽垯鍙彇璺緞閮ㄥ垎锛涘惁鍒欎繚鎸佸師鏍�
+ if (fileKey.startsWith('http://') || fileKey.startsWith('https://')) {
+ // 鎻愬彇URL涓殑璺緞閮ㄥ垎
+ try {
+ const urlObj = new URL(fileKey);
+ fileKey = urlObj.pathname.substring(1); // 鍘绘帀寮�澶寸殑鏂滄潬
+ } catch (e) {
+ // 濡傛灉URL瑙f瀽澶辫触锛屼繚鎸佸師鏍�
+ console.warn('Failed to parse URL:', fileKey);
+ }
+ }
+
this.$set(this.formValues, fieldId, fileKey);
+
this.$Message.success("鍥剧墖涓婁紶鎴愬姛");
+
+ // 寮哄埗鏇存柊瑙嗗浘浠ョ‘淇濆浘鐗囬瑙堟纭樉绀�
+ this.$forceUpdate();
} else {
this.$Message.error(res.msg || "鍥剧墖涓婁紶澶辫触");
}
@@ -327,6 +434,8 @@
sn: this.orderSn,
templateName: this.form.templateName,
chooseImageId: this.selectedImageId,
+ // 淇敼杩欓噷锛氬鐞哻hooseImage锛屽彧淇濆瓨鐩稿璺緞
+ chooseImage: this.processImageUrl(this.selectedImageUrl),
templateForm: []
};
@@ -337,13 +446,35 @@
id: item.id,
templateTitle: item.templateTitle,
contentType: item.contentType,
- value: this.formValues[item.id] || ""
+ // 淇敼杩欓噷锛氬鐞唙alue锛屽彧淇濆瓨鐩稿璺緞
+ value: this.processImageUrl(this.formValues[item.id]) || ""
});
});
}
console.log("鎻愪氦鍙傛暟:", params);
return params;
+ },
+
+ // 澶勭悊鍥剧墖URL锛屽彧淇濈暀鐩稿璺緞
+ processImageUrl(url) {
+ if (!url || typeof url !== 'string') {
+ return url;
+ }
+
+ // 濡傛灉鏄畬鏁碪RL锛屽垯鍙彇璺緞閮ㄥ垎锛涘惁鍒欎繚鎸佸師鏍�
+ if (url.startsWith('http://') || url.startsWith('https://')) {
+ try {
+ const urlObj = new URL(url);
+ return urlObj.pathname.substring(1); // 鍘绘帀寮�澶寸殑鏂滄潬
+ } catch (e) {
+ // 濡傛灉URL瑙f瀽澶辫触锛屼繚鎸佸師鏍�
+ console.warn('Failed to parse URL:', url);
+ return url;
+ }
+ }
+
+ return url;
},
// 纭畾鎸夐挳
@@ -476,4 +607,4 @@
border-color: #57a3f3;
color: #57a3f3;
}
-</style>
+</style>
\ No newline at end of file
--
Gitblit v1.8.0