feat: 🚀 图片排序
This commit is contained in:
116
src/components.d.ts
vendored
116
src/components.d.ts
vendored
@@ -5,62 +5,62 @@
|
||||
// Read more: https://github.com/vuejs/core/pull/3399
|
||||
export {}
|
||||
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
ElAside: typeof import('element-plus/es')['ElAside']
|
||||
ElAutocomplete: typeof import('element-plus/es')['ElAutocomplete']
|
||||
ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb']
|
||||
ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElCarousel: typeof import("element-plus/es")["ElCarousel"]
|
||||
ElCarouselItem: typeof import("element-plus/es")["ElCarouselItem"]
|
||||
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
|
||||
ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup']
|
||||
ElColorPicker: typeof import("element-plus/es")["ElColorPicker"]
|
||||
ElContainer: typeof import('element-plus/es')['ElContainer']
|
||||
ElDatePicker: typeof import('element-plus/es')['ElDatePicker']
|
||||
ElDialog: typeof import('element-plus/es')['ElDialog']
|
||||
ElDivider: typeof import('element-plus/es')['ElDivider']
|
||||
ElDrawer: typeof import('element-plus/es')['ElDrawer']
|
||||
ElDropdown: typeof import('element-plus/es')['ElDropdown']
|
||||
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
|
||||
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
|
||||
ElForm: typeof import('element-plus/es')['ElForm']
|
||||
ElFormItem: typeof import('element-plus/es')['ElFormItem']
|
||||
ElHeader: typeof import('element-plus/es')['ElHeader']
|
||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||
ElImage: typeof import('element-plus/es')['ElImage']
|
||||
ElInput: typeof import('element-plus/es')['ElInput']
|
||||
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
|
||||
ElMain: typeof import('element-plus/es')['ElMain']
|
||||
ElMenu: typeof import('element-plus/es')['ElMenu']
|
||||
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
|
||||
ElOption: typeof import('element-plus/es')['ElOption']
|
||||
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||
ElRadioButton: typeof import("element-plus/es")["ElRadioButton"]
|
||||
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
||||
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
||||
ElSelect: typeof import('element-plus/es')['ElSelect']
|
||||
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
|
||||
ElSwitch: typeof import('element-plus/es')['ElSwitch']
|
||||
ElTable: typeof import('element-plus/es')['ElTable']
|
||||
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
|
||||
ElTabPane: typeof import('element-plus/es')['ElTabPane']
|
||||
ElTabs: typeof import('element-plus/es')['ElTabs']
|
||||
ElTag: typeof import('element-plus/es')['ElTag']
|
||||
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
||||
ElTree: typeof import("element-plus/es")["ElTree"]
|
||||
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
|
||||
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||
IEpArrowDown: typeof import('~icons/ep/arrow-down')['default']
|
||||
IEpCircleClose: typeof import('~icons/ep/circle-close')['default']
|
||||
IEpFolderDelete: typeof import('~icons/ep/folder-delete')['default']
|
||||
IEpFullScreen: typeof import('~icons/ep/full-screen')['default']
|
||||
IEpRemove: typeof import('~icons/ep/remove')['default']
|
||||
IEpSearch: typeof import('~icons/ep/search')['default']
|
||||
IEpSwitchButton: typeof import('~icons/ep/switch-button')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
}
|
||||
declare module "vue" {
|
||||
export interface GlobalComponents {
|
||||
ElAside: typeof import("element-plus/es")["ElAside"];
|
||||
ElAutocomplete: typeof import("element-plus/es")["ElAutocomplete"];
|
||||
ElBreadcrumb: typeof import("element-plus/es")["ElBreadcrumb"];
|
||||
ElBreadcrumbItem: typeof import("element-plus/es")["ElBreadcrumbItem"];
|
||||
ElButton: typeof import("element-plus/es")["ElButton"];
|
||||
ElCarousel: typeof import("element-plus/es")["ElCarousel"];
|
||||
ElCarouselItem: typeof import("element-plus/es")["ElCarouselItem"];
|
||||
ElCheckbox: typeof import("element-plus/es")["ElCheckbox"];
|
||||
ElCheckboxGroup: typeof import("element-plus/es")["ElCheckboxGroup"];
|
||||
ElColorPicker: typeof import("element-plus/es")["ElColorPicker"];
|
||||
ElContainer: typeof import("element-plus/es")["ElContainer"];
|
||||
ElDatePicker: typeof import("element-plus/es")["ElDatePicker"];
|
||||
ElDialog: typeof import("element-plus/es")["ElDialog"];
|
||||
ElDivider: typeof import("element-plus/es")["ElDivider"];
|
||||
ElDrawer: typeof import("element-plus/es")["ElDrawer"];
|
||||
ElDropdown: typeof import("element-plus/es")["ElDropdown"];
|
||||
ElDropdownItem: typeof import("element-plus/es")["ElDropdownItem"];
|
||||
ElDropdownMenu: typeof import("element-plus/es")["ElDropdownMenu"];
|
||||
ElForm: typeof import("element-plus/es")["ElForm"];
|
||||
ElFormItem: typeof import("element-plus/es")["ElFormItem"];
|
||||
ElHeader: typeof import("element-plus/es")["ElHeader"];
|
||||
ElIcon: typeof import("element-plus/es")["ElIcon"];
|
||||
ElImage: typeof import("element-plus/es")["ElImage"];
|
||||
ElInput: typeof import("element-plus/es")["ElInput"];
|
||||
ElInputNumber: typeof import("element-plus/es")["ElInputNumber"];
|
||||
ElMain: typeof import("element-plus/es")["ElMain"];
|
||||
ElMenu: typeof import("element-plus/es")["ElMenu"];
|
||||
ElMenuItem: typeof import("element-plus/es")["ElMenuItem"];
|
||||
ElOption: typeof import("element-plus/es")["ElOption"];
|
||||
ElPagination: typeof import("element-plus/es")["ElPagination"];
|
||||
ElRadio: typeof import("element-plus/es")["ElRadio"];
|
||||
ElRadioButton: typeof import("element-plus/es")["ElRadioButton"];
|
||||
ElRadioGroup: typeof import("element-plus/es")["ElRadioGroup"];
|
||||
ElScrollbar: typeof import("element-plus/es")["ElScrollbar"];
|
||||
ElSelect: typeof import("element-plus/es")["ElSelect"];
|
||||
ElSubMenu: typeof import("element-plus/es")["ElSubMenu"];
|
||||
ElSwitch: typeof import("element-plus/es")["ElSwitch"];
|
||||
ElTable: typeof import("element-plus/es")["ElTable"];
|
||||
ElTableColumn: typeof import("element-plus/es")["ElTableColumn"];
|
||||
ElTabPane: typeof import("element-plus/es")["ElTabPane"];
|
||||
ElTabs: typeof import("element-plus/es")["ElTabs"];
|
||||
ElTag: typeof import("element-plus/es")["ElTag"];
|
||||
ElTooltip: typeof import("element-plus/es")["ElTooltip"];
|
||||
ElTree: typeof import("element-plus/es")["ElTree"];
|
||||
ElTreeSelect: typeof import("element-plus/es")["ElTreeSelect"];
|
||||
ElUpload: typeof import("element-plus/es")["ElUpload"];
|
||||
IEpArrowDown: typeof import("~icons/ep/arrow-down")["default"];
|
||||
IEpCircleClose: typeof import("~icons/ep/circle-close")["default"];
|
||||
IEpFolderDelete: typeof import("~icons/ep/folder-delete")["default"];
|
||||
IEpFullScreen: typeof import("~icons/ep/full-screen")["default"];
|
||||
IEpRemove: typeof import("~icons/ep/remove")["default"];
|
||||
IEpSearch: typeof import("~icons/ep/search")["default"];
|
||||
IEpSwitchButton: typeof import("~icons/ep/switch-button")["default"];
|
||||
RouterLink: typeof import("vue-router")["RouterLink"];
|
||||
RouterView: typeof import("vue-router")["RouterView"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import { h } from "@/utils/url";
|
||||
import { routerObj } from "./utils.js";
|
||||
import { titleConfig } from "./titleConfig.js";
|
||||
import { uploadVideo, uploadImg } from "@/api/modules/upload";
|
||||
import { ElNotification } from "element-plus";
|
||||
//uploadImg
|
||||
// 字体配置
|
||||
let fontSizeStyle = Quill.import("attributors/style/size");
|
||||
@@ -87,13 +88,14 @@ const props = defineProps({
|
||||
const editorContent = computed({
|
||||
get: () => props.content,
|
||||
set: val => {
|
||||
console.log(val, "======value==========");
|
||||
emit("update:content", val);
|
||||
}
|
||||
});
|
||||
//富文本ref
|
||||
const myQuillEditor = ref(null);
|
||||
//富文本值
|
||||
const oldContent = ref("");
|
||||
// const oldContent = ref("");
|
||||
//富文本配置项
|
||||
const options = reactive({
|
||||
theme: "snow",
|
||||
@@ -149,16 +151,32 @@ const options = reactive({
|
||||
]
|
||||
}
|
||||
});
|
||||
// 对 imageListDb 按文件名末尾数字排序(从小到大)
|
||||
const sortImageListByNumber = () => {
|
||||
imageListDb.value.sort((a, b) => {
|
||||
// 提取文件名中的数字(匹配末尾的 -数字 格式)
|
||||
const getNumber = fileName => {
|
||||
// 正则匹配:以 - 开头,后面跟数字,且在文件名末尾(\d+$ 表示数字结尾)
|
||||
const match = fileName.match(/-(\d+)$/);
|
||||
// 若匹配到数字则返回,否则返回 0(避免无数字的文件排序出错)
|
||||
return match ? parseInt(match[1], 10) : 0;
|
||||
};
|
||||
|
||||
// 分别获取 a 和 b 文件名中的数字
|
||||
const numA = getNumber(a.name);
|
||||
const numB = getNumber(b.name);
|
||||
|
||||
// 按数字从小到大排序(numA - numB 为升序)
|
||||
return numA - numB;
|
||||
});
|
||||
};
|
||||
// 上传前的钩子
|
||||
const handleBeforeUpload = file => {
|
||||
const fileType = file.type;
|
||||
console.log(file, "====file====");
|
||||
|
||||
// 为文件添加唯一标识
|
||||
file.customUid = generateUUID(); // 确保有唯一ID
|
||||
imageListDb.value.push(file);
|
||||
|
||||
sortImageListByNumber();
|
||||
// 图片和视频格式校验
|
||||
const validTypes = [
|
||||
"image/jpeg",
|
||||
@@ -177,36 +195,42 @@ const handleBeforeUpload = file => {
|
||||
// 校检文件大小
|
||||
const isLt = file.size / 1024 / 1024 < props.fileSizeLimit;
|
||||
if (!isLt) {
|
||||
console.log(`上传文件大小不能超过 ${props.fileSizeLimit} MB!`);
|
||||
alert(`上传文件大小不能超过 ${props.fileSizeLimit} MB!`);
|
||||
ElNotification({
|
||||
title: "温馨提示",
|
||||
message: `上传文件大小不能超过 ${props.fileSizeLimit} MB!`,
|
||||
type: "warning"
|
||||
});
|
||||
|
||||
imageListDb.value = [];
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
alert(`文件格式不正确!`);
|
||||
ElNotification({
|
||||
title: "温馨提示",
|
||||
message: `文件格式不正确!`,
|
||||
type: "warning"
|
||||
});
|
||||
imageListDb.value = [];
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 图片上传
|
||||
const handleHttpUpload = async options => {
|
||||
console.log(imageListDb.value.length, "==============length============");
|
||||
let formData = new FormData();
|
||||
formData.append("image", options.file);
|
||||
imageList.value.push(options.file);
|
||||
|
||||
try {
|
||||
const result = await uploadImg(formData, routerName.value, options.file.customUid);
|
||||
|
||||
// 假设服务器返回格式为 { imgId: 'xxx', data: { code: 0, data: { path: 'xxx' } } }
|
||||
const { imgId } = result;
|
||||
console.log(imgId, "==========imgId from server");
|
||||
|
||||
if (result?.data?.code === 0) {
|
||||
const { data } = result?.data;
|
||||
|
||||
// 1. 通过customUid查找对应的文件对象
|
||||
const fileItem = imageListDb.value.find(item => item.customUid === options.file.customUid);
|
||||
const fileItem = imageListDb.value.find(item => item.customUid === imgId);
|
||||
if (fileItem) {
|
||||
fileItem.serverImgId = imgId; // 保存服务器返回的imgId
|
||||
fileItem.path = data.path; // 保存图片路径
|
||||
@@ -228,8 +252,6 @@ const handleHttpUpload = async options => {
|
||||
imageListDb.value.forEach((item, index) => {
|
||||
// 获取光标位置(每次插入后光标会移动)
|
||||
const length = quill.getLength() - 1; // 文本末尾
|
||||
console.log(length, "=插入位置=");
|
||||
|
||||
quill.insertEmbed(length, "image", {
|
||||
url: h + item.path,
|
||||
id: item.serverImgId || generateUUID()
|
||||
@@ -252,86 +274,6 @@ const handleHttpUpload = async options => {
|
||||
}
|
||||
};
|
||||
|
||||
// //上传前的钩子
|
||||
// const handleBeforeUpload = file => {
|
||||
// const fileType = file.type;
|
||||
// console.log(file, "====file====");
|
||||
// imageListDb.value.push(file);
|
||||
// // 图片
|
||||
// if (
|
||||
// fileType == "image/jpeg" ||
|
||||
// fileType == "image/png" ||
|
||||
// fileType == "image/gif" ||
|
||||
// fileType == "image/jpg" ||
|
||||
// fileType == "image/bmp" ||
|
||||
// fileType == "image/webp" ||
|
||||
// fileType == "video/mov" ||
|
||||
// fileType == "video/ts" ||
|
||||
// fileType == "video/mp4" ||
|
||||
// fileType == "video/avi"
|
||||
// ) {
|
||||
// const fileSizeLimit = file.size;
|
||||
// // 校检文件大小
|
||||
// const isLt = fileSizeLimit / 1024 / 1024 < props.fileSizeLimit;
|
||||
// if (!isLt) {
|
||||
// console.log(`上传文件大小不能超过 ${props.fileSizeLimit} MB!`);
|
||||
// alert(`上传文件大小不能超过 ${props.fileSizeLimit} MB!`);
|
||||
// return false;
|
||||
// } else {
|
||||
// console.log(`RIch MB!`);
|
||||
// return true;
|
||||
// }
|
||||
// } else {
|
||||
// alert(`文件格式不正确!`);
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
// //图片上传
|
||||
// const handleHttpUpload = async options => {
|
||||
// console.log(imageListDb.value.length, "==============length============");
|
||||
// let formData = new FormData();
|
||||
// //这里要根据后端设置的name设置key值,如果name是file就传file是image就传image
|
||||
// formData.append("image", options.file);
|
||||
// imageList.value.push(options.file);
|
||||
// try {
|
||||
// const result = await uploadImg(formData, routerName.value, options.file.uid);
|
||||
// const { imgId } = result;
|
||||
// console.log(imgId, "==========sdsdsd");
|
||||
// if (result?.data?.code === 0) {
|
||||
// const { data } = result?.data;
|
||||
// //获取到imgId,将data.path匹配
|
||||
// let iLength = imageListDb.value.length;
|
||||
// for (let i = 0; i < iLength; i++) {
|
||||
// let item = imageListDb.value[i];
|
||||
// if (item.uid == imgId) {
|
||||
// item.path = data.path;
|
||||
// }
|
||||
// }
|
||||
// if (imageList.value.length === imageListDb.value.length) {
|
||||
// console.log("走进来了");
|
||||
// let tLength = imageListDb.value.length;
|
||||
// for (let j = 0; j < tLength; j++) {
|
||||
// let rawMyQuillEditor = toRaw(myQuillEditor.value);
|
||||
// // 获取富文本实例
|
||||
// let quill = rawMyQuillEditor.getQuill();
|
||||
// // 获取光标位置
|
||||
// let length = quill.selection.savedRange.index;
|
||||
// console.log(length, "=光标length=");
|
||||
// quill.insertEmbed(length, "image", {
|
||||
// url: h + imageListDb.value[j].path,
|
||||
// id: generateUUID()
|
||||
// });
|
||||
// quill.setSelection(length + 1);
|
||||
// if (j === tLength - 1) {
|
||||
// imageList.value = [];
|
||||
// imageListDb.value = [];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } catch (error) {}
|
||||
// };
|
||||
|
||||
//视频上传
|
||||
const handleVideoUpload = async evt => {
|
||||
if (evt.target.files.length === 0) {
|
||||
@@ -367,9 +309,22 @@ const initTitle = () => {
|
||||
tip.setAttribute("title", item.title);
|
||||
}
|
||||
};
|
||||
// 获取 Quill 实例并定义清空方法
|
||||
const clearEditor = () => {
|
||||
const rawMyQuillEditor = toRaw(myQuillEditor.value);
|
||||
if (rawMyQuillEditor) {
|
||||
const quill = rawMyQuillEditor.getQuill();
|
||||
quill.setText(""); // 清空内容(会触发 v-model 同步)
|
||||
editorContent.value = ""; // 同步更新绑定的变量
|
||||
}
|
||||
};
|
||||
onMounted(() => {
|
||||
initTitle();
|
||||
oldContent.value = props.content;
|
||||
// oldContent.value = props.content;
|
||||
});
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
clearEditor
|
||||
});
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</template>
|
||||
<template #default="scope" v-if="item.formType === 'inputNumber'">
|
||||
<el-input-number
|
||||
:min="1"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:controls="true"
|
||||
style="width: 125px"
|
||||
|
||||
@@ -119,9 +119,9 @@ const handleHttpUpload = async (options: UploadRequestOptions) => {
|
||||
const api = props.api ?? uploadImg;
|
||||
|
||||
const result = await api(formData, routerName.value);
|
||||
console.log(result, "============>>>");
|
||||
if (result?.data?.code === 0) {
|
||||
const { data } = result;
|
||||
emit("update:imageUrl", data.path);
|
||||
emit("update:imageUrl", result?.data?.data.path);
|
||||
}
|
||||
|
||||
// 调用 el-form 内部的校验方法(可自动校验)
|
||||
|
||||
@@ -136,10 +136,8 @@ const handleHttpUpload = async (options: UploadRequestOptions) => {
|
||||
const api = props.api ?? uploadImg;
|
||||
|
||||
const { data } = await api(formData, routerName.value);
|
||||
console.log(data, "============>>>.");
|
||||
|
||||
console.log(data.path, "========data==========");
|
||||
options.onSuccess(data.path);
|
||||
console.log(data.data.path, "========data==========");
|
||||
options.onSuccess(data.data.path);
|
||||
} catch (error) {
|
||||
options.onError(error as any);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</template>
|
||||
<template v-if="item.type === 'inputNumber'">
|
||||
<el-input-number
|
||||
:min="1"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:controls="true"
|
||||
v-model="_ruleForm[`${item.prop}`]"
|
||||
@@ -178,7 +178,7 @@
|
||||
<slot />
|
||||
</template>
|
||||
<template v-if="item.type === 'WangEditor'">
|
||||
<Editor v-model:content="_ruleForm[`${item.prop}`]"></Editor>
|
||||
<Editor v-model:content="_ruleForm[`${item.prop}`]" ref="editorRef"></Editor>
|
||||
</template>
|
||||
</el-form-item>
|
||||
</template>
|
||||
@@ -209,7 +209,7 @@ const emits = defineEmits<{
|
||||
(e: "handleRadioGroupEmits", result?: any): void;
|
||||
(e: "handleTreesSelectChangeEmits", result?: any): void;
|
||||
}>();
|
||||
|
||||
const editorRef = ref<any>(null);
|
||||
const ruleFormRef = ref<FormInstance>();
|
||||
const props = defineProps<IProps>();
|
||||
//本地化处理,props是单向的,通过本地化就可以改变父组件传过来的值了
|
||||
@@ -235,7 +235,8 @@ const handleRadioGroup = (value: any) => {
|
||||
// 暴露给父组件的参数和方法(外部需要什么,都可以从这里暴露出去)
|
||||
defineExpose({
|
||||
ruleForm: _ruleForm,
|
||||
ruleFormRef: ruleFormRef
|
||||
ruleFormRef: ruleFormRef,
|
||||
editorRef: editorRef
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<el-tab-pane label="问答详细" name="third">
|
||||
<div style="width: 1280px; margin: 0 auto">
|
||||
<Editor v-model:content="dataStore.editRuleForm.answer" />
|
||||
<Editor v-model:content="dataStore.editRuleForm.answer" ref="editorRef" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
@@ -47,6 +47,7 @@ const dataStore = reactive<any>({
|
||||
rules: RULES
|
||||
});
|
||||
const formRef: any = ref(null);
|
||||
const editorRef = ref<any>(null);
|
||||
//详情
|
||||
const getQAListDetails = async () => {
|
||||
let id = $route.query.id;
|
||||
@@ -58,6 +59,9 @@ const getQAListDetails = async () => {
|
||||
const { data } = result;
|
||||
//这里是传给基本信息组件的表单数据
|
||||
dataStore.editRuleForm = cloneDeep(data);
|
||||
if (!data.answer) {
|
||||
editorRef!.value!.clearEditor();
|
||||
}
|
||||
// dataStore.editRuleForm.answer = convertSpanToDiv(dataStore.editRuleForm.answer);
|
||||
|
||||
dataStore.value = data.answer;
|
||||
@@ -93,9 +97,11 @@ const handleReset = () => {
|
||||
const resetFields = () => {
|
||||
if (!formRef.value!.ruleFormRef) return;
|
||||
formRef!.value!.ruleFormRef.resetFields();
|
||||
editorRef!.value!.clearEditor();
|
||||
for (let key in dataStore.editRuleForm) {
|
||||
dataStore.editRuleForm[key] = "";
|
||||
}
|
||||
dataStore.editRuleForm.sort = 1;
|
||||
// dataStore.value = "";
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<el-tab-pane label="详细内容" name="third">
|
||||
<div style="width: 1280px; margin: 0 auto">
|
||||
<Editor v-model:content="dataStore.editRuleForm.content"></Editor>
|
||||
<Editor v-model:content="dataStore.editRuleForm.content" ref="editorRef"></Editor>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
@@ -47,7 +47,7 @@ import { useMsg } from "@/hooks/useMsg";
|
||||
const formRef = ref<any>(null);
|
||||
const activeName = ref("basicInfo");
|
||||
const $route = useRoute();
|
||||
|
||||
const editorRef = ref<any>(null);
|
||||
//数据集合
|
||||
const dataStore = reactive<any>({
|
||||
rules: cloneDeep(RULES), //抽屉表单验证
|
||||
@@ -79,6 +79,9 @@ const getArticleListDetails = async () => {
|
||||
if (result?.code === 0) {
|
||||
const { data } = result;
|
||||
dataStore.editRuleForm = data;
|
||||
if (!data.content) {
|
||||
editorRef.value.clearEditor(); // 调用子组件的清空方法
|
||||
}
|
||||
// dataStore.editRuleForm.content = convertSpanToDiv(dataStore.editRuleForm.content);
|
||||
let is = dataStore.editFormData[1].options.some((item: any) =>
|
||||
recursiveCompare(item, dataStore.editRuleForm.category_id)
|
||||
@@ -148,6 +151,13 @@ const handleConfirmClick = () => {
|
||||
const handleReset = () => {
|
||||
if ($route.query.type === "add") {
|
||||
dataStore.editRuleForm = cloneDeep(EDIT_RULE_FORM);
|
||||
editorRef.value.clearEditor(); // 调用子组件的清空方法
|
||||
// if (!data.detail) {
|
||||
// dataStore.detail = "";
|
||||
// editorRef.value.clearEditor(); // 调用子组件的清空方法
|
||||
// } else {
|
||||
// dataStore.detail = cloneDeep(data.detail);
|
||||
// }
|
||||
} else {
|
||||
getArticleListDetails();
|
||||
}
|
||||
|
||||
@@ -224,6 +224,9 @@ const getBannerRead = async (id: any) => {
|
||||
if (result?.code === 0) {
|
||||
setImgOrVideo(result);
|
||||
getProductCategoryList();
|
||||
if (!result?.data?.desc) {
|
||||
formRef?.value?.editorRef[0]?.clearEditor();
|
||||
}
|
||||
nextTick(() => {
|
||||
dataStore.editRuleForm = result?.data;
|
||||
if (dataStore.editRuleForm.link && dataStore.editRuleForm.link_to) {
|
||||
@@ -231,7 +234,6 @@ const getBannerRead = async (id: any) => {
|
||||
if (!id || !name || !link) {
|
||||
return;
|
||||
}
|
||||
console.log("1232323");
|
||||
let obj: any = {
|
||||
label: name, // 确保这里的name是你想要显示的文本
|
||||
value: `${dataStore.editRuleForm.link_to}` + "/" + `${id}` + "/" + `${name}`,
|
||||
@@ -331,6 +333,7 @@ const handleConfirmClick = () => {
|
||||
const resetFields = () => {
|
||||
if (!formRef.value!.ruleFormRef) return;
|
||||
formRef!.value!.ruleFormRef.resetFields();
|
||||
formRef?.value?.editorRef[0]?.clearEditor();
|
||||
};
|
||||
// 抽屉重置
|
||||
const handleResetClick = () => {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<!-- <el-input v-model="_ruleFormParam.sort" /> -->
|
||||
|
||||
<el-input-number
|
||||
:min="1"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
:controls="true"
|
||||
v-model="_ruleFormParam.sort"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<div class="table-box">
|
||||
<div style="padding-bottom: 16px">
|
||||
<el-button @click="handleReset(dataStore)"> 重置 </el-button>
|
||||
<el-button @click="handleReset(dataStore, editorRef)"> 重置 </el-button>
|
||||
<el-button type="primary" @click="handleSubmit(infoRef, imgInfoRef, dataStore)"> 提交 </el-button>
|
||||
</div>
|
||||
<div class="card table-main">
|
||||
@@ -16,7 +16,7 @@
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="产品详情" name="third">
|
||||
<div style="width: 1280px; margin: 0 auto">
|
||||
<Editor v-model:content="dataStore.detail" />
|
||||
<Editor v-model:content="dataStore.detail" ref="editorRef" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="相关信息" name="related">
|
||||
@@ -65,6 +65,9 @@ import imgInfo from "./components/imgInfo.vue";
|
||||
import FormTable from "@/components/FormTable/index.vue";
|
||||
|
||||
const $route = useRoute();
|
||||
|
||||
const editorRef = ref<any>(null);
|
||||
|
||||
//数据集合
|
||||
const dataStore = reactive<any>({
|
||||
relatedColumns: cloneDeep(RELATED_INFO_COLUMNS), //相关信息及下载表格配置
|
||||
@@ -94,7 +97,7 @@ const getProductDetails = async () => {
|
||||
if (result?.code === 0) {
|
||||
const { data } = result;
|
||||
//参数初始化(将参数按照不同的tab区分出来)
|
||||
initDetailParams(dataStore, data);
|
||||
initDetailParams(dataStore, data, editorRef);
|
||||
}
|
||||
};
|
||||
getProductDetails();
|
||||
|
||||
@@ -16,7 +16,7 @@ const hasIdRecursive = (data: any, targetId: any) => {
|
||||
};
|
||||
|
||||
//将参数分离
|
||||
export const initDetailParams = (dataStore: any, data: any) => {
|
||||
export const initDetailParams = (dataStore: any, data: any, editorRef: any) => {
|
||||
let is = hasIdRecursive(dataStore.options, data.category_id);
|
||||
//基本信息
|
||||
dataStore.basicInfoRuleForm = cloneDeep({
|
||||
@@ -40,9 +40,15 @@ export const initDetailParams = (dataStore: any, data: any) => {
|
||||
stock_qty: data.stock_qty,
|
||||
id: data.id
|
||||
});
|
||||
console.log(dataStore.basicInfoRuleForm, "= dataStore.basicInfoRuleForm=");
|
||||
//详情
|
||||
dataStore.detail = cloneDeep(data.detail);
|
||||
//dataStore.detail = convertSpanToDiv(dataStore.detail);
|
||||
if (!data.detail) {
|
||||
dataStore.detail = "";
|
||||
editorRef.value.clearEditor(); // 调用子组件的清空方法
|
||||
} else {
|
||||
dataStore.detail = cloneDeep(data.detail);
|
||||
}
|
||||
|
||||
//图片
|
||||
dataStore.imgInfoData.cover_image = data.cover_image;
|
||||
dataStore.imgInfoData.video_url = data.video_url;
|
||||
|
||||
@@ -4,19 +4,19 @@ import { messageBox } from "@/utils/messageBox";
|
||||
// import { cloneDeep } from "lodash-es";
|
||||
import { initDetailParams } from "./initDetailParams";
|
||||
//详情(重置,重新获取一下详情)
|
||||
const getProductDetails = async (dataStore: any) => {
|
||||
const getProductDetails = async (dataStore: any, editorRef: any) => {
|
||||
const { id } = dataStore.basicInfoRuleForm;
|
||||
const result = await getProductDetailsApi(id);
|
||||
if (result?.code === 0) {
|
||||
const { data } = result;
|
||||
|
||||
initDetailParams(dataStore, data);
|
||||
initDetailParams(dataStore, data, editorRef);
|
||||
useMsg("success", "重置成功 !");
|
||||
}
|
||||
};
|
||||
|
||||
export const handleReset = (dataStore: any) => {
|
||||
export const handleReset = (dataStore: any, editorRef?: any) => {
|
||||
messageBox("该操作会将数据重置为初始状态", () => {
|
||||
getProductDetails(dataStore);
|
||||
getProductDetails(dataStore, editorRef);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user