houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3     title="API授权"
4     :close-on-click-modal="false"
5     :visible.sync="visible">
6     <el-tree
7       :data="treeData"
8       :props="defaultProps"
9       node-key="id"
10       ref="apiListTree"
11       show-checkbox>
12     </el-tree>
13     <span slot="footer" class="dialog-footer">
14       <el-button @click="visible = false">取消</el-button>
15       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
16     </span>
17   </el-dialog>
18 </template>
19 <script>
20   export default {
21     data () {
22       return {
23         visible: false,
24         dataForm: {
25           id: '',
26           appName: '',
27           appKey: '',
28           appSecret: '',
29           appDesc: ''
30         },
31         apiAuthorizedIdList: [],
32         defaultProps: {
33           children: 'children',
34           label: 'label'
35         },
36         treeData: []
37       }
38     },
39     methods: {
40       init (id) {
41         this.dataForm.id = id || 0
42         this.visible = true
43         this.$nextTick(() => {
44           if (this.dataForm.id) {
45             this.$http({
46               url: `/data/api-gateway/info/group-tree`,
47               method: 'get',
48               params: this.$http.adornParams()
49             }).then(({data}) => {
50               if (data && data.code === 0) {
51                 this.treeData = data.data
52               }
53               this.$refs.apiListTree.setCheckedKeys([])
54             }).then(() => {
55               this.$http({
56                 url: `/data/api-gateway/app/info/${this.dataForm.id}`,
57                 method: 'get',
58                 params: this.$http.adornParams()
59               }).then(({data}) => {
60                 if (data && data.code === 0) {
61                   this.dataForm.appName = data.data.appName
62                   this.dataForm.appKey = data.data.appKey
63                   this.dataForm.appSecret = data.data.appSecret
64                   this.dataForm.appDesc = data.data.appDesc
65                   if (data.data.apiAuthorizedList && data.data.apiAuthorizedList.length > 0) {
66                     this.apiAuthorizedIdList = data.data.apiAuthorizedList.map(function (item) {
67                       return item.apiId
68                     })
69                     this.$refs.apiListTree.setCheckedKeys(this.apiAuthorizedIdList)
70                   }
71                 }
72               })
73             })
74           }
75         })
76       },
77       // 表单提交
78       dataFormSubmit () {
79         this.$http({
80           url: `/data/api-gateway/authorized/grant-api/${this.dataForm.id}`,
81           method: 'post',
82           data: this.$http.adornData([].concat(this.$refs.apiListTree.getCheckedKeys(), this.$refs.apiListTree.getHalfCheckedKeys()), false)
83         }).then(({data}) => {
84           if (data && data.code === 0) {
85             this.$message({
86               message: '操作成功',
87               type: 'success',
88               duration: 1500,
89               onClose: () => {
90                 this.visible = false
91                 this.$emit('refreshDataList')
92               }
93             })
94           } else {
95             this.$message.error(data.msg)
96           }
97         })
98       }
99     }
100   }
101 </script>