quanyawei
2024-06-18 cb0882e7c2194c398bb998c16e86a84c1b616cb0
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<template>
  <div>
    <a-card :bordered="false"  style="margin-top: 24px">
      <div class="tableList">
        <div class="tableListForm">
          <a-form  layout="horizontal">
            <!-- gutter间隔属性 md>768 lg>992 xl>1200  目前宽度是891 ,是form的宽度-->
            <a-row :gutter="{ md: 8, lg: 24, xl: 48 }">
 
              <a-col :md="8" :sm="24">
                <!-- v-bind="searchFormLayout"绑定的是form表单布局 -->
                <a-form-item label="用户名" fieldDecoratorId="name" v-bind="searchFormLayout">
                  <a-input placeholder="请输入用户名" v-model="searchInform.userinform" />
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="电话" fieldDecoratorId="phone" v-bind="searchFormLayout">
                  <a-input placeholder="请输入电话" v-model="searchInform.mobileinform" />
                </a-form-item>
              </a-col>
 
              <a-col :md="8" :sm="24" v-if="!expandForm">
                <span class="submitButtons">
                  <a-button type="primary" @click="this.handleSearch">查询</a-button>
                  <a-button style="margin-left: 8px" @click="this.handleFormReset">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div class="tableListOperator">
          <a-button icon="plus" type="primary" @click="() => this.handleModalVisible(true)">新建</a-button>
 
 
        </div>
        <av-standard-table
          :dataSource="dataSource"
          :columns="columns"
          :paginationProps="pagination"
          :selectedRows="selectedRows"
          :loading="tableLoading"
          @tableChange="handlerTableChange"
          @selectChange="handlerSelectChange"
        ></av-standard-table>
      </div>
    </a-card>
 
    <a-modal
      title="新建-账户"
      destroyOnClose
      :visible="visibleCreateModal"
      @ok="handleCreateModalOk"
      @cancel="handleCreateModalCancel"
      okText="保存"
    >
      <a-form style="margin-top: 8px" :autoFormCreate="(form)=>{this.createForm = form}">
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="帐号"
          fieldDecoratorId="account"
          :fieldDecoratorOptions="{rules: [{ required: true, pattern:/^[A-Za-z][a-zA-z0-9]*$/ ,message: '请输入账号,英文字母开头!', min: 2 }]}"
        >
          <a-input placeholder="请输入帐号,英文字母开头" />
        </a-form-item>
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="密码"
          fieldDecoratorId="password"
          :fieldDecoratorOptions="{rules: [{ required: true,pattern:/^[A-Za-z0-9]+$/, message: '请输入密码,只能输入数字或字母!', min: 3 }]}"
        >
          <a-input placeholder="请输入密码" />
        </a-form-item>
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="用户名"
          fieldDecoratorId="userName"
          :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入用户名!'},{  message: '用户名字数不能超过20个!',max: 19}]}"
        >
          <a-input placeholder="请输入用户名" />
        </a-form-item>
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="电话"
          fieldDecoratorId="mobile"
        >
          <a-input placeholder="请输入电话" />
        </a-form-item>
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="电子邮件"
          fieldDecoratorId="email"
        >
          <a-input placeholder="请输入电子邮件" />
        </a-form-item>
 
<!--        <a-form-item-->
<!--          :labelCol="{ span: 5 }"-->
<!--          :wrapperCol="{ span: 15 }"-->
<!--          label="分配角色"-->
<!--          fieldDecoratorId="assignRoles"-->
<!--        >-->
 
<!--          <a-select-->
<!--              placeholder="请为账户分配角色"-->
<!--              allow-clear-->
<!--              show-search-->
<!--          >-->
<!--            <a-select-option v-for="(item,index) in this.searchrole" :key="item.id">{{item.name}}</a-select-option>-->
<!--          </a-select>-->
 
 
<!--        </a-form-item>-->
      </a-form>
    </a-modal>
 
    <update-task-form
      :visible.sync="updateTaskFormVisible"
      :record="updateRecord"
      @updateData="loadRuleData"
    ></update-task-form>
    <change-password
      :visible.sync="changePasswordVisible"
      :record="changeRecord"
      @updateData="loadRuleData"
    ></change-password>
    <distrib-role
      @updateData="loadRuleData"
      :visible.sync="distribRoleVisible"
      :record="distribRoleRecord"
    ></distrib-role>
  </div>
</template>
 
<script lang="tsx">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { State, Mutation, namespace } from "vuex-class";
import { get, post } from "@/util/request";
 
// import moment from "moment";
import axios from "axios";
 
import { Observable, Subscription, BehaviorSubject } from "rxjs";
 
import UpdateTaskForm from "../list/components/UpdateTaskFormUser.vue";
import ChangePassword from '../list/components/ChangePassword.vue'
import DistribRole from '../list/components/DistribRole.vue'
 
