index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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="clientSecret" :show-overflow-tooltip="true" />
  54. <el-table-column label="授权范围" align="center" prop="scope" />
  55. <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :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="clientSecret">
  91. <el-input v-model="form.clientSecret" 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-input v-model="form.authorizedGrantTypes" placeholder="请输入授权类型" />
  98. </el-form-item>
  99. <el-form-item label="令牌时效" prop="accessTokenValidity">
  100. <el-input-number v-model="form.accessTokenValidity" controls-position="right" :min="0" />
  101. </el-form-item>
  102. <el-form-item label="刷新时效" prop="refreshTokenValidity">
  103. <el-input-number v-model="form.refreshTokenValidity" controls-position="right" :min="0" />
  104. </el-form-item>
  105. </el-form>
  106. <div slot="footer" class="dialog-footer">
  107. <el-button type="primary" @click="submitForm">确 定</el-button>
  108. <el-button @click="cancel">取 消</el-button>
  109. </div>
  110. </el-dialog>
  111. </div>
  112. </template>
  113. <script>
  114. import { listClient, getClient, delClient, addClient, updateClient } from "@/api/system/client";
  115. export default {
  116. name: "Client",
  117. data() {
  118. return {
  119. // 遮罩层
  120. loading: true,
  121. // 选中数组
  122. ids: [],
  123. // 非单个禁用
  124. single: true,
  125. // 非多个禁用
  126. multiple: true,
  127. // 显示搜索条件
  128. showSearch: true,
  129. // 总条数
  130. total: 0,
  131. // 终端表格数据
  132. clientList: [],
  133. // 弹出层标题
  134. title: "",
  135. // 是否显示弹出层
  136. open: false,
  137. // 查询参数
  138. queryParams: {
  139. pageNum: 1,
  140. pageSize: 10,
  141. clientId: undefined
  142. },
  143. // 是否新增
  144. isAdd: false,
  145. // 表单参数
  146. form: {},
  147. // 表单校验
  148. rules: {
  149. clientId: [
  150. { required: true, message: "编号不能为空", trigger: "blur" }
  151. ],
  152. clientSecret: [
  153. { required: true, message: "安全码不能为空", trigger: "blur" }
  154. ],
  155. scope: [
  156. { required: true, message: "授权范围不能为空", trigger: "blur" }
  157. ],
  158. authorizedGrantTypes: [
  159. { required: true, message: "授权类型不能为空", trigger: "blur" }
  160. ]
  161. }
  162. };
  163. },
  164. created() {
  165. this.getList();
  166. },
  167. methods: {
  168. /** 查询终端列表 */
  169. getList() {
  170. this.loading = true;
  171. listClient(this.queryParams).then(response => {
  172. this.clientList = response.rows;
  173. this.total = response.total;
  174. this.loading = false;
  175. });
  176. },
  177. // 取消按钮
  178. cancel() {
  179. this.open = false;
  180. this.reset();
  181. },
  182. // 表单重置
  183. reset() {
  184. this.form = {
  185. clientId: undefined,
  186. clientSecret: undefined,
  187. scope: "server",
  188. authorizedGrantTypes: "password,refresh_token",
  189. accessTokenValidity: 3600,
  190. refreshTokenValidity: 7200
  191. };
  192. this.resetForm("form");
  193. },
  194. /** 搜索按钮操作 */
  195. handleQuery() {
  196. this.queryParams.pageNum = 1;
  197. this.getList();
  198. },
  199. /** 重置按钮操作 */
  200. resetQuery() {
  201. this.resetForm("queryForm");
  202. this.handleQuery();
  203. },
  204. // 多选框选中数据
  205. handleSelectionChange(selection) {
  206. this.ids = selection.map(item => item.clientId);
  207. this.single = selection.length != 1;
  208. this.multiple = !selection.length;
  209. },
  210. /** 新增按钮操作 */
  211. handleAdd() {
  212. this.reset();
  213. this.open = true;
  214. this.isAdd = true;
  215. this.title = "添加终端";
  216. },
  217. /** 修改按钮操作 */
  218. handleUpdate(row) {
  219. this.reset();
  220. this.isAdd = false;
  221. const clientId = row.clientId || this.ids;
  222. getClient(clientId).then(response => {
  223. this.form = response.data;
  224. this.open = true;
  225. this.title = "修改终端";
  226. });
  227. },
  228. /** 提交按钮 */
  229. submitForm: function() {
  230. this.$refs["form"].validate(valid => {
  231. if (valid) {
  232. if (!this.isAdd && this.form.clientId != undefined) {
  233. updateClient(this.form).then(response => {
  234. if (response.code === 200) {
  235. this.msgSuccess("修改成功");
  236. this.open = false;
  237. this.getList();
  238. }
  239. });
  240. } else {
  241. addClient(this.form).then(response => {
  242. if (response.code === 200) {
  243. this.msgSuccess("新增成功");
  244. this.open = false;
  245. this.getList();
  246. }
  247. });
  248. }
  249. }
  250. });
  251. },
  252. /** 删除按钮操作 */
  253. handleDelete(row) {
  254. const clientIds = row.clientId || this.ids;
  255. this.$confirm('是否确认删除终端编号为"' + clientIds + '"的数据项?', "警告", {
  256. confirmButtonText: "确定",
  257. cancelButtonText: "取消",
  258. type: "warning"
  259. }).then(function() {
  260. return delClient(clientIds);
  261. }).then(() => {
  262. this.getList();
  263. this.msgSuccess("删除成功");
  264. }).catch(function() {});
  265. }
  266. }
  267. };
  268. </script>