调整json格式存储link信息

This commit is contained in:
liuwei
2025-06-10 14:29:08 +08:00
parent 4286bb21a2
commit 1d61576ae7
6 changed files with 191 additions and 39 deletions

View File

@@ -294,8 +294,26 @@
</el-dialog>
</el-tab-pane>
<el-tab-pane label="链接" name="link">
<el-form-item label="链接标题">
<el-input {% raw %}v-model="taskForm.content_link.title" {% endraw %}></el-input>
</el-form-item>
<el-form-item label="链接描述">
<el-input type="textarea" {% raw %}v-model="taskForm.content_link.des" {% endraw %}></el-input>
</el-form-item>
<el-form-item label="链接地址">
<el-input {% raw %}v-model="taskForm.content_link" {% endraw %}></el-input>
<el-input {% raw %}v-model="taskForm.content_link.url" {% endraw %}></el-input>
</el-form-item>
<el-form-item label="缩略图">
<el-upload
class="upload-demo"
action="/message_push/api/upload"
{% raw %}:on-success="handleThumbnailSuccess"
:before-upload="beforeImageUpload"
:on-preview="handleThumbnailPreview"
:file-list="thumbnailList" {% endraw %}>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件且不超过2MB</div>
</el-upload>
</el-form-item>
</el-tab-pane>
<el-tab-pane label="小程序" name="miniprogram">
@@ -377,7 +395,12 @@ new Vue({
groups: [],
content_text: '',
content_image: '',
content_link: '',
content_link: {
title: '',
des: '',
url: '',
thumburl: ''
},
content_miniprogram: {
title: '',
path: ''
@@ -412,7 +435,8 @@ new Vue({
},
imageList: [],
previewVisible: false,
previewUrl: ''
previewUrl: '',
thumbnailList: []
}
},
mounted() {
@@ -513,7 +537,12 @@ new Vue({
groups: [],
content_text: '',
content_image: '',
content_link: '',
content_link: {
title: '',
des: '',
url: '',
thumburl: ''
},
content_miniprogram: {
title: '',
path: ''
@@ -529,7 +558,13 @@ new Vue({
this.$refs.taskForm.validate(async (valid) => {
if (valid) {
try {
const response = await axios.post('/message_push/api/tasks', this.taskForm);
// 确保链接内容是JSON字符串
const formData = { ...this.taskForm };
if (formData.content_link) {
formData.content_link = JSON.stringify(formData.content_link);
}
const response = await axios.post('/message_push/api/tasks', formData);
if (response.data.success) {
this.$message.success('保存任务成功');
this.taskDialogVisible = false;
@@ -559,6 +594,31 @@ new Vue({
editTask(task) {
this.dialogTitle = '编辑任务';
this.taskForm = { ...task };
// 处理链接内容
if (task.content_link) {
try {
this.taskForm.content_link = typeof task.content_link === 'string'
? JSON.parse(task.content_link)
: task.content_link;
// 如果有缩略图,显示缩略图
if (this.taskForm.content_link.thumburl) {
const fileName = this.taskForm.content_link.thumburl.split('/').pop();
this.thumbnailList = [{
name: '已上传缩略图',
url: `/static/uploads/${fileName}`
}];
}
} catch (e) {
console.error('解析链接内容失败:', e);
this.taskForm.content_link = {
title: '',
des: '',
url: '',
thumburl: ''
};
}
}
if (task.content_image) {
// 编辑时显示图片
const fileName = task.content_image.split('/').pop();
@@ -728,6 +788,28 @@ new Vue({
this.previewVisible = true;
},
// 缩略图上传相关
handleThumbnailSuccess(response, file) {
if (response.success) {
this.taskForm.content_link.thumburl = response.data.url; // 存储绝对路径
// 显示时使用文件名
const fileName = file.name;
this.thumbnailList = [{
name: fileName,
url: `/static/uploads/${response.data.url.split('/').pop()}` // 显示时使用相对路径
}];
} else {
this.$message.error('上传失败');
}
},
handleThumbnailPreview(file) {
// 预览时使用相对路径
const fileName = file.url.split('/').pop();
this.previewUrl = `/static/uploads/${fileName}`;
this.previewVisible = true;
},
// 工具函数
getStatusType(status) {
const typeMap = {