import modalService from "../../core/ModalService";
import { Encrypt, Decrypt} from '../../util/AES.js'
 
@Component({
  components: {
    UpdateTaskForm,
    ChangePassword,
    DistribRole
  }
})
//QueryList继承Vue类
export default class QueryList extends Vue {
  private searchFormLayout: any = {
    labelCol: {
      span: 5
    },
    wrapperCol: {
      span: 18,
      offset: 1
    }
  };
 
  private expandForm: boolean = false;
 
  private selectedRowKeys: any[] = [];
 
  private selectedRows: any[] = [];
 
  private tableLoading: boolean = false;
 
  private dataSource: any[] = [];
  private dataSourceMiddle:any=[];
  private pagination:any={
   total:0,
   current:1,
   pageSize:5,
   showSizeChanger: false,
   showQuickJumper: false,
  };
 
  private searchInform: any = {
    userinform: null,
    mobileinform: null
  };
 
  private visibleCreateModal: boolean = false;
  private updateTaskFormVisible: boolean = false;
  private changePasswordVisible:boolean=false;
  private distribRoleVisible:boolean=false;
  private createForm: any = null;
  private roles:any=null;
  private updateRecord: any = {};
  private changeRecord:any={};
  private distribRoleRecord:any={}
 
  private columns: any[] = [
    {
     title:'账号',
     dataIndex:'account'
    },
    {
      title: "用户名",
      dataIndex: "userName"
    },
    {
      title: "电话",
      dataIndex: "mobile"
    },
    {
      title: "电子邮件",
      dataIndex: "email"
 
    },
    {
      title: "角色",
      dataIndex: "name"
 
    },
    {
      title: "创建日期",
      dataIndex: "createTime"
 
    },
    {
      title: "操作",
      customRender: this.opRender
    }
  ];
 
 
 
  //新建 button 弹窗事件 请求角色列表
  private handleModalVisible(isVisible: boolean): void {
    this.visibleCreateModal = isVisible;
    axios.get('manageRole/getAllManageRole?current=1&size=100',{}).then(res=>{
      this.searchrole=res.data.data.manageRoles
    })
  }
 
private searchrole :any=null;
  private toggleForm(): void {
    this.expandForm = !this.expandForm;
  }
 
  private handleFormReset(): void {
     this.searchInform.userinform=null;
     this.searchInform.mobileinform=null;
  }
 
private searchData(pageSize: any):void{
  if (
      this.searchInform.userinform ||
      this.searchInform.mobileinform
    ) {
      get("account/query", {
        page: pageSize,
        size: 5,
        orderType:1,
        order:'updateTime',
        userName:this.searchInform.userinform,
        mobile:this.searchInform.mobileinform
        }).then(res => {
            this.pagination.total=res.data.data.total;
            this.pagination.current=res.data.data.current;
            this.pagination.pageSize=res.data.data.size
            this.dataSource=[]
          this.dataSource = res.data.data.accountVOs;
          this.tableLoading  = false;
        })
        .catch(err => {
          console.log(err);
        });
    }
}
  //查询,网络请求,一页显示多少条
  private handleSearch(): void {
   this.searchData(1)
  }
  @Watch('searchInform.userinform')
  private watchsearchInform(newVal:string,oldval:string){
    if(!newVal&&!this.searchInform.mobileinform){
     this.loadRuleData()
    }
  }
  //监听写法,下面的方法,和上面连在一起
  @Watch('searchInform.mobileinform')
  private watchmobileinform(newVal:string,oldval:string){
     if(!newVal&&!this.searchInform.userinform){
     this.loadRuleData()
    }
  }
  // 切换页码触发 分两块,一种是有查询的 ,一种是没查询的
  private handlerTableChange(pagination: any, filter: any, sorter: any): void {
 if (
      this.searchInform.userinform  ||
      this.searchInform.mobileinform
    ) {
      this. searchData(pagination.current)
    }else{
     get("account/query", {
          page: pagination.current,
          size: 5,
          orderType:1,
          order:'updateTime'
      }).then(res => {
       let dataSource=res.data.data.accountVOs;
        this.pagination.total=res.data.data.total;
            this.pagination.current=res.data.data.current;
            this.pagination.pageSize=res.data.data.size
         for(let i=0;i<dataSource.length;i++){
            let rolesInform= dataSource[i].roles;
            if(rolesInform){
              let role='';
             for(let j=0;j<rolesInform.length;j++){
              //  只有一个角色,后面不要、 2个以上最后一位去掉
               role+= rolesInform[j].name+'、'
            }
            if(role.charAt(role.length-1)=='、'){
              role=role.slice(0,role.length-1)
            }
             dataSource[i].name=role
        }
     }
        this.dataSource=dataSource
         this.dataSourceMiddle=dataSource
        this.tableLoading = false;
      })
      .catch(err => {
        console.log(err);
      });
 
    }
  }
 
