From 0d9fb68a04311c53f4254348e15f33a22bc023b3 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期三, 16 六月 2021 19:40:59 +0800
Subject: [PATCH] update 更新 自定义主键案例
---
ruoyi-ui/src/views/system/dept/index.vue | 624 ++++++++++++++++++++++++++++---------------------------
1 files changed, 317 insertions(+), 307 deletions(-)
diff --git a/ruoyi-ui/src/views/system/dept/index.vue b/ruoyi-ui/src/views/system/dept/index.vue
index c5bb197..b10653e 100644
--- a/ruoyi-ui/src/views/system/dept/index.vue
+++ b/ruoyi-ui/src/views/system/dept/index.vue
@@ -1,307 +1,317 @@
-<template>
- <div class="app-container">
- <el-form :inline="true">
- <el-form-item label="閮ㄩ棬鍚嶇О">
- <el-input
- v-model="queryParams.deptName"
- placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�"
- clearable
- size="small"
- @keyup.enter.native="handleQuery"
- />
- </el-form-item>
- <el-form-item label="鐘舵��">
- <el-select v-model="queryParams.status" placeholder="閮ㄩ棬鐘舵��" clearable size="small">
- <el-option
- v-for="dict in statusOptions"
- :key="dict.dictValue"
- :label="dict.dictLabel"
- :value="dict.dictValue"
- />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button
- class="filter-item"
- type="primary"
- icon="el-icon-search"
- size="mini"
- @click="handleQuery"
- >鎼滅储</el-button>
- <el-button
- class="filter-item"
- type="primary"
- icon="el-icon-plus"
- size="mini"
- @click="handleAdd"
- v-hasPermi="['system:dept:add']"
- >鏂板</el-button>
- </el-form-item>
- </el-form>
-
- <el-table
- v-loading="loading"
- :data="deptList"
- row-key="deptId"
- default-expand-all
- :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
- >
- <el-table-column prop="deptName" label="閮ㄩ棬鍚嶇О" width="200"></el-table-column>
- <el-table-column prop="orderNum" label="鎺掑簭" width="200"></el-table-column>
- <el-table-column prop="status" label="鐘舵��" :formatter="statusFormat" width="100"></el-table-column>
- <el-table-column label="鍒涘缓鏃堕棿" align="center" prop="createTime" width="200">
- <template slot-scope="scope">
- <span>{{ dateFormat(scope.row.createTime) }}</span>
- </template>
- </el-table-column>
- <el-table-column label="鎿嶄綔" align="center" class-name="small-padding fixed-width">
- <template slot-scope="scope">
- <el-button
- size="mini"
- type="text"
- icon="el-icon-edit"
- @click="handleUpdate(scope.row)"
- v-hasPermi="['system:dept:edit']"
- >淇敼</el-button>
- <el-button
- size="mini"
- type="text"
- icon="el-icon-plus"
- @click="handleAdd(scope.row)"
- v-hasPermi="['system:dept:add']"
- >鏂板</el-button>
- <el-button
- v-if="scope.row.parentId != 0"
- size="mini"
- type="text"
- icon="el-icon-delete"
- @click="handleDelete(scope.row)"
- v-hasPermi="['system:dept:remove']"
- >鍒犻櫎</el-button>
- </template>
- </el-table-column>
- </el-table>
-
- <!-- 娣诲姞鎴栦慨鏀归儴闂ㄥ璇濇 -->
- <el-dialog :title="title" :visible.sync="open" width="600px">
- <el-form ref="form" :model="form" :rules="rules" label-width="80px">
- <el-row>
- <el-col :span="24" v-if="form.parentId !== 0">
- <el-form-item label="涓婄骇閮ㄩ棬" prop="parentId">
- <treeselect v-model="form.parentId" :options="deptOptions" placeholder="閫夋嫨涓婄骇閮ㄩ棬" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="閮ㄩ棬鍚嶇О" prop="deptName">
- <el-input v-model="form.deptName" placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="鏄剧ず鎺掑簭" prop="orderNum">
- <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="璐熻矗浜�" prop="leader">
- <el-input v-model="form.leader" placeholder="璇疯緭鍏ヨ礋璐d汉" maxlength="20" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="鑱旂郴鐢佃瘽" prop="phone">
- <el-input v-model="form.phone" placeholder="璇疯緭鍏ヨ仈绯荤數璇�" maxlength="11" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="閭" prop="email">
- <el-input v-model="form.email" placeholder="璇疯緭鍏ラ偖绠�" maxlength="50" />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="閮ㄩ棬鐘舵��">
- <el-radio-group v-model="form.status">
- <el-radio
- v-for="dict in statusOptions"
- :key="dict.dictValue"
- :label="dict.dictValue"
- >{{dict.dictLabel}}</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" @click="submitForm">纭� 瀹�</el-button>
- <el-button @click="cancel">鍙� 娑�</el-button>
- </div>
- </el-dialog>
- </div>
-</template>
-
-<script>
-import { listDept, getDept, treeselect, delDept, addDept, updateDept } from "@/api/system/dept";
-import Treeselect from "@riophae/vue-treeselect";
-import "@riophae/vue-treeselect/dist/vue-treeselect.css";
-
-export default {
- components: { Treeselect },
- data() {
- return {
- // 閬僵灞�
- loading: true,
- // 琛ㄦ牸鏍戞暟鎹�
- deptList: [],
- // 閮ㄩ棬閮ㄩ棬鏍戦�夐」
- deptOptions: undefined,
- // 寮瑰嚭灞傛爣棰�
- title: "",
- // 鏄惁鏄剧ず寮瑰嚭灞�
- open: false,
- // 鐘舵�佹暟鎹瓧鍏�
- statusOptions: [],
- // 鏌ヨ鍙傛暟
- queryParams: {
- deptName: undefined,
- status: undefined
- },
- // 琛ㄥ崟鍙傛暟
- form: {},
- // 琛ㄥ崟鏍¢獙
- rules: {
- parentId: [
- { required: true, message: "涓婄骇閮ㄩ棬涓嶈兘涓虹┖", trigger: "blur" }
- ],
- deptName: [
- { required: true, message: "閮ㄩ棬鍚嶇О涓嶈兘涓虹┖", trigger: "blur" }
- ],
- orderNum: [
- { required: true, message: "鑿滃崟椤哄簭涓嶈兘涓虹┖", trigger: "blur" }
- ],
- email: [
- {
- type: "email",
- message: "'璇疯緭鍏ユ纭殑閭鍦板潃",
- trigger: ["blur", "change"]
- }
- ],
- phone: [
- {
- pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
- message: "璇疯緭鍏ユ纭殑鎵嬫満鍙风爜",
- trigger: "blur"
- }
- ]
- }
- };
- },
- created() {
- this.getList();
- this.getDicts("sys_normal_disable").then(response => {
- this.statusOptions = response.data;
- });
- },
- methods: {
- /** 鏌ヨ閮ㄩ棬鍒楄〃 */
- getList() {
- this.loading = true;
- listDept(this.queryParams).then(response => {
- this.deptList = response.data;
- this.loading = false;
- });
- },
- /** 鏌ヨ閮ㄩ棬涓嬫媺鏍戠粨鏋� */
- getTreeselect() {
- treeselect().then(response => {
- this.deptOptions = response.data;
- });
- },
- // 瀛楀吀鐘舵�佸瓧鍏哥炕璇�
- statusFormat(row, column) {
- return this.selectDictLabel(this.statusOptions, row.status);
- },
- // 鍙栨秷鎸夐挳
- cancel() {
- this.open = false;
- this.reset();
- },
- // 琛ㄥ崟閲嶇疆
- reset() {
- this.form = {
- deptId: undefined,
- parentId: 100,
- deptName: undefined,
- orderNum: undefined,
- leader: undefined,
- phone: undefined,
- email: undefined,
- status: "0"
- };
- this.resetForm("form");
- },
- /** 鎼滅储鎸夐挳鎿嶄綔 */
- handleQuery() {
- this.getList();
- },
- /** 鏂板鎸夐挳鎿嶄綔 */
- handleAdd(row) {
- this.reset();
- this.getTreeselect();
- if (row != undefined) {
- this.form.parentId = row.deptId;
- }
- this.open = true;
- this.title = "娣诲姞閮ㄩ棬";
- },
- /** 淇敼鎸夐挳鎿嶄綔 */
- handleUpdate(row) {
- this.reset();
- this.getTreeselect();
- getDept(row.deptId).then(response => {
- this.form = response.data;
- this.open = true;
- this.title = "淇敼閮ㄩ棬";
- });
- },
- /** 鎻愪氦鎸夐挳 */
- submitForm: function() {
- this.$refs["form"].validate(valid => {
- if (valid) {
- if (this.form.deptId != undefined) {
- updateDept(this.form).then(response => {
- if (response.code === 200) {
- this.msgSuccess("淇敼鎴愬姛");
- this.open = false;
- this.getList();
- } else {
- this.msgError(response.msg);
- }
- });
- } else {
- addDept(this.form).then(response => {
- if (response.code === 200) {
- this.msgSuccess("鏂板鎴愬姛");
- this.open = false;
- this.getList();
- } else {
- this.msgError(response.msg);
- }
- });
- }
- }
- });
- },
- /** 鍒犻櫎鎸夐挳鎿嶄綔 */
- handleDelete(row) {
- this.$confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.deptName + '"鐨勬暟鎹」?', "璀﹀憡", {
- confirmButtonText: "纭畾",
- cancelButtonText: "鍙栨秷",
- type: "warning"
- }).then(function() {
- return delDept(row.deptId);
- }).then(() => {
- this.getList();
- this.msgSuccess("鍒犻櫎鎴愬姛");
- }).catch(function() {});
- }
- }
-};
-</script>
\ No newline at end of file
+<template>
+ <div class="app-container">
+ <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
+ <el-form-item label="閮ㄩ棬鍚嶇О" prop="deptName">
+ <el-input
+ v-model="queryParams.deptName"
+ placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�"
+ clearable
+ size="small"
+ @keyup.enter.native="handleQuery"
+ />
+ </el-form-item>
+ <el-form-item label="鐘舵��" prop="status">
+ <el-select v-model="queryParams.status" placeholder="閮ㄩ棬鐘舵��" clearable size="small">
+ <el-option
+ v-for="dict in statusOptions"
+ :key="dict.dictValue"
+ :label="dict.dictLabel"
+ :value="dict.dictValue"
+ />
+ </el-select>
+ </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"
+ v-hasPermi="['system:dept:add']"
+ >鏂板</el-button>
+ </el-col>
+ <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+ </el-row>
+
+ <el-table
+ v-loading="loading"
+ :data="deptList"
+ row-key="deptId"
+ default-expand-all
+ :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
+ >
+ <el-table-column prop="deptName" label="閮ㄩ棬鍚嶇О" width="260"></el-table-column>
+ <el-table-column prop="orderNum" label="鎺掑簭" width="200"></el-table-column>
+ <el-table-column prop="status" label="鐘舵��" :formatter="statusFormat" width="100"></el-table-column>
+ <el-table-column label="鍒涘缓鏃堕棿" align="center" prop="createTime" width="200">
+ <template slot-scope="scope">
+ <span>{{ parseTime(scope.row.createTime) }}</span>
+ </template>
+ </el-table-column>
+ <el-table-column label="鎿嶄綔" align="center" class-name="small-padding fixed-width">
+ <template slot-scope="scope">
+ <el-button
+ size="mini"
+ type="text"
+ icon="el-icon-edit"
+ @click="handleUpdate(scope.row)"
+ v-hasPermi="['system:dept:edit']"
+ >淇敼</el-button>
+ <el-button
+ size="mini"
+ type="text"
+ icon="el-icon-plus"
+ @click="handleAdd(scope.row)"
+ v-hasPermi="['system:dept:add']"
+ >鏂板</el-button>
+ <el-button
+ v-if="scope.row.parentId != 0"
+ size="mini"
+ type="text"
+ icon="el-icon-delete"
+ @click="handleDelete(scope.row)"
+ v-hasPermi="['system:dept:remove']"
+ >鍒犻櫎</el-button>
+ </template>
+ </el-table-column>
+ </el-table>
+
+ <!-- 娣诲姞鎴栦慨鏀归儴闂ㄥ璇濇 -->
+ <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
+ <el-form ref="form" :model="form" :rules="rules" label-width="80px">
+ <el-row>
+ <el-col :span="24" v-if="form.parentId !== 0">
+ <el-form-item label="涓婄骇閮ㄩ棬" prop="parentId">
+ <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="閫夋嫨涓婄骇閮ㄩ棬" />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="閮ㄩ棬鍚嶇О" prop="deptName">
+ <el-input v-model="form.deptName" placeholder="璇疯緭鍏ラ儴闂ㄥ悕绉�" />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="鏄剧ず鎺掑簭" prop="orderNum">
+ <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="璐熻矗浜�" prop="leader">
+ <el-input v-model="form.leader" placeholder="璇疯緭鍏ヨ礋璐d汉" maxlength="20" />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="鑱旂郴鐢佃瘽" prop="phone">
+ <el-input v-model="form.phone" placeholder="璇疯緭鍏ヨ仈绯荤數璇�" maxlength="11" />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="閭" prop="email">
+ <el-input v-model="form.email" placeholder="璇疯緭鍏ラ偖绠�" maxlength="50" />
+ </el-form-item>
+ </el-col>
+ <el-col :span="12">
+ <el-form-item label="閮ㄩ棬鐘舵��">
+ <el-radio-group v-model="form.status">
+ <el-radio
+ v-for="dict in statusOptions"
+ :key="dict.dictValue"
+ :label="dict.dictValue"
+ >{{dict.dictLabel}}</el-radio>
+ </el-radio-group>
+ </el-form-item>
+ </el-col>
+ </el-row>
+ </el-form>
+ <div slot="footer" class="dialog-footer">
+ <el-button type="primary" @click="submitForm">纭� 瀹�</el-button>
+ <el-button @click="cancel">鍙� 娑�</el-button>
+ </div>
+ </el-dialog>
+ </div>
+</template>
+
+<script>
+import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";
+import Treeselect from "@riophae/vue-treeselect";
+import "@riophae/vue-treeselect/dist/vue-treeselect.css";
+
+export default {
+ name: "Dept",
+ components: { Treeselect },
+ data() {
+ return {
+ // 閬僵灞�
+ loading: true,
+ // 鏄剧ず鎼滅储鏉′欢
+ showSearch: true,
+ // 琛ㄦ牸鏍戞暟鎹�
+ deptList: [],
+ // 閮ㄩ棬鏍戦�夐」
+ deptOptions: [],
+ // 寮瑰嚭灞傛爣棰�
+ title: "",
+ // 鏄惁鏄剧ず寮瑰嚭灞�
+ open: false,
+ // 鐘舵�佹暟鎹瓧鍏�
+ statusOptions: [],
+ // 鏌ヨ鍙傛暟
+ queryParams: {
+ deptName: undefined,
+ status: undefined
+ },
+ // 琛ㄥ崟鍙傛暟
+ form: {},
+ // 琛ㄥ崟鏍¢獙
+ rules: {
+ parentId: [
+ { required: true, message: "涓婄骇閮ㄩ棬涓嶈兘涓虹┖", trigger: "blur" }
+ ],
+ deptName: [
+ { required: true, message: "閮ㄩ棬鍚嶇О涓嶈兘涓虹┖", trigger: "blur" }
+ ],
+ orderNum: [
+ { required: true, message: "鏄剧ず鎺掑簭涓嶈兘涓虹┖", trigger: "blur" }
+ ],
+ email: [
+ {
+ type: "email",
+ message: "'璇疯緭鍏ユ纭殑閭鍦板潃",
+ trigger: ["blur", "change"]
+ }
+ ],
+ phone: [
+ {
+ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
+ message: "璇疯緭鍏ユ纭殑鎵嬫満鍙风爜",
+ trigger: "blur"
+ }
+ ]
+ }
+ };
+ },
+ created() {
+ this.getList();
+ this.getDicts("sys_normal_disable").then(response => {
+ this.statusOptions = response.data;
+ });
+ },
+ methods: {
+ /** 鏌ヨ閮ㄩ棬鍒楄〃 */
+ getList() {
+ this.loading = true;
+ listDept(this.queryParams).then(response => {
+ this.deptList = this.handleTree(response.data, "deptId");
+ this.loading = false;
+ });
+ },
+ /** 杞崲閮ㄩ棬鏁版嵁缁撴瀯 */
+ normalizer(node) {
+ if (node.children && !node.children.length) {
+ delete node.children;
+ }
+ return {
+ id: node.deptId,
+ label: node.deptName,
+ children: node.children
+ };
+ },
+ // 瀛楀吀鐘舵�佸瓧鍏哥炕璇�
+ statusFormat(row, column) {
+ return this.selectDictLabel(this.statusOptions, row.status);
+ },
+ // 鍙栨秷鎸夐挳
+ cancel() {
+ this.open = false;
+ this.reset();
+ },
+ // 琛ㄥ崟閲嶇疆
+ reset() {
+ this.form = {
+ deptId: undefined,
+ parentId: undefined,
+ deptName: undefined,
+ orderNum: undefined,
+ leader: undefined,
+ phone: undefined,
+ email: undefined,
+ status: "0"
+ };
+ this.resetForm("form");
+ },
+ /** 鎼滅储鎸夐挳鎿嶄綔 */
+ handleQuery() {
+ this.getList();
+ },
+ /** 閲嶇疆鎸夐挳鎿嶄綔 */
+ resetQuery() {
+ this.resetForm("queryForm");
+ this.handleQuery();
+ },
+ /** 鏂板鎸夐挳鎿嶄綔 */
+ handleAdd(row) {
+ this.reset();
+ if (row != undefined) {
+ this.form.parentId = row.deptId;
+ }
+ this.open = true;
+ this.title = "娣诲姞閮ㄩ棬";
+ listDept().then(response => {
+ this.deptOptions = this.handleTree(response.data, "deptId");
+ });
+ },
+ /** 淇敼鎸夐挳鎿嶄綔 */
+ handleUpdate(row) {
+ this.reset();
+ getDept(row.deptId).then(response => {
+ this.form = response.data;
+ this.open = true;
+ this.title = "淇敼閮ㄩ棬";
+ });
+ listDeptExcludeChild(row.deptId).then(response => {
+ this.deptOptions = this.handleTree(response.data, "deptId");
+ });
+ },
+ /** 鎻愪氦鎸夐挳 */
+ submitForm: function() {
+ this.$refs["form"].validate(valid => {
+ if (valid) {
+ if (this.form.deptId != undefined) {
+ updateDept(this.form).then(response => {
+ this.msgSuccess("淇敼鎴愬姛");
+ this.open = false;
+ this.getList();
+ });
+ } else {
+ addDept(this.form).then(response => {
+ this.msgSuccess("鏂板鎴愬姛");
+ this.open = false;
+ this.getList();
+ });
+ }
+ }
+ });
+ },
+ /** 鍒犻櫎鎸夐挳鎿嶄綔 */
+ handleDelete(row) {
+ this.$confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.deptName + '"鐨勬暟鎹」?', "璀﹀憡", {
+ confirmButtonText: "纭畾",
+ cancelButtonText: "鍙栨秷",
+ type: "warning"
+ }).then(function() {
+ return delDept(row.deptId);
+ }).then(() => {
+ this.getList();
+ this.msgSuccess("鍒犻櫎鎴愬姛");
+ }).catch(() => {});
+ }
+ }
+};
+</script>
--
Gitblit v1.9.3