index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" @submit.native.prevent>
  4. <el-form-item label="终端编号" prop="clientId">
  5. <el-input
  6. v-model="queryParams.clientId"
  7. placeholder="终端编号"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['system:client:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="success"
  31. icon="el-icon-edit"
  32. size="mini"
  33. :disabled="single"
  34. @click="handleUpdate"
  35. v-hasPermi="['system:client:edit']"
  36. >修改</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="danger"
  41. icon="el-icon-delete"
  42. size="mini"
  43. :disabled="multiple"
  44. @click="handleDelete"
  45. v-hasPermi="['system:client:remove']"
  46. >删除</el-button>
  47. </el-col>
  48. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  49. </el-row>
  50. <el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange">
  51. <el-table-column type="selection" width="55" align="center" />
  52. <el-table-column label="编号" align="center" prop="clientId" />
  53. <el-table-column label="安全码" align="center" prop="originSecret" :show-overflow-tooltip="true" />
  54. <el-table-column label="授权范围" align="center" prop="scope" />
  55. <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :formatter="authorizedGrantTypesFormat" :show-overflow-tooltip="true"/>
  56. <el-table-column label="令牌时效" align="center" prop="accessTokenValidity" />
  57. <el-table-column label="刷新时效" align="center" prop="refreshTokenValidity" />
  58. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  59. <template slot-scope="scope">
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-edit"
  64. @click="handleUpdate(scope.row)"
  65. v-hasPermi="['system:client:edit']"
  66. >修改</el-button>
  67. <el-button
  68. size="mini"
  69. type="text"
  70. icon="el-icon-delete"
  71. @click="handleDelete(scope.row)"
  72. v-hasPermi="['system:client:remove']"
  73. >删除</el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <pagination
  78. v-show="total>0"
  79. :total="total"
  80. :page.sync="queryParams.pageNum"
  81. :limit.sync="queryParams.pageSize"
  82. @pagination="getList"
  83. />
  84. <!-- 添加或修改终端对话框 -->
  85. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  86. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  87. <el-form-item label="编号" prop="clientId">
  88. <el-input v-model="form.clientId" placeholder="请输入编号" :disabled="!isAdd" />
  89. </el-form-item>
  90. <el-form-item label="安全码" prop="originSecret">
  91. <el-input v-model="form.originSecret" placeholder="请输入安全码" />
  92. </el-form-item>
  93. <el-form-item label="授权范围" prop="scope">
  94. <el-input v-model="form.scope" placeholder="请输入授权范围" />
  95. </el-form-item>
  96. <el-form-item label="授权类型" prop="authorizedGrantTypes">
  97. <el-checkbox-group v-model="form.authorizedGrantTypes">
  98. <el-checkbox
  99. v-for="dict in authorizedGrantTypesOptions"
  100. :key="dict.dictValue"
  101. :label="dict.dictValue">
  102. {{dict.dictLabel}}
  103. </el-checkbox>
  104. </el-checkbox-group>
  105. </el-form-item>
  106. <el-form-item label="令牌时效" prop="accessTokenValidity">
  107. <el-input-number v-model="form.accessTokenValidity" controls-position="right" :min="0" />
  108. </el-form-item>
  109. <el-form-item label="刷新时效" prop="refreshTokenValidity">
  110. <el-input-number v-model="form.refreshTokenValidity" controls-position="right" :min="0" />
  111. </el-form-item>
  112. </el-form>
  113. <div slot="footer" class="dialog-footer">
  114. <el-button type="primary" @click="submitForm">确 定</el-button>
  115. <el-button @click="cancel">取 消</el-button>
  116. </div>
  117. </el-dialog>
  118. </div>
  119. </template>
  120. <script>
  121. import { listClient, getClient, delClient, addClient, updateClient } from "@/api/system/client";
  122. export default {
  123. name: "Client",
  124. data() {
  125. return {
  126. // 遮罩层
  127. loading: true,
  128. // 选中数组
  129. ids: [],
  130. // 非单个禁用
  131. single: true,
  132. // 非多个禁用
  133. multiple: true,
  134. // 显示搜索条件
  135. showSearch: true,
  136. // 总条数
  137. total: 0,
  138. // 终端表格数据
  139. clientList: [],
  140. // 弹出层标题
  141. title: "",
  142. // 是否显示弹出层
  143. open: false,
  144. // 终端授权类型字典
  145. authorizedGrantTypesOptions: [],
  146. // 查询参数
  147. queryParams: {
  148. pageNum: 1,
  149. pageSize: 10,
  150. clientId: undefined
  151. },
  152. // 是否新增
  153. isAdd: false,
  154. // 表单参数
  155. form: {},
  156. // 表单校验
  157. rules: {
  158. clientId: [
  159. { required: true, message: "编号不能为空", trigger: "blur" }
  160. ],
  161. originSecret: [
  162. { required: true, message: "安全码不能为空", trigger: "blur" }
  163. ],
  164. scope: [
  165. { required: true, message: "授权范围不能为空", trigger: "blur" }
  166. ],
  167. authorizedGrantTypes: [
  168. { required: true, message: "授权类型不能为空", trigger: "blur" }
  169. ]
  170. }
  171. };
  172. },
  173. created() {
  174. this.getList();
  175. this.getDicts("sys_grant_type").then(response => {
  176. this.authorizedGrantTypesOptions = response.data;
  177. });
  178. },
  179. methods: {
  180. /** 查询终端列表 */
  181. getList() {
  182. this.loading = true;
  183. listClient(this.queryParams).then(response => {
  184. this.clientList = response.rows;
  185. this.total = response.total;
  186. this.loading = false;
  187. });
  188. },
  189. // 终端授权类型字典翻译
  190. authorizedGrantTypesFormat(row, column) {
  191. return this.selectDictLabels(this.authorizedGrantTypesOptions, row.authorizedGrantTypes);
  192. },
  193. // 取消按钮
  194. cancel() {
  195. this.open = false;
  196. this.reset();
  197. },
  198. // 表单重置
  199. reset() {
  200. this.form = {
  201. clientId: undefined,
  202. clientSecret: undefined,
  203. scope: "server",
  204. authorizedGrantTypes: [],
  205. accessTokenValidity: 3600,
  206. refreshTokenValidity: 7200
  207. };
  208. this.resetForm("form");
  209. },
  210. /** 搜索按钮操作 */
  211. handleQuery() {
  212. this.queryParams.pageNum = 1;
  213. this.getList();
  214. },
  215. /** 重置按钮操作 */
  216. resetQuery() {
  217. this.resetForm("queryForm");
  218. this.handleQuery();
  219. },
  220. // 多选框选中数据
  221. handleSelectionChange(selection) {
  222. this.ids = selection.map(item => item.clientId);
  223. this.single = selection.length != 1;
  224. this.multiple = !selection.length;
  225. },
  226. /** 新增按钮操作 */
  227. handleAdd() {
  228. this.reset();
  229. this.open = true;
  230. this.isAdd = true;
  231. this.title = "添加终端";
  232. },
  233. /** 修改按钮操作 */
  234. handleUpdate(row) {
  235. this.reset();
  236. this.isAdd = false;
  237. const clientId = row.clientId || this.ids;
  238. getClient(clientId).then(response => {
  239. this.form = response.data;
  240. this.form.authorizedGrantTypes = this.form.authorizedGrantTypes.split(",");
  241. this.open = true;
  242. this.title = "修改终端";
  243. });
  244. },
  245. /** 提交按钮 */
  246. submitForm: function() {
  247. this.$refs["form"].validate(valid => {
  248. if (valid) {
  249. this.form.authorizedGrantTypes = this.form.authorizedGrantTypes.join(",");
  250. if (!this.isAdd && this.form.clientId != undefined) {
  251. updateClient(this.form).then(response => {
  252. if (response.code === 200) {
  253. this.msgSuccess("修改成功");
  254. this.open = false;
  255. this.getList();
  256. }
  257. });
  258. } else {
  259. addClient(this.form).then(response => {
  260. if (response.code === 200) {
  261. this.msgSuccess("新增成功");
  262. this.open = false;
  263. this.getList();
  264. }
  265. });
  266. }
  267. }
  268. });
  269. },
  270. /** 删除按钮操作 */
  271. handleDelete(row) {
  272. const clientIds = row.clientId || this.ids;
  273. this.$confirm('是否确认删除终端编号为"' + clientIds + '"的数据项?', "警告", {
  274. confirmButtonText: "确定",
  275. cancelButtonText: "取消",
  276. type: "warning"
  277. }).then(function() {
  278. return delClient(clientIds);
  279. }).then(() => {
  280. this.getList();
  281. this.msgSuccess("删除成功");
  282. }).catch(function() {});
  283. }
  284. }
  285. };
  286. </script>