Files
hjsq_h5/src/views/community/publish/pubilshImg/index.vue
T
2026-11-05 12:01:36 +07:00

126 lines
3.4 KiB
Vue

<template>
<div class="publish_box">
<Header title="发布图片" rightTitle="规则" @rightFuc="state.ruleShow = true" />
<div class="content overflow-y-auto">
<div class="changeboxs" @click="$router.push('/topicMore')">
<div v-if="communityStore.tags?.id" class="info">
<lazyImg :src="communityStore.tags.coverImg" class="avatar" />
<div class="mess">
<div class="name ellipsis">#{{ communityStore.tags.name }}</div>
</div>
</div>
<div class="flex-vcenter" v-else>
<SvgIcon name="publish_#" />
<span>选择标签</span>
</div>
<SvgIcon name="publishRight" color="#fff" />
</div>
<van-field @blur="blur" class="titleText" v-model="state.title" placeholder="请填写标题" />
<h2 class="subTitle">
添加图集
<span>最大每张1M以内</span>
</h2>
<UploadImg :isCover="true" @uploadSuccess="uploadSuccess" @delImg="delImg" ref="uploadFileRef" :multiple="true" />
<div class="btnbox">
<div class="btn flex-center-center" @click="publish">确认发布</div>
</div>
</div>
<!-- <PublishTip :isOpen="state.isOpen" @close="(state.isOpen = false), $router.go(-1)" /> -->
<!-- <SelectHt :isOpen="state.htOpen" @close="state.htOpen = false" /> -->
<RulePopup :isOpen="state.ruleShow" @close="state.ruleShow = false" />
</div>
</template>
<script lang="ts">
export default {
name: 'pubilshImg',
};
</script>
<script lang="ts" setup>
import { ref, reactive, nextTick, watch } from 'vue';
import { showToast } from 'vant';
import { useRoute, useRouter } from 'vue-router';
import { useCommunityStore } from '@/stores/community';
import CommunityApi from '@/service/community';
// import SelectHt from '../components/select_ht.vue';
import RulePopup from '../components/rule_popup.vue';
const communityStore = useCommunityStore();
const router = useRouter();
const route = useRoute();
const uploadFileRef = ref(null);
const state = reactive({
title: '', //标题
imgList: <Array<string>>[], //上传图片
isOpen: false,
htOpen: false,
ruleShow: false,
});
watch(
() => route.path,
(toPath, fromPath) => {
try {
if (toPath == '/community') {
resetPublish();
}
} catch (e) {
console.log(e);
}
},
);
const blur = () => {
nextTick(() => {
window.scrollTo(0, 0);
});
};
const uploadSuccess = (img: string) => {
state.imgList.push(img);
};
const delImg = (index: number) => {
state.imgList.splice(index, 1);
};
// 发布
const publish = async () => {
if (!communityStore.tags?.id) return showToast('请选择帖子标签');
if (!state.title.trim()) return showToast('请输入标题');
if (!state.imgList.length) return showToast('请上传图片');
let req = {
title: state.title,
newsType: 'PIC',
seriesCover: state.imgList,
tags: [communityStore.tags.id],
};
try {
await CommunityApi.publishGraphics(req);
resetPublish();
showToast('发布成功');
setTimeout(() => {
router.back();
}, 1000);
// state.isOpen = true;
} catch (err) {
console.log(err);
}
};
const resetPublish = () => {
state.title = '';
state.imgList = [];
let uploadFilesRef: any = uploadFileRef.value;
uploadFilesRef.clearImg();
communityStore.setTopics(null);
};
</script>
<style lang="scss" scoped>
@import '../styles/publish.scss';
</style>