|
@@ -0,0 +1,192 @@
|
|
|
+<template>
|
|
|
+ <div class="box">
|
|
|
+ <el-card class="box-card">
|
|
|
+ <div slot="header" class="clearfix">
|
|
|
+ <span>投稿管理</span>
|
|
|
+ <el-button style="float: right; padding: 3px 0" type="text" @click="addcontribution">添加投稿</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="main">
|
|
|
+ <filterList ref="filterList" :tableData="contributionList" :filed="filed" @edit="filtereEdit" @delete="filterDelete" @query="filterQuery" :total="Total"></filterList>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
+ <dialogAndDrawer :width="'35%'" :title="title" :visibleSync="visibleSync" v-if="visibleSync" @close="visibleSync = false">
|
|
|
+ <template v-slot:windowMain>
|
|
|
+ <formData ref="formData" :filed="formfiled" :data="formdata" :rules="formrules" @save="formSave" v-if="visibleSync">
|
|
|
+ <template v-slot:formItem="{ item }">
|
|
|
+ <!-- 附件上传 -->
|
|
|
+ <el-upload
|
|
|
+ v-if="item.name == 'url'"
|
|
|
+ :headers="myHeaders"
|
|
|
+ class="upload-demo"
|
|
|
+ action="/api/files/avatar/upload"
|
|
|
+ :on-success="handleAnnexSuccess"
|
|
|
+ :on-remove="handleRemove"
|
|
|
+ :file-list="fileList">
|
|
|
+ <el-button size="small" type="primary">附件上传</el-button>
|
|
|
+ </el-upload>
|
|
|
+ </template>
|
|
|
+ </formData>
|
|
|
+ </template>
|
|
|
+ </dialogAndDrawer>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import filterList from '@components/filterList/index.vue';
|
|
|
+import dialogAndDrawer from '@components/dialogAndDrawer.vue';
|
|
|
+import formData from '@components/formData/index.vue';
|
|
|
+import { mapState, mapActions } from 'vuex';
|
|
|
+const token = sessionStorage.getItem('token');
|
|
|
+export default {
|
|
|
+ components: {
|
|
|
+ filterList,
|
|
|
+ dialogAndDrawer,
|
|
|
+ formData
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ fileList: [],
|
|
|
+ myHeaders: { Authorization: token },
|
|
|
+ title: '',
|
|
|
+ visibleSync: false,
|
|
|
+ filed: [
|
|
|
+ { name: 'title', label: '标题', filter: true },
|
|
|
+ { name: 'name', label: '姓名', filter: true },
|
|
|
+ { name: 'phone', label: '电话' }
|
|
|
+ ],
|
|
|
+ formdata: {},
|
|
|
+ formfiled: [
|
|
|
+ { name: 'title', label: '标题' },
|
|
|
+ { name: 'name', label: '姓名' },
|
|
|
+ { name: 'phone', label: '电话' },
|
|
|
+ { name: 'workUnit', label: '单位' },
|
|
|
+ { name: 'address', label: '地址' },
|
|
|
+ { name: 'status', label: '状态', formater: 'dict:contributionStatus' },
|
|
|
+ { name: 'url', label: '附件', formater: 'slot' },
|
|
|
+ { name: 'openid', label: 'openid' }
|
|
|
+ ],
|
|
|
+ formrules: {
|
|
|
+ title: [
|
|
|
+ { required: true, message: '请输入标题', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ name: [
|
|
|
+ { required: true, message: '请输入姓名', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ phone: [
|
|
|
+ { required: true, message: '请输入手机号', trigger: 'chage' }
|
|
|
+ ],
|
|
|
+ workUnit: [
|
|
|
+ { required: true, message: '请输入单位', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ address: [
|
|
|
+ { required: true, message: '请输入地址', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ status: [
|
|
|
+ { required: true, message: '请选择状态', trigger: 'chage' }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['contributionList', 'Total'])
|
|
|
+ },
|
|
|
+ async created() {
|
|
|
+ await this.filterQuery();
|
|
|
+ await this.statusQuery();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapActions(['contributionQuery', 'contributionCreate', 'contributionUpdate', 'contributionDelete', 'contributionFetch', 'statusQuery']),
|
|
|
+ // 添加
|
|
|
+ addcontribution () {
|
|
|
+ this.formdata = {};
|
|
|
+ this.title = '添加投稿';
|
|
|
+ this.visibleSync = true;
|
|
|
+ },
|
|
|
+ // 修改
|
|
|
+ async filtereEdit (e) {
|
|
|
+ this.formdata = e;
|
|
|
+ this.title = '修改投稿';
|
|
|
+ this.visibleSync = true;
|
|
|
+ },
|
|
|
+ // 删除
|
|
|
+ async filterDelete (e) {
|
|
|
+ const res = await this.contributionDelete({ id: e?._id });
|
|
|
+ this.$resChange(res, '删除成功');
|
|
|
+ this.filterQuery();
|
|
|
+ },
|
|
|
+ // 查询
|
|
|
+ async filterQuery ({ filter = {}, paging = { content: 0, size: 10 } } = {}) {
|
|
|
+ await this.contributionQuery({ filter, paging });
|
|
|
+ },
|
|
|
+ // 表单保存
|
|
|
+ async formSave (e) {
|
|
|
+ if (e.isRevise && e?.isRevise == false) {
|
|
|
+ this.$message.warning('未作修改');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$delete(e, 'isRevise');
|
|
|
+ let res, msg;
|
|
|
+ // 修改
|
|
|
+ if (e._id) {
|
|
|
+ res = await this.contributionUpdate(e);
|
|
|
+ msg = '投稿修改成功';
|
|
|
+ } else {
|
|
|
+ res = await this.contributionCreate(e);
|
|
|
+ msg = '投稿添加成功';
|
|
|
+ }
|
|
|
+ this.$resChange(res, msg);
|
|
|
+ this.filterQuery();
|
|
|
+ this.visibleSync = false;
|
|
|
+ },
|
|
|
+ // 附件上传
|
|
|
+ handleAnnexSuccess(res, file) {
|
|
|
+ this.$refs.formData.setForm('annex', res.data.filePath);
|
|
|
+ this.fileList.push({ name: res.data.name, url: res.data.filePath });
|
|
|
+ },
|
|
|
+ // 删除附件列表
|
|
|
+ handleRemove(file, fileList) {
|
|
|
+ console.log(123);
|
|
|
+ this.$refs.formData.setForm('annex', null);
|
|
|
+ delete this.fileList[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="scss" scoped>
|
|
|
+.box {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ .box-card {
|
|
|
+ height: 100%;
|
|
|
+ .el-card__body {
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+.el-dialog {
|
|
|
+ .avatar-uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+ width: 120px;
|
|
|
+ height: 120px;
|
|
|
+ line-height: 120px;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+ .avatar {
|
|
|
+ width: 120px;
|
|
|
+ height: 120px;
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|
|
|
+<style>
|
|
|
+.el-upload {
|
|
|
+ border: 1px dashed #d9d9d9;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.el-upload:hover {
|
|
|
+ border-color: #409EFF;
|
|
|
+}
|
|
|
+</style>
|