review:【antd】【mp】图文草稿箱

This commit is contained in:
YunaiV
2025-11-09 17:16:51 +08:00
parent d6cbad72e5
commit 229ead48f1
7 changed files with 52 additions and 49 deletions

View File

@@ -13,8 +13,6 @@ import { Button, Image, message, Modal, Upload } from 'ant-design-vue';
import { UploadType, useBeforeUpload } from '#/utils/useUpload';
import { WxMaterialSelect } from '#/views/mp/modules/wx-material-select';
// 设置上传的请求头部
const props = defineProps<{
isFirst: boolean;
modelValue: NewsItem;
@@ -54,10 +52,11 @@ function onMaterialSelected(item: any) {
newsItem.value.thumbMediaId = item.mediaId;
newsItem.value.thumbUrl = item.url;
}
// TODO @hw注释都补充下哈
const onBeforeUpload = (file: UploadFile) =>
useBeforeUpload(UploadType.Image, 2)(file as any);
// TODO @hw注释都补充下哈
function onUploadChange(info: any) {
if (info.file.status === 'done') {
onUploadSuccess(info.file.response || info.file);
@@ -66,6 +65,7 @@ function onUploadChange(info: any) {
}
}
// TODO @hw注释都补充下哈
function onUploadSuccess(res: any) {
if (res.code !== 0) {
message.error(`上传出错:${res.msg}`);
@@ -74,12 +74,12 @@ function onUploadSuccess(res: any) {
// 重置上传文件的表单
fileList.value = [];
// 设置草稿的封面字段
newsItem.value.thumbMediaId = res.data.mediaId;
newsItem.value.thumbUrl = res.data.url;
}
// TODO @hw注释都补充下哈
function onUploadError(err: Error) {
message.error(`上传失败: ${err.message}`);
}
@@ -88,6 +88,7 @@ function onUploadError(err: Error) {
<template>
<div>
<p>封面:</p>
<!-- TODO @hw我貌似上传不成功不确定是不是我这边的问题可以微信沟通下哈 -->
<div class="thumb-div">
<Image
v-if="newsItem.thumbUrl"
@@ -115,6 +116,7 @@ function onUploadError(err: Error) {
<Button size="small" type="primary">本地上传</Button>
</template>
</Upload>
<!-- TODO @hwtindwind -->
<Button
size="small"
type="primary"
@@ -146,6 +148,7 @@ function onUploadError(err: Error) {
</template>
<style lang="scss" scoped>
/** TODO @hw尽量使用 tindwind 替代。ps如果多个组件复用那就不用调整 */
.upload-tip {
margin-top: 5px;
margin-left: 5px;

View File

@@ -20,7 +20,6 @@ const props = defineProps<{
modelValue: NewsItem[] | null;
}>();
// v-model=newsList
const emit = defineEmits<{
(e: 'update:modelValue', v: NewsItem[]): void;
}>();
@@ -45,6 +44,7 @@ const activeNewsItem = computed(() => {
return item;
});
// TODO @hw注释使用 /** */
// 将图文向下移动
function moveDownNews(index: number) {
const current = newsList.value[index];
@@ -69,14 +69,10 @@ function moveUpNews(index: number) {
// 删除指定 index 的图文
async function removeNews(index: number) {
try {
await confirm('确定删除该图文吗?');
newsList.value.splice(index, 1);
if (activeNewsIndex.value === index) {
activeNewsIndex.value = 0;
}
} catch {
// empty
await confirm('确定删除该图文吗?');
newsList.value.splice(index, 1);
if (activeNewsIndex.value === index) {
activeNewsIndex.value = 0;
}
}
@@ -234,6 +230,7 @@ function plusNews() {
</template>
<style lang="scss" scoped>
/** TODO @hw尽量使用 tindwind 替代。ps如果多个组件复用那就不用调整 */
.ope-row {
padding-top: 5px;
margin-top: 5px;

View File

@@ -1,3 +1,4 @@
// TODO @hw要不把 components 里的部分,拿到 modules 里。
interface NewsItem {
title: string;
thumbMediaId: string;