  private handleUpdateModalVisible(visible: boolean, record: any): void {
    this.updateTaskFormVisible = true;
    this.updateRecord = record;
  }
  //新建账户
  private handleCreateModalOk() {
    this.createForm.validateFields((err: any, fieldsValue: any) => {
      if (err) {
        return;
      }
      const account=this.createForm.getFieldValue("account")
      let password=this.createForm.getFieldValue("password")
      const userName=this.createForm.getFieldValue("userName")
      const mobile=this.createForm.getFieldValue('mobile')?this.createForm.getFieldValue('mobile'):null
      const email=this.createForm.getFieldValue('email')?this.createForm.getFieldValue('email'):null
 
      //密码加密传入
     password= Encrypt(password);
      //插入数据库47.99.64.149
     if(account!=""){
       post("account/insert",{
           account:account,
           password:password,
           userName:userName,
           email:email,
           mobile:mobile
       }).then(res=>{
         if(res.data.code!=0){
           this.$message.error(res.data.message)
         }else{
           this.$message.success(res.data.message)
        this.visibleCreateModal = false;
         //新建完后,重新调接口刷新数据,刚创建,显示最上面
        this.loadRuleData();
         }
       }).catch(err=>{
         console.log(err)
       })
     }
    });
  }
 
  private handleUpdateOk() {
    this.loadRuleData();
  }
 
  private handleCreateModalCancel(): any {
    this.visibleCreateModal = false;
  }
 
  private handlerSelectChange(arr1: any, arr2: any) {
    this.selectedRows = arr2;
  }
 
  private handleMenuClick(e: any) {}
 
  private mounted() {
    this.loadRuleData();
  }
 
  private popupScroll(){}
 //初始加载账号信息
  private loadRuleData() {
    this.tableLoading = true;
    get("account/query", {
          page: 1,
          size: 5,
          orderType:1,
          order:'updateTime'
      }).then(res => {
        this.pagination.total=res.data.data.total;
        this.pagination.current=res.data.data.current;
        this.pagination.pageSize=res.data.data.size;
        let dataSource=res.data.data.accountVOs;
 
        for(let i=0;i<dataSource.length;i++){
        let rolesInform= dataSource[i].roles;
        if(rolesInform){
          let role='';
          for(let j=0;j<rolesInform.length;j++){
            //  只有一个角色,后面不要、 2个以上最后一位去掉
            role+= rolesInform[j].name+'、'
          }
          if(role.charAt(role.length-1)=='、'){
            role=role.slice(0,role.length-1)
          }
          dataSource[i].name=role
        }
     }
        this.dataSource=dataSource
        this.dataSourceMiddle=dataSource
        this.tableLoading = false;
      })
      .catch(err => {
        console.log(err);
      });
  }
 
 
 
 
 //删除 ,确认网络请求
 private popconfirm(record:any):void{
      post("account/delete",{
            accountId:record.id,
       }).then(res=>{
        if (res.data.code === 0) {
          this.$message.success(res.data.message)
          //删除刷新数据
          this.loadRuleData()
        } else {
          this.$message.warning(res.data.message)
        }
       }).catch(err=>{
         console.log(err)
       })
 }
//点击更多选项
private handleMenuItemClick(e:any,visible:boolean,record:any):void{
   //判断e.key=1 修改密码
   if(e.key==1){
 this.changePasswordVisible=true
  this.changeRecord=record
   }
   else{
     this.distribRoleVisible=true;
     this.distribRoleRecord=record
   }
}
 
  private opRender(text: string, record: any, index: number) {
    return (
      <div>
        <a onClick={() => this.handleUpdateModalVisible(true, record)}>
        编辑
        </a>
         <a-divider type="vertical" />
          <a-popconfirm  onConfirm={()=>this.popconfirm(record)}  title="确定要删除该数据吗?" ok-text="确定" cancel-text="取消" >
         <a >
        删除
        </a>
       </a-popconfirm>
        <a-divider type="vertical" />
        <a-dropdown>
      <a-menu slot="overlay" onClick={(e: any)=>this.handleMenuItemClick(e,true,record)}>
        <a-menu-item key="1"> <a-icon type="unlock" />修改密码</a-menu-item>
        <a-menu-item key="2"> <a-icon type="user" />分配角色 </a-menu-item>
      </a-menu>
        <a >更多<a-icon type="down" /></a>
      // <a-button > 更多 <a-icon type="down" /> </a-button>
       </a-dropdown>
      </div>
    );
  }
}
</script>
 
<style lang="less">
.tableList {
  .tableListOperator {
    margin-bottom: 16px;
    button {
      margin-right: 8px;
    }
  }
}
</style>