feat:完成城市管理增刪改查功能
This commit is contained in:
44
ruoyi-ui/src/api/system/city.js
Normal file
44
ruoyi-ui/src/api/system/city.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询城市列表
|
||||
export function listCity(query) {
|
||||
return request({
|
||||
url: '/oa/city/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询城市详细
|
||||
export function getCity(cityId) {
|
||||
return request({
|
||||
url: `/oa/city/${cityId}`,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增城市
|
||||
export function addCity(data) {
|
||||
return request({
|
||||
url: '/oa/city',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改城市
|
||||
export function updateCity(data) {
|
||||
return request({
|
||||
url: '/oa/city',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除城市
|
||||
export function delCity(cityIds) {
|
||||
return request({
|
||||
url: `/oa/city/${cityIds}`,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
@@ -9,6 +9,20 @@ import Layout from "@/layout";
|
||||
|
||||
// 公共路由
|
||||
export const constantRoutes = [
|
||||
{
|
||||
path: "/oa/city",
|
||||
component: Layout,
|
||||
hidden: false,
|
||||
meta: { title: "城市管理", icon: "dashboard" },
|
||||
children: [
|
||||
{
|
||||
path: "index",
|
||||
component: () => import("@/views/oa/city/index"),
|
||||
name: "City",
|
||||
meta: { title: "城市管理", icon: "el-icon-office-building" }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/redirect",
|
||||
component: Layout,
|
||||
@@ -182,6 +196,7 @@ export const constantRoutes = [
|
||||
];
|
||||
|
||||
export const dynamicRoutes = [
|
||||
|
||||
{
|
||||
path: "/system/user-auth",
|
||||
component: Layout,
|
||||
@@ -314,6 +329,7 @@ export const dynamicRoutes = [
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
let routerPush = Router.prototype.push;
|
||||
|
||||
169
ruoyi-ui/src/views/oa/city/index.vue
Normal file
169
ruoyi-ui/src/views/oa/city/index.vue
Normal file
@@ -0,0 +1,169 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
|
||||
<el-form-item label="城市名称" prop="cityName">
|
||||
<el-input
|
||||
v-model="queryParams.cityName"
|
||||
placeholder="请输入城市名称"
|
||||
clearable
|
||||
style="width: 200px"
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="cityList" @selection-change="handleSelectionChange" border stripe>
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="序号" type="index" width="50" align="center" />
|
||||
<el-table-column prop="cityCode" label="城市编码" align="center" width="150" />
|
||||
<el-table-column prop="cityName" label="城市名称" align="center" width="200" />
|
||||
<el-table-column prop="provinceName" label="所属省份" align="center" width="150" />
|
||||
<el-table-column label="操作" align="center" width="150">
|
||||
<template slot-scope="scope">
|
||||
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
|
||||
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="城市编码" prop="cityCode">
|
||||
<el-input v-model="form.cityCode" placeholder="请输入城市编码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="城市名称" prop="cityName">
|
||||
<el-input v-model="form.cityName" placeholder="请输入城市名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属省份" prop="provinceName">
|
||||
<el-input v-model="form.provinceName" placeholder="请输入所属省份" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listCity, getCity, delCity, addCity, updateCity } from "@/api/system/city";
|
||||
import Pagination from "@/components/Pagination";
|
||||
|
||||
export default {
|
||||
name: "City",
|
||||
components: { Pagination },
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
cityList: [],
|
||||
total: 0,
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
cityName: null
|
||||
},
|
||||
ids: [],
|
||||
multiple: true,
|
||||
title: "",
|
||||
open: false,
|
||||
form: {},
|
||||
rules: {
|
||||
cityCode: [{ required: true, message: "城市编码不能为空", trigger: "blur" }],
|
||||
cityName: [{ required: true, message: "城市名称不能为空", trigger: "blur" }]
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listCity(this.queryParams).then(response => {
|
||||
this.cityList = response.rows || [];
|
||||
this.total = response.total || 0;
|
||||
this.loading = false;
|
||||
}).catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getList();
|
||||
},
|
||||
resetQuery() {
|
||||
this.queryParams = { pageNum: 1, pageSize: 10, cityName: null };
|
||||
this.getList();
|
||||
},
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.cityId);
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
handleAdd() {
|
||||
this.form = {};
|
||||
this.open = true;
|
||||
this.title = "添加城市";
|
||||
},
|
||||
handleUpdate(row) {
|
||||
getCity(row.cityId).then(response => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = "修改城市";
|
||||
});
|
||||
},
|
||||
submitForm() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.cityId) {
|
||||
updateCity(this.form).then(() => {
|
||||
this.$message.success("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
addCity(this.form).then(() => {
|
||||
this.$message.success("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
handleDelete(row) {
|
||||
const cityIds = row.cityId || this.ids.join(",");
|
||||
this.$confirm("确认删除选中的城市吗?", "提示", { type: "warning" }).then(() => {
|
||||
delCity(cityIds).then(() => {
|
||||
this.$message.success("删除成功");
|
||||
this.getList();
|
||||
});
|
||||
});
|
||||
},
|
||||
cancel() {
|
||||
this.open = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user