From e2c4ca4922acaeb01fdc79369f2c1618951ecd85 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Sun, 23 Aug 2020 10:51:46 +0800
Subject: [PATCH] 终端授权类型改为复选框

---
 ruoyi-ui/src/views/system/client/index.vue |   24 +++++++++++++++++++++---
 sql/ry_20200823.sql                        |    6 ++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/ruoyi-ui/src/views/system/client/index.vue b/ruoyi-ui/src/views/system/client/index.vue
index e78870e..fea107f 100644
--- a/ruoyi-ui/src/views/system/client/index.vue
+++ b/ruoyi-ui/src/views/system/client/index.vue
@@ -54,7 +54,7 @@
       <el-table-column label="编号" align="center" prop="clientId" />
       <el-table-column label="安全码" align="center" prop="originSecret" :show-overflow-tooltip="true" />
       <el-table-column label="授权范围" align="center" prop="scope" />
-      <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :show-overflow-tooltip="true" />
+      <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :formatter="authorizedGrantTypesFormat" :show-overflow-tooltip="true"/>
       <el-table-column label="令牌时效" align="center" prop="accessTokenValidity" />
       <el-table-column label="刷新时效" align="center" prop="refreshTokenValidity" />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@@ -98,7 +98,14 @@
           <el-input v-model="form.scope" placeholder="请输入授权范围" />
         </el-form-item>
         <el-form-item label="授权类型" prop="authorizedGrantTypes">
-          <el-input v-model="form.authorizedGrantTypes" placeholder="请输入授权类型" />
+          <el-checkbox-group v-model="form.authorizedGrantTypes">
+            <el-checkbox
+              v-for="dict in authorizedGrantTypesOptions"
+              :key="dict.dictValue"
+              :label="dict.dictValue">
+              {{dict.dictLabel}}
+            </el-checkbox>
+          </el-checkbox-group>
         </el-form-item>
         <el-form-item label="令牌时效" prop="accessTokenValidity">
           <el-input-number v-model="form.accessTokenValidity" controls-position="right" :min="0" />
@@ -140,6 +147,8 @@
       title: "",
       // 是否显示弹出层
       open: false,
+      // 终端授权类型字典
+      authorizedGrantTypesOptions: [],
       // 查询参数
       queryParams: {
         pageNum: 1,
@@ -169,6 +178,9 @@
   },
   created() {
     this.getList();
+    this.getDicts("sys_grant_type").then(response => {
+      this.authorizedGrantTypesOptions = response.data;
+    });
   },
   methods: {
     /** 查询终端列表 */
@@ -179,6 +191,10 @@
         this.total = response.total;
         this.loading = false;
       });
+    },
+    // 终端授权类型字典翻译
+    authorizedGrantTypesFormat(row, column) {
+      return this.selectDictLabels(this.authorizedGrantTypesOptions, row.authorizedGrantTypes);
     },
     // 取消按钮
     cancel() {
@@ -191,7 +207,7 @@
         clientId: undefined,
         clientSecret: undefined,
         scope: "server",
-        authorizedGrantTypes: "password,refresh_token",
+        authorizedGrantTypes: [],
         accessTokenValidity: 3600,
         refreshTokenValidity: 7200
       };
@@ -227,6 +243,7 @@
       const clientId = row.clientId || this.ids;
       getClient(clientId).then(response => {
         this.form = response.data;
+        this.form.authorizedGrantTypes = this.form.authorizedGrantTypes.split(",");
         this.open = true;
         this.title = "修改终端";
       });
@@ -235,6 +252,7 @@
     submitForm: function() {
       this.$refs["form"].validate(valid => {
         if (valid) {
+          this.form.authorizedGrantTypes = this.form.authorizedGrantTypes.join(",");
           if (!this.isAdd && this.form.clientId != undefined) {
             updateClient(this.form).then(response => {
               if (response.code === 200) {
diff --git a/sql/ry_20200822.sql b/sql/ry_20200823.sql
similarity index 97%
rename from sql/ry_20200822.sql
rename to sql/ry_20200823.sql
index 5a5b170..2e7acd7 100644
--- a/sql/ry_20200822.sql
+++ b/sql/ry_20200823.sql
@@ -461,6 +461,7 @@
 insert into sys_dict_type values(8,  '通知状态', 'sys_notice_status',   '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '通知状态列表');
 insert into sys_dict_type values(9,  '操作类型', 'sys_oper_type',       '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '操作类型列表');
 insert into sys_dict_type values(10, '系统状态', 'sys_common_status',   '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '登录状态列表');
+insert into sys_dict_type values(11, '授权类型', 'sys_grant_type',      '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '授权类型列表');
 
 
 -- ----------------------------
@@ -514,6 +515,11 @@
 insert into sys_dict_data values(26, 9,  '清空数据', '9',       'sys_oper_type',       '',   'danger',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '清空操作');
 insert into sys_dict_data values(27, 1,  '成功',     '0',       'sys_common_status',   '',   'primary', 'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '正常状态');
 insert into sys_dict_data values(28, 2,  '失败',     '1',       'sys_common_status',   '',   'danger',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '停用状态');
+insert into sys_dict_data values(29, 1,  '授权码模式',  'authorization_code',  'sys_grant_type',   '',   '',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '授权码模式');
+insert into sys_dict_data values(30, 2,  '密码模式',    'password',            'sys_grant_type',   '',   '',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '密码模式');
+insert into sys_dict_data values(31, 3,  '客户端模式',  'client_credentials',  'sys_grant_type',   '',   '',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '客户端模式');
+insert into sys_dict_data values(32, 4,  '简化模式',    'implicit',            'sys_grant_type',   '',   '',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '简化模式');
+insert into sys_dict_data values(33, 5,  '刷新模式',    'refresh_token',       'sys_grant_type',   '',   '',  'N', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '刷新模式');
 
 
 -- ----------------------------

--
Gitblit v1.9.3