wangting
2025-01-02 e358d69fc18870584dd2d9f531910b7838ea27d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
  <!--文仓管理页面-->
  <basic-container>
    <avue-crud
      ref="crud"
      v-model="form"
      :data="tableData"
      :option="option"
      :table-loading="tableLoading"
      @on-load="getTableList"
      @row-save="rowSaveHandler"
      @row-update="rowUpdateHandler"
      @row-del="rowDeleteHandler"
      @row-click="rowClickHandler"
      @selection-change="selectionChange"
    >
      <template slot="menuLeft" slot-scope="scope">
        <el-button v-if="permissionList.exportBtn" icon="el-icon-download" plain size="small" type="primary" @click="exportClickHandler">导出</el-button>
      </template>
      <!--<template #menu="{row,index,size}">
        <el-button icon="el-icon-user" type="text" size="small" @click="userHandler(row,index)">分配成员</el-button>
      </template>-->
    </avue-crud>
    <!-- 分配成员穿梭框   -->
    <transfer ref="transfer" :left-role-data="leftRoleData" :right-role-data="rightRoleData"
              :transferTitle="transferTitle" title="文件柜添加成员"
              @transferSend="roleSendHandler">
    </transfer>
  </basic-container>
</template>
 
<script>
import {exportPvolumes, getPvolumesPage,savePvolume,updatePvolume,deletePvolume} from "@/api/system/fileCab/api";
import func from "@/util/func";
import basicOption from "@/util/basic-option";
import {listUserByRoleOid, listUserUnInRoleOid, saveRight} from "@/api/system/role/api";
import {mapGetters} from "vuex";
 
export default {
  name: "index",
  data: function () {
    return {
      form:{},
      tableLoading: false,
      tableData: [],
      currentRow:null,
      leftRoleData: [],  // 分配成员穿梭框左侧初始数据
      rightRoleData: [], // 分配成员穿梭框右侧初始数据
      transferTitle: ['文件柜外成员', '文件柜内成员'],
      selectionList: [],
    }
  },
  computed: {
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission[this.$route.query.id].ADD, false),
        delBtn: this.vaildData(this.permission[this.$route.query.id].DELETE, false),
        editBtn: this.vaildData(this.permission[this.$route.query.id].EDIT, false),
        exportBtn: this.vaildData(this.permission[this.$route.query.id].EXPORT, false),
      };
    },
    option(){
      return  {
        ...basicOption,
        addBtn:this.permissionList.addBtn,
        editBtn:this.permissionList.editBtn,
        delBtn:this.permissionList.delBtn,
        calcHeight: -60,
        align:'left',
        headerAlign:'center',
        menuWidth:160,
        dialogMenuPosition: 'right',
        dialogWidth:600,
        column: [
          {
            label: '卷名',
            prop: 'name',
            width: 200,
            span: 24,
            rules: [{ required: true, message: '请输入卷名', trigger: 'blur' }]
          },{
            label: '服务器',
            prop: 'host',
            span: 24,
            rules: [{ required: true, message: '请输入服务器', trigger: 'blur' }]
          },{
            label: '卷服务',
            prop: 'service',
            span: 24,
            rules: [{ required: true, message: '请输入卷服务', trigger: 'blur' }]
          }, {
            label: '机器类型',
            prop: 'type',
            width: 120,
            span: 24,
            type:'radio',
            dicData:[{
              label:'Unix',
              value:0
            },{
              label:'Win NT',
              value:1
            }],
            value:1
          },{
            label: '路径名称',
            prop: 'path',
            span: 24,
            overHidden: true,
            rules: [{ required: true, message: '请输入路径名称', trigger: 'blur' }]
          },{
            label: '首选路径',
            prop: 'isvalid',
            width: 120,
            span: 24,
            type: 'switch',
            value:false,
            beforeChange: (done) => {debugger;
              this.$confirm('您确实要修改卷的首选路径吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                done(true);
              }).catch(() => {
                done(false);
              });
            },
          }]
      }
    }
  },
  methods: {
    // 表格请求
    getTableList() {
      this.tableLoading = true;
      getPvolumesPage().then(res => {
        this.tableData = res.data.data;
        this.tableLoading = false;
      })
    },
 
    // 新增
    rowSaveHandler(row, done, loading) {
      savePvolume(row).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.obj);
          this.getTableList();
          done();
        }
      }).catch(err => {
        loading()
      });
    },
 
    // 编辑
    rowUpdateHandler(row, index, done, loading) {
      updatePvolume(row).then(res => {
        if (res.data.code === 200) {
          this.$message.success(res.data.obj);
          this.getTableList();
          done()
        }
      }).catch(err => {
        loading()
      });
    },
 
    // 删除
    rowDeleteHandler(row) {
      let params = {
        ids: row.id
      }
 
      this.$confirm('您确定要删除当前的卷节点吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletePvolume(params).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.obj);
            this.getTableList();
          }
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 导出
    exportClickHandler() {
      if (this.ids == null || this.ids == "") {
        this.$message({
          type: 'warning',
          message: '请勾选要导出的数据!'
        });
        return;
      }
      const loading = this.$loading({});
      exportPvolumes({"pvolumeIds": this.ids}).then(res => {
        func.downloadFileByBlobHandler(res);
        this.createdLoading = false
        this.$message.success('导出成功');
        loading.close();
      })
    },
 
    //分配成员
    userHandler(row, index) {
      this.currentRow = row;
      Promise.all([
        listUserUnInRoleOid({pkRole: row.id}),
        listUserByRoleOid({pkRole: row.id})
      ]).then(([unInRoleRes, byRoleRes]) => {
        if (unInRoleRes.data.code === 200 && byRoleRes.data.code === 200) {
          const leftData = [...unInRoleRes.data.data, ...byRoleRes.data.data];
          // 组装好穿梭框可用数据
          this.leftRoleData = leftData.map(item => {
            return {
              name: item.name + `(${item.id})`,
              oid: item.oid
            }
          })
          this.rightRoleData = byRoleRes.data.data.map(item => item.oid);
          this.$refs.transfer.visible = true;
        }
      });
    },
    // 分配成员穿梭框回填
    roleSendHandler(row) {
      let params = {
        userOids: row.join(','),
        roleId: this.currentRow.id
      }
      saveRight(params).then(res => {
        this.$message.success(res.data.obj);
        this.getTableList();
      })
    },
    //选择的行
    selectionChange(list) {
      this.selectionList = list;
    },
 
    // 行单选
    rowClickHandler(row) {
      func.rowClickHandler(
        row,
        this.$refs.crud,
        this.lastIndex,
        (newIndex) => {
          this.lastIndex = newIndex;
        },
        () => {
          this.selectionList = [row];
        }
      );
    },
  }
}
</script>
 
<style scoped>
 
</style>