|
@@ -2,40 +2,195 @@
|
|
|
<div id="index">
|
|
|
<el-row>
|
|
|
<el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
|
|
|
- <el-col :span="24" class="one"> 系统首页 </el-col>
|
|
|
+ <el-col :span="24" class="one">
|
|
|
+ <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch"> </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" @edit="toEdit" @del="toDel">
|
|
|
+ <template #type="{ item, row }">
|
|
|
+ <template v-if="item.model === 'type'">
|
|
|
+ <el-link size="small" type="primary" @click="toType(row)">{{ getProps(row, item.model) }}</el-link>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ <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="rules" @save="onSubmit">
|
|
|
+ <template #is_use>
|
|
|
+ <el-radio v-for="(i, index) in is_useList" :key="index" :label="i.value">{{ i.label }}</el-radio>
|
|
|
+ </template>
|
|
|
+ </cForm>
|
|
|
+ </el-col>
|
|
|
+ </template>
|
|
|
+ </cDialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
-
|
|
|
-<script setup lang="ts">
|
|
|
+<script lang="ts" setup>
|
|
|
// 基础
|
|
|
+import _ from 'lodash';
|
|
|
+import type { FormRules } from 'element-plus';
|
|
|
import type { Ref } from 'vue';
|
|
|
-import { onMounted, ref } from 'vue';
|
|
|
+import { ref, onMounted, getCurrentInstance, reactive } from 'vue';
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
+import { useRouter } from 'vue-router';
|
|
|
|
|
|
// 接口
|
|
|
-// import { ToolsStore } from '@/stores/tool';
|
|
|
-// import type { IQueryResult } from '@/util/types.util';
|
|
|
-// const toolsAxios = ToolsStore();
|
|
|
-
|
|
|
+import { DictDataStore } from '@/stores/basic/dictData'; //
|
|
|
+import { DictTypeStore } from '@/stores/basic/dictType'; //
|
|
|
+import type { IQueryResult } from '@/util/types.util';
|
|
|
+const dictType = DictTypeStore();
|
|
|
+const dictData = DictDataStore();
|
|
|
+// 路由
|
|
|
+const router = useRouter();
|
|
|
+const { proxy } = getCurrentInstance() as any;
|
|
|
// 加载中
|
|
|
-const loading: Ref<any> = ref(false);
|
|
|
-
|
|
|
-// 请求
|
|
|
+const loading = 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: 'title', isSearch: true },
|
|
|
+ { label: '字典类型', model: 'type', custom: true },
|
|
|
+ { label: '是否启用', model: 'is_use', custom: true },
|
|
|
+ { label: '备注', model: 'remark' }
|
|
|
+]);
|
|
|
+// 操作
|
|
|
+let opera: Ref<any[]> = ref([
|
|
|
+ { label: '修改', method: 'edit' },
|
|
|
+ { label: '删除', method: 'del', confirm: true, type: 'danger' }
|
|
|
+]);
|
|
|
+// 弹框
|
|
|
+const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' });
|
|
|
+let form: Ref<{}> = ref({});
|
|
|
+// 表单
|
|
|
+let formFields: Ref<any[]> = ref([
|
|
|
+ { label: '字典名称', model: 'title' },
|
|
|
+ { label: '字典类型', model: 'type' },
|
|
|
+ { label: '是否启用', model: 'is_use', type: 'radio' },
|
|
|
+ { label: '备注', model: 'remark', type: 'textarea' }
|
|
|
+]);
|
|
|
+const rules = reactive<FormRules>({
|
|
|
+ name: [{ required: true, message: '字典名称', trigger: 'blur' }],
|
|
|
+ type: [{ required: true, message: '字典类型', trigger: 'blur' }]
|
|
|
+});
|
|
|
+// 查询数据
|
|
|
+let searchForm: Ref<any> = ref({});
|
|
|
+// 字典表
|
|
|
+let is_useList: Ref<any> = ref([]);
|
|
|
onMounted(async () => {
|
|
|
loading.value = true;
|
|
|
- search();
|
|
|
+ await searchOther();
|
|
|
+ await search({ skip, limit });
|
|
|
loading.value = false;
|
|
|
});
|
|
|
-const search = async () => {
|
|
|
- // let res: IQueryResult = await toolsAxios.dataCount();
|
|
|
- // if (res.errcode == '0') {
|
|
|
- // info.value = res.data;
|
|
|
- // }
|
|
|
+// 查询
|
|
|
+const search = async (e: { skip: number; limit: number }) => {
|
|
|
+ const { skip, limit } = e;
|
|
|
+ const condition = _.cloneDeep(searchForm.value);
|
|
|
+ let info = { limit: limit, skip: skip, ...condition };
|
|
|
+ let res: IQueryResult = await dictType.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 getProps = (data: any, prop: any) => {
|
|
|
+ return _.get(data, prop);
|
|
|
+};
|
|
|
+// 修改是否启用
|
|
|
+const handleChange = (row: any) => {
|
|
|
+ const text = row.is_use === '0' ? '启用' : '停用';
|
|
|
+ ElMessageBox.confirm('确认要"' + text + '""' + row.type + '"吗?', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ .then(async () => {
|
|
|
+ let res: IQueryResult;
|
|
|
+ if (row._id) res = await dictType.update(row);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `修改成功` });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ row.is_use = row.is_use === '0' ? '1' : '0';
|
|
|
+ });
|
|
|
+};
|
|
|
+// 新增
|
|
|
+const toAdd = () => {
|
|
|
+ dialog.value = { title: '信息管理', show: true, type: '1' };
|
|
|
+};
|
|
|
+// 修改
|
|
|
+const toEdit = async (data: any) => {
|
|
|
+ let res: IQueryResult = await dictType.fetch(data._id);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ form.value = res.data as {};
|
|
|
+ dialog.value = { title: '信息管理', show: true, type: '1' };
|
|
|
+ }
|
|
|
+};
|
|
|
+// 提交
|
|
|
+const onSubmit = async (data: any) => {
|
|
|
+ let res: IQueryResult;
|
|
|
+ if (data._id) res = await dictType.update(data);
|
|
|
+ else res = await dictType.create(data);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `维护信息成功` });
|
|
|
+ toClose();
|
|
|
+ }
|
|
|
+};
|
|
|
+// 删除
|
|
|
+const toDel = async (data: any) => {
|
|
|
+ let res: IQueryResult = await dictType.del(data._id);
|
|
|
+ if (res.errcode == 0) {
|
|
|
+ ElMessage({ type: `success`, message: `刪除信息成功` });
|
|
|
+ search({ skip, limit });
|
|
|
+ }
|
|
|
+};
|
|
|
+// 弹框关闭
|
|
|
+const toClose = () => {
|
|
|
+ form.value = {};
|
|
|
+ searchForm.value = {};
|
|
|
+ dialog.value = { title: '信息管理', show: false, type: '1' };
|
|
|
+ search({ skip, limit });
|
|
|
+};
|
|
|
+// 字典类型跳转
|
|
|
+const toType = (data: any) => {
|
|
|
+ router.push({ path: '/system/dictData', query: { id: data._id, type: data.type } });
|
|
|
+};
|
|
|
+// 查询其他信息
|
|
|
+const searchOther = async () => {
|
|
|
+ let res: IQueryResult = await dictData.query({ type: 'is_use' });
|
|
|
+ if (res.errcode == 0) is_useList.value = res.data;
|
|
|
};
|
|
|
</script>
|
|
|
-<style scoped lang="scss">
|
|
|
+<style lang="scss" scoped>
|
|
|
.main {
|
|
|
- padding: 2px;
|
|
|
+ .two {
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|