Commit d5cbea47cc572fb146f469d990c3f73cda39e31b

Authored by 张红振
1 parent 1970e0f3

add 项目维护

src/api/notify/maintain.ts 0 → 100644
  1 +import request from '../request'
  2 +
  3 +// 列表查询
  4 +export function getTableList(params:any) {
  5 + return request({
  6 + method: 'get',
  7 + url: '/maintain/listByOid',
  8 + params: params
  9 + })
  10 +}
  11 +// 删除
  12 +export function deleteMaintainById(params:any) {
  13 + return request({
  14 + method: 'DELETE',
  15 + url: '/maintain/deleteMaintainById',
  16 + params: params
  17 + })
  18 +}
  19 +// 新增
  20 +export function insertOrUpdate(params:any) {
  21 + return request({
  22 + method: 'POST',
  23 + url: '/maintain/insertOrUpdate',
  24 + data: params
  25 + })
  26 +}
... ...
src/router/index.ts
... ... @@ -10,6 +10,7 @@ import Community from "./modules/community"
10 10 import OwnerManagement from "./modules/ownerManagement"
11 11 import Housekeeper from "./modules/housekeeper"
12 12 import Serviceman from "./modules/serviceman"
  13 +import Maintain from "./modules/maintain"
13 14 import Layout from '@/layout/enter.vue'
14 15 const routes: Array<any> = [
15 16 {
... ... @@ -40,6 +41,7 @@ const routes: Array&lt;any&gt; = [
40 41 OwnerManagement,
41 42 Housekeeper,
42 43 Serviceman,
  44 + Maintain,
43 45 {
44 46 path: '/404',
45 47 name: 'Error',
... ...
src/router/modules/maintain.ts 0 → 100644
  1 +import Layout from '@/layout/enter.vue'
  2 +const Maintain = {
  3 + path: '/',
  4 + component: Layout,
  5 + name: 'maintain',
  6 + children: [{
  7 + path: 'maintain',
  8 + name: 'maintain',
  9 + component: () => import('@/views/maintain/index.vue'),
  10 + meta: { title: '项目维护' }
  11 + }
  12 + ]
  13 +}
  14 +
  15 +export default Maintain
... ...
src/views/maintain/detail.vue 0 → 100644
  1 +<script setup lang="ts">
  2 +import { reactive, ref, onMounted, getCurrentInstance } from "vue";
  3 +import type { ElForm } from "element-plus";
  4 +import { insertOrUpdate } from "@/api/notify/maintain.ts";
  5 +
  6 +const ruleFormRef = ref<InstanceType<typeof ElForm>>();
  7 +let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
  8 +// 声明props
  9 +const props = defineProps({
  10 + formObj: {
  11 + type: Object,
  12 + default: {
  13 + name: null,
  14 + status: null,
  15 + },
  16 + },
  17 +});
  18 +
  19 +let loading = ref(false);
  20 +
  21 +// 表单验证
  22 +const rules = reactive({
  23 + name: [
  24 + {
  25 + required: true,
  26 + message: "请输入项目名称",
  27 + trigger: "blur",
  28 + },
  29 + ],
  30 + status: [
  31 + {
  32 + required: true,
  33 + message: "请选择状态",
  34 + trigger: "blur",
  35 + },
  36 + ],
  37 +});
  38 +
  39 +const emit = defineEmits<{
  40 + (e: "cancel"): void;
  41 + (e: "success"): void;
  42 +}>();
  43 +
  44 +/**
  45 + * 表单提交
  46 + * @param {ElForm | undefined} formEl 表单对象
  47 + */
  48 +let submitForm = (formEl: InstanceType<typeof ElForm> | undefined) => {
  49 + loading.value = true;
  50 + if (!formEl) return;
  51 + formEl.validate((valid) => {
  52 + if (valid) {
  53 + insertOrUpdate(props.formObj)
  54 + .then((res) => {
  55 + loading.value = false;
  56 + emit("success");
  57 + })
  58 + .catch((err) => {
  59 + loading.value = false;
  60 + });
  61 + } else {
  62 + instance?.proxy?.$message.error("请完善信息"); //调用
  63 + loading.value = false;
  64 + return false;
  65 + }
  66 + });
  67 +};
  68 +
  69 +/**
  70 + * 取消提交
  71 + */
  72 +const cancel: void = () => {
  73 + emit("cancel");
  74 +};
  75 +</script>
  76 +
  77 +<template>
  78 + <el-form
  79 + ref="ruleFormRef"
  80 + :model="props.formObj"
  81 + :rules="rules"
  82 + label-width="100px"
  83 + >
  84 + <el-form-item label="项目名称:" prop="name">
  85 + <el-input
  86 + v-model="props.formObj.name"
  87 + placeholder="请输入名称"
  88 + maxlength="30"
  89 + ></el-input>
  90 + </el-form-item>
  91 + <el-form-item label="启用状态:" prop="status">
  92 + <el-radio-group v-model="props.formObj.status">
  93 + <el-radio :label="0">停用</el-radio>
  94 + <el-radio :label="1">启用</el-radio>
  95 + </el-radio-group>
  96 + </el-form-item>
  97 + <el-form-item>
  98 + <el-button
  99 + type="primary"
  100 + @click="submitForm(ruleFormRef)"
  101 + :loading="loading"
  102 + >保存</el-button
  103 + >
  104 + <el-button @click="cancel">取消</el-button>
  105 + </el-form-item>
  106 + </el-form>
  107 +</template>
... ...
src/views/maintain/index.vue 0 → 100644
  1 +<script setup lang="ts">
  2 +import { reactive, onMounted, getCurrentInstance } from "vue";
  3 +import { getTableList,deleteMaintainById } from "@/api/notify/maintain.ts";
  4 +import { parseTime } from "@/utils/tool.ts";
  5 +import Detail from "./detail.vue";
  6 +import Pagination from "@/components/Pagination/index.vue";
  7 +import * as store from "@/pinia/index";
  8 +
  9 +let instance: ComponentInternalInstance | null = getCurrentInstance(); //获取app实例
  10 +
  11 +// 数据筛选
  12 +const searchData = reactive({
  13 + name: null,
  14 + page: 1,
  15 + pageSize: 10,
  16 + oid:store?.family?.loginStore()?.organizationId??0
  17 +});
  18 +// 展示
  19 +const data = reactive({
  20 + total: 0,
  21 + time: [],
  22 + tableList: [],
  23 + dialogVisible: false,
  24 + loading: false,
  25 + title: "新增项目",
  26 + formObj: {},
  27 +});
  28 +
  29 +/**
  30 + * 列表查询
  31 + */
  32 +const search = (): void => {
  33 + data.loading = true;
  34 + searchData.startTime = data.time?.[0] ?? null;
  35 + searchData.endTime = data.time?.[1] ?? null;
  36 + getTableList(searchData)
  37 + .then((res) => {
  38 + data.tableList = res.data.data.list;
  39 + data.total = res.data.data.total;
  40 + searchData.pageSize = res.data.data.pageSize;
  41 + data.loading = false;
  42 + })
  43 + .catch((err) => {
  44 + console.log(err);
  45 + data.loading = false;
  46 + });
  47 +};
  48 +/**
  49 + * 编辑
  50 + * @param { Object } 列表对象
  51 + */
  52 +const edit = (row: Object) => {
  53 + data.title = "编辑项目";
  54 + data.formObj = JSON.parse(JSON.stringify(row));
  55 + data.dialogVisible = true;
  56 +};
  57 +/**
  58 + * 删除
  59 + * @param { number } id 唯一ID
  60 + */
  61 +const remove = (id: number) => {
  62 + instance?.proxy?.$messageBox
  63 + .confirm("确认要进行此操作?", "提示", {
  64 + confirmButtonText: "确定",
  65 + cancelButtonText: "取消",
  66 + })
  67 + .then(() => {
  68 + deleteMaintainById({ id: id }).then((res) => {
  69 + instance?.proxy?.$message.success("操作成功"); //调用
  70 + search();
  71 + });
  72 + })
  73 + .catch((err) => {});
  74 +};
  75 +/**
  76 + * 组件操作成功回调
  77 + */
  78 +const changeData: void = () => {
  79 + data.dialogVisible = false;
  80 + search();
  81 +};
  82 +
  83 +/**
  84 + * 弹框关闭
  85 + */
  86 +const dialogClose: void = () => {
  87 + data.title = "新增项目";
  88 + data.formObj = {};
  89 +};
  90 +onMounted(() => {
  91 + search();
  92 +});
  93 +</script>
  94 +<template>
  95 + <div class="app-container">
  96 + <!-- 搜索 -->
  97 + <el-form :inline="true" :model="searchData" v-loading="data.loading">
  98 + <el-form-item>
  99 + <el-input
  100 + placeholder="请输入项目名称"
  101 + v-model="searchData.name"
  102 + clearable
  103 + ></el-input>
  104 + </el-form-item>
  105 + <el-form-item>
  106 + <el-date-picker
  107 + v-model="data.time"
  108 + type="datetimerange"
  109 + range-separator="至"
  110 + start-placeholder="开始时间"
  111 + end-placeholder="结束时间"
  112 + value-format="YYYY-MM-DD hh:mm:ss"
  113 + >
  114 + </el-date-picker>
  115 + </el-form-item>
  116 +
  117 + <el-form-item
  118 + ><el-button type="primary" @click="search"
  119 + >查询</el-button
  120 + ></el-form-item
  121 + >
  122 + <el-row>
  123 + <el-form-item>
  124 + <el-button type="primary" @click="data.dialogVisible = true"
  125 + >新增</el-button
  126 + >
  127 + </el-form-item>
  128 + </el-row>
  129 + </el-form>
  130 +
  131 + <!-- 表格 -->
  132 + <el-table border :data="data.tableList">
  133 + <el-table-column label="项目名称" prop="name"></el-table-column>
  134 + <el-table-column label="添加时间" prop="createTime">
  135 + <template #default="scope">
  136 + <span>{{ parseTime(new Date(scope.row.createTime).getTime()) }}</span>
  137 + </template>
  138 + </el-table-column>
  139 + <el-table-column label="状态" prop="status">
  140 + <template #default="scope">
  141 + <span>{{ scope.row.status == 0 ? "停用" : "启用" }}</span>
  142 + </template>
  143 + </el-table-column>
  144 + <el-table-column label="操作">
  145 + <template #default="scope">
  146 + <el-button type="text" size="mini" @click="edit(scope.row)"
  147 + >编辑</el-button
  148 + >
  149 + <el-button type="text" size="mini" @click="remove(scope.row.id)"
  150 + >删除</el-button
  151 + >
  152 + </template>
  153 + </el-table-column>
  154 + </el-table>
  155 +
  156 + <!-- 分页 -->
  157 + <Pagination
  158 + v-if="data.total > 0"
  159 + :total="data.total"
  160 + v-model:currentPage="searchData.page"
  161 + v-model:pageSize="searchData.pageSize"
  162 + @pageChange="search"
  163 + ></Pagination>
  164 +
  165 + <!-- 详情弹框 -->
  166 + <el-dialog
  167 + v-model="data.dialogVisible"
  168 + :title="data.title"
  169 + width="30%"
  170 + @close="dialogClose"
  171 + >
  172 + <Detail
  173 + @cancel="data.dialogVisible = false"
  174 + @success="changeData"
  175 + :formObj="data.formObj"
  176 + ></Detail>
  177 + </el-dialog>
  178 + </div>
  179 +</template>
  180 +
  181 +<style></style>
... ...