Michael Wang 4 лет назад
Родитель
Сommit
11aaaadc6c

+ 6 - 3
src/modules/basic/view/data_previllege.vue

@@ -355,9 +355,12 @@ export default {
       return this.$refs[type + "Table"].selection.length;
     },
     selectChange() {
-      this.noBatchSelectedExam = !this.$refs.tableExam.selection.length;
-      this.noBatchSelectedCourse = !this.$refs.tableCourse.selection.length;
-      this.noBatchSelectedOrg = !this.$refs.tableOrg.selection.length;
+      this.noBatchSelectedExam =
+        this.$refs.tableExam && !this.$refs.tableExam.selection.length;
+      this.noBatchSelectedCourse =
+        this.$refs.tableCourse && !this.$refs.tableCourse.selection.length;
+      this.noBatchSelectedOrg =
+        this.$refs.tableOrg && !this.$refs.tableOrg.selection.length;
     },
     handleSizeChangeExam(val) {
       this.pageSizeExam = val;

+ 5 - 5
src/modules/basic/view/data_previllege_add_course.vue

@@ -164,14 +164,14 @@ export default {
         return;
       }
 
-      this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
-        refIds,
-        type: "COURSE",
-        userId: this.userId
-      });
       try {
         this.loading = true;
         // await saveActivity(data);
+        await this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
+          refIds,
+          type: "COURSE",
+          userId: this.userId
+        });
         this.$emit("reload");
         this.$notify({ title: "保存成功", type: "success" });
         this.closeDialog();

+ 5 - 5
src/modules/basic/view/data_previllege_add_exam.vue

@@ -164,14 +164,14 @@ export default {
         return;
       }
 
-      this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
-        refIds,
-        type: "EXAM",
-        userId: this.userId
-      });
       try {
         this.loading = true;
         // await saveActivity(data);
+        await this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
+          refIds,
+          type: "EXAM",
+          userId: this.userId
+        });
         this.$emit("reload");
         this.$notify({ title: "保存成功", type: "success" });
         this.closeDialog();

+ 5 - 5
src/modules/basic/view/data_previllege_add_org.vue

@@ -166,14 +166,14 @@ export default {
         return;
       }
 
-      this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
-        refIds,
-        type: "ORG",
-        userId: this.userId
-      });
       try {
         this.loading = true;
         // await saveActivity(data);
+        await this.$httpWithMsg.post(CORE_API + "/user/data/rule/add", {
+          refIds,
+          type: "ORG",
+          userId: this.userId
+        });
         this.$emit("reload");
         this.$notify({ title: "保存成功", type: "success" });
         this.closeDialog();

+ 28 - 1
src/modules/basic/view/user.vue

@@ -89,6 +89,15 @@
             >
               新增
             </el-button>
+
+            <el-button
+              size="small"
+              type="primary"
+              icon="el-icon-plus"
+              @click="copyPrevillegeDialog"
+            >
+              权限复制
+            </el-button>
           </el-form-item>
         </el-form>
 
@@ -374,6 +383,7 @@
 
         <!-- 页面列表 -->
         <el-table
+          ref="table"
           :data="tableData"
           border
           resizable
@@ -512,15 +522,23 @@
         </div>
       </div>
     </div>
+
+    <UserCopyPrevillegeDialog
+      ref="copyPrevillegeDialog"
+      :sourceUser="selectedUserToCopy"
+      @reload="init"
+    />
   </section>
 </template>
 
 <script>
 import { CORE_API } from "@/constants/constants.js";
 import { mapState } from "vuex";
+import UserCopyPrevillegeDialog from "./user_copy_previllege_dialog";
 
 export default {
   name: "User",
+  components: { UserCopyPrevillegeDialog },
   data() {
     var validateRootOrg = (rule, value, callback) => {
       if (0 != value && !value) {
@@ -569,6 +587,7 @@ export default {
       tempOrgList: [],
       userId: "",
       selectedUserIds: [],
+      selectedUserToCopy: null,
       tableData: [],
       currentPage: 1,
       pageSize: 10,
@@ -815,7 +834,6 @@ export default {
       row.forEach(element => {
         this.selectedUserIds.push(element.id);
       });
-      console.log(this.selectedUserIds);
     },
     //新增
     openAddingDialog() {
@@ -1097,6 +1115,15 @@ export default {
       }
 
       return true;
+    },
+    copyPrevillegeDialog() {
+      const refIds = this.$refs.table.selection;
+      if (refIds.length === 0 || refIds > 1) {
+        this.$notify({ type: "warning", message: "请先选择一行" });
+        return;
+      }
+      this.selectedUserToCopy = refIds[0];
+      this.$refs.copyPrevillegeDialog.openDialog();
     }
   },
   //初始化查询

+ 210 - 0
src/modules/basic/view/user_copy_previllege_dialog.vue

@@ -0,0 +1,210 @@
+<template>
+  <el-dialog
+    ref="dialog"
+    title="数据权限复制"
+    width="700px"
+    :visible.sync="visible"
+    @close="closeDialog"
+    v-if="sourceUser"
+  >
+    <div>
+      <div>
+        <span>从数据源:</span> <span>{{ sourceUser.name }}</span>
+      </div>
+      <div>
+        <span>复制到:</span>
+        <el-tag v-for="user in targetUsers" :key="user.name" class="mr-1">
+          {{ user.name }}
+        </el-tag>
+      </div>
+    </div>
+    <el-form
+      :model="form"
+      ref="form"
+      :rules="rules"
+      :inline="true"
+      label-position="right"
+      label-width="80px"
+    >
+      <el-row>
+        <div class="float-right">
+          <el-form-item label="姓名">
+            <el-input
+              placeholder="请输入姓名"
+              v-model="form.name"
+              class="input_width"
+            />
+          </el-form-item>
+          <el-form-item>
+            <el-button
+              size="small"
+              type="primary"
+              icon="el-icon-search"
+              @click="search"
+            >
+              查询
+            </el-button>
+          </el-form-item>
+        </div>
+      </el-row>
+
+      <el-row>
+        <div>
+          <el-table
+            ref="table"
+            :data="tableData"
+            border
+            resizable
+            stripe
+            style="width: 100%;"
+            @selection-change="selectChange"
+          >
+            <el-table-column type="selection" width="40" />
+            <el-table-column width="85" label="用户ID">
+              <span slot-scope="scope">{{ scope.row.id }}</span>
+            </el-table-column>
+            <el-table-column width="200" label="姓名">
+              <span slot-scope="scope">{{ scope.row.name }}</span>
+            </el-table-column>
+            <el-table-column label="登录名">
+              <span slot-scope="scope">{{ scope.row.loginName }}</span>
+            </el-table-column>
+            <el-table-column width="120" label="角色">
+              <span
+                slot-scope="scope"
+                v-html="scope.row.roleNamesStr.replace(/,/g, '<br />')"
+              >
+              </span>
+            </el-table-column>
+          </el-table>
+          <div class="page pull-right">
+            <el-pagination
+              v-if="paginationShow"
+              @current-change="handleCurrentChange"
+              :current-page="currentPage"
+              :page-size="pageSize"
+              :page-sizes="[10, 20, 50, 100, 200, 300]"
+              @size-change="handleSizeChange"
+              layout="total, sizes, prev, pager, next, jumper"
+              :total="total"
+            />
+          </div>
+        </div>
+        <div style="margin-bottom: 20px"></div>
+      </el-row>
+
+      <el-row class="d-flex justify-content-center mt-2">
+        <el-button type="primary" @click="submitForm" :loading="loading"
+          >确 定</el-button
+        >
+        <el-button @click="closeDialog">取 消</el-button>
+      </el-row>
+    </el-form>
+  </el-dialog>
+</template>
+
+<script>
+import { CORE_API } from "@/constants/constants";
+export default {
+  name: "UserCopyPrevillegeDialog",
+  props: {
+    sourceUser: Object
+  },
+  data() {
+    return {
+      visible: false,
+      form: {
+        name: ""
+      },
+      rules: {},
+      targetUsers: [],
+      loading: false,
+      paginationShow: false,
+      tableData: [],
+      noBatchSelected: true,
+      currentPage: 1,
+      pageSize: 10,
+      total: 10
+    };
+  },
+  methods: {
+    async search() {
+      var param = new URLSearchParams(this.form);
+      var url =
+        CORE_API +
+        "/user/all/" +
+        this.currentPage +
+        "/" +
+        this.pageSize +
+        "?" +
+        param;
+      this.loading = true;
+      return this.$httpWithMsg.get(url).then(response => {
+        this.tableData = response.data.list;
+        this.total = response.data.total;
+        this.loading = false;
+        this.paginationShow = true;
+      });
+    },
+    async openDialog() {
+      this.visible = true;
+      try {
+        await this.search();
+      } catch (error) {
+        console.log(error);
+        this.$notify({ type: "error", title: "获取用户列表失败" });
+      }
+    },
+    closeDialog() {
+      this.visible = false;
+    },
+    handleSizeChange(val) {
+      this.pageSize = val;
+      this.currentPage = 1;
+      this.search();
+    },
+    selectChange(row) {
+      this.targetUsers = row;
+      // row.forEach(element => {
+      //   this.selectedUserIds.push(element.id);
+      // });
+      // console.log(this.selectedUserIds);
+    },
+    handleCurrentChange(val) {
+      this.currentPage = val;
+      this.search();
+    },
+    async submitForm() {
+      try {
+        await this.$refs.form.validate();
+      } catch (error) {
+        console.log("校验失败", error);
+        return;
+      }
+
+      const refIds = this.$refs.table.selection.map(v => v.id);
+      console.log(refIds);
+      if (refIds.length === 0) {
+        this.$notify({ type: "warning", message: "请先选择一行或多行" });
+        return;
+      }
+
+      try {
+        this.loading = true;
+        // await saveActivity(data);
+        await this.$httpWithMsg.post(CORE_API + "/user/data/rule/copy", {
+          sourceUserId: this.sourceUser.id,
+          targetUserIds: refIds
+        });
+        this.$emit("reload");
+        this.$notify({ title: "保存成功", type: "success" });
+        this.closeDialog();
+      } finally {
+        this.loading = false;
+      }
+    }
+  }
+};
+</script>
+
+<style></style>