123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <div id="index">
- <el-row>
- <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
- <el-col :span="24" class="one">
- <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch">
- <template #type>
- <el-option v-for="i in typeList" :key="i.value" :label="i.label" :value="i.value"></el-option>
- </template>
- </cSearch>
- </el-col>
- <el-col :span="24" class="two">
- <cButton @toAdd="toAdd()"> </cButton>
- </el-col>
- <el-col :span="24" class="thr">
- <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @exam="toExam" @edit="toEdit" @del="toDel">
- <template #is_use="{ row }">
- <el-switch
- v-model="row.is_use"
- inline-prompt
- active-text="是"
- inactive-text="否"
- active-value="0"
- inactive-value="1"
- @click="handleChange(row)"
- ></el-switch>
- </template>
- </cTable>
- </el-col>
- </el-col>
- </el-row>
- <cDialog :dialog="dialog" @toClose="toClose">
- <template v-slot:info>
- <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
- <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
- <template #status>
- <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
- </template>
- </cForm>
- </el-col>
- </template>
- </cDialog>
- </div>
- </template>
- <script setup lang="ts">
- // 基础
- import store from '@/stores/counter';
- import type { Ref } from 'vue';
- import { ref, onMounted, getCurrentInstance } from 'vue';
- import { ElMessage, ElMessageBox } from 'element-plus';
- import { useRouter } from 'vue-router';
- // 接口
- import { ArticleStore } from '@/stores/content/article';
- import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
- import type { IQueryResult } from '@/util/types.util';
- const articleAxios = ArticleStore();
- const dictAxios = DictDataStore();
- const { proxy } = getCurrentInstance() as any;
- let user: Ref<any> = ref(store.state.user);
- // 路由
- const router = useRouter();
- // 加载中
- const loading: Ref<any> = ref(false);
- let list: Ref<any> = ref([]);
- let total: Ref<number> = ref(0);
- let skip = 0;
- let limit: number = proxy.$limit;
- let fields: Ref<any[]> = ref([
- { label: '发布人', model: 'contact_name', isSearch: true },
- { label: '标题', model: 'title', isSearch: true },
- { label: '类型', model: 'type', type: 'select', isSearch: true, format: (i: any) => getDict(i) },
- { label: '创建时间', model: 'create_time' },
- { label: '排序', model: 'sort', type: 'number' },
- { label: '是否启用', model: 'is_use', custom: true }
- ]);
- // 操作
- let opera: Ref<any[]> = ref([
- { label: '审核', method: 'exam', type: 'warning', display: (i: any) => i.status == '0' && user.value.type == '0' },
- { label: '修改', method: 'edit' },
- { label: '删除', method: 'del', confirm: true, type: 'danger' }
- ]);
- // 查询数据
- let searchForm: Ref<any> = ref({});
- // 字典表
- let is_useList: Ref<any> = ref([]);
- let statusList: Ref<any> = ref([]);
- let typeList: Ref<any> = ref([]);
- // 弹框
- const dialog: Ref<any> = ref({ title: '信息管理', show: false, type: '1' });
- const form: Ref<any> = ref({});
- const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
- // 请求
- onMounted(async () => {
- loading.value = true;
- await searchOther();
- await search({ skip, limit });
- loading.value = false;
- });
- const search = async (e: { skip: number; limit: number }) => {
- const info = { skip: e.skip, limit: e.limit, ...searchForm.value };
- const res: any = await articleAxios.query(info);
- if (res.errcode == '0') {
- list.value = res.data;
- total.value = res.total;
- }
- };
- const toSearch = (query: any) => {
- searchForm.value = query;
- search({ skip, limit });
- };
- const getDict = (value: any) => {
- if (value) {
- let data = typeList.value.find((i: any) => i.value == value);
- if (data) return data.label;
- else return '暂无';
- }
- };
- // 审核
- const toExam = async (data: any) => {
- let res: IQueryResult = await articleAxios.fetch(data._id);
- if (res.errcode == '0') {
- form.value = res.data;
- dialog.value = { title: '审核管理', show: true, type: '1' };
- }
- };
- // 提交保存
- const toSave = async (data: any) => {
- let res: IQueryResult;
- if (data._id) res = await articleAxios.update(data);
- else res = await articleAxios.create(data);
- if (res.errcode == 0) {
- ElMessage({ type: `success`, message: `维护信息成功` });
- toClose();
- }
- };
- // 新增
- const toAdd = () => {
- router.push({ path: '/content/article/detail' });
- };
- // 修改
- const toEdit = async (data: any) => {
- router.push({ path: '/content/article/detail', query: { id: data._id } });
- };
- // 删除
- const toDel = async (data: any) => {
- let res: IQueryResult = await articleAxios.del(data._id);
- if (res.errcode == 0) {
- ElMessage({ type: `success`, message: `刪除信息成功` });
- search({ skip, limit });
- }
- };
- // 关闭弹框
- const toClose = () => {
- form.value = { file: [] };
- dialog.value = { show: false };
- search({ skip, limit });
- };
- // 查询其他信息
- const searchOther = async () => {
- let res: IQueryResult;
- res = await dictAxios.query({ type: 'is_use', is_use: '0' });
- if (res.errcode == 0) is_useList.value = res.data;
- // 状态
- res = await dictAxios.query({ type: 'exam_status', is_use: '0' });
- if (res.errcode == '0') statusList.value = res.data;
- // 类型
- res = await dictAxios.query({ type: 'home_tabs', is_use: '0' });
- if (res.errcode == '0') typeList.value = res.data;
- };
- // 修改是否启用
- const handleChange = (row: any) => {
- const text = row.is_use === '0' ? '启用' : '停用';
- ElMessageBox.confirm('确认要"' + text + '""' + row.title + '"吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- let res: IQueryResult;
- if (row._id) res = await articleAxios.update(row);
- if (res.errcode == 0) {
- ElMessage({ type: `success`, message: `修改成功` });
- }
- })
- .catch(() => {
- row.is_use = row.is_use === '0' ? '1' : '0';
- });
- };
- </script>
- <style scoped lang="scss">
- .main {
- .two {
- margin: 0 0 10px 0;
- }
- }
- </style>
|