index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. <div class="top-right-btn">
  49. <el-tooltip class="item" effect="dark" content="刷新" placement="top">
  50. <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
  51. </el-tooltip>
  52. <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
  53. <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
  54. </el-tooltip>
  55. </div>
  56. </el-row>
  57. <el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange">
  58. <el-table-column type="selection" width="55" align="center" />
  59. <el-table-column label="编号" align="center" prop="clientId" />
  60. <el-table-column label="安全码" align="center" prop="clientSecret" :show-overflow-tooltip="true" />
  61. <el-table-column label="授权范围" align="center" prop="scope" />
  62. <el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :show-overflow-tooltip="true" />
  63. <el-table-column label="令牌时效" align="center" prop="accessTokenValidity" />
  64. <el-table-column label="刷新时效" align="center" prop="refreshTokenValidity" />
  65. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  66. <template slot-scope="scope">
  67. <el-button
  68. size="mini"
  69. type="text"
  70. icon="el-icon-edit"
  71. @click="handleUpdate(scope.row)"
  72. v-hasPermi="['system:client:edit']"
  73. >修改</el-button>
  74. <el-button
  75. size="mini"
  76. type="text"
  77. icon="el-icon-delete"
  78. @click="handleDelete(scope.row)"
  79. v-hasPermi="['system:client:remove']"
  80. >删除</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <pagination
  85. v-show="total>0"
  86. :total="total"
  87. :page.sync="queryParams.pageNum"
  88. :limit.sync="queryParams.pageSize"
  89. @pagination="getList"
  90. />
  91. <!-- 添加或修改终端对话框 -->
  92. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  93. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  94. <el-form-item label="编号" prop="clientId">
  95. <el-input v-model="form.clientId" placeholder="请输入编号" :disabled="!isAdd" />
  96. </el-form-item>
  97. <el-form-item label="安全码" prop="clientSecret">
  98. <el-input v-model="form.clientSecret" placeholder="请输入安全码" />
  99. </el-form-item>
  100. <el-form-item label="授权范围" prop="scope">
  101. <el-input v-model="form.scope" placeholder="请输入授权范围" />
  102. </el-form-item>
  103. <el-form-item label="授权类型" prop="authorizedGrantTypes">
  104. <el-input v-model="form.authorizedGrantTypes" placeholder="请输入授权类型" />
  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. queryParams: {
  146. pageNum: 1,
  147. pageSize: 10,
  148. clientId: undefined
  149. },
  150. // 是否新增
  151. isAdd: false,
  152. // 表单参数
  153. form: {},
  154. // 表单校验
  155. rules: {
  156. clientId: [
  157. { required: true, message: "编号不能为空", trigger: "blur" }
  158. ],
  159. clientSecret: [
  160. { required: true, message: "安全码不能为空", trigger: "blur" }
  161. ],
  162. scope: [
  163. { required: true, message: "授权范围不能为空", trigger: "blur" }
  164. ],
  165. authorizedGrantTypes: [
  166. { required: true, message: "授权类型不能为空", trigger: "blur" }
  167. ]
  168. }
  169. };
  170. },
  171. created() {
  172. this.getList();
  173. },
  174. methods: {
  175. /** 查询终端列表 */
  176. getList() {
  177. this.loading = true;
  178. listClient(this.queryParams).then(response => {
  179. this.clientList = response.rows;
  180. this.total = response.total;
  181. this.loading = false;
  182. });
  183. },
  184. // 取消按钮
  185. cancel() {
  186. this.open = false;
  187. this.reset();
  188. },
  189. // 表单重置
  190. reset() {
  191. this.form = {
  192. clientId: undefined,
  193. clientSecret: undefined,
  194. scope: "server",
  195. authorizedGrantTypes: "password,refresh_token",
  196. accessTokenValidity: 3600,
  197. refreshTokenValidity: 7200
  198. };
  199. this.resetForm("form");
  200. },
  201. /** 搜索按钮操作 */
  202. handleQuery() {
  203. this.queryParams.pageNum = 1;
  204. this.getList();
  205. },
  206. /** 重置按钮操作 */
  207. resetQuery() {
  208. this.resetForm("queryForm");
  209. this.handleQuery();
  210. },
  211. // 多选框选中数据
  212. handleSelectionChange(selection) {
  213. this.ids = selection.map(item => item.clientId);
  214. this.single = selection.length != 1;
  215. this.multiple = !selection.length;
  216. },
  217. /** 新增按钮操作 */
  218. handleAdd() {
  219. this.reset();
  220. this.open = true;
  221. this.isAdd = true;
  222. this.title = "添加终端";
  223. },
  224. /** 修改按钮操作 */
  225. handleUpdate(row) {
  226. this.reset();
  227. this.isAdd = false;
  228. const clientId = row.clientId || this.ids;
  229. getClient(clientId).then(response => {
  230. this.form = response.data;
  231. this.open = true;
  232. this.title = "修改终端";
  233. });
  234. },
  235. /** 提交按钮 */
  236. submitForm: function() {
  237. this.$refs["form"].validate(valid => {
  238. if (valid) {
  239. if (!this.isAdd && this.form.clientId != undefined) {
  240. updateClient(this.form).then(response => {
  241. if (response.code === 200) {
  242. this.msgSuccess("修改成功");
  243. this.open = false;
  244. this.getList();
  245. }
  246. });
  247. } else {
  248. addClient(this.form).then(response => {
  249. if (response.code === 200) {
  250. this.msgSuccess("新增成功");
  251. this.open = false;
  252. this.getList();
  253. }
  254. });
  255. }
  256. }
  257. });
  258. },
  259. /** 删除按钮操作 */
  260. handleDelete(row) {
  261. const clientIds = row.clientId || this.ids;
  262. this.$confirm('是否确认删除终端编号为"' + clientIds + '"的数据项?', "警告", {
  263. confirmButtonText: "确定",
  264. cancelButtonText: "取消",
  265. type: "warning"
  266. }).then(function() {
  267. return delClient(clientIds);
  268. }).then(() => {
  269. this.getList();
  270. this.msgSuccess("删除成功");
  271. }).catch(function() {});
  272. }
  273. }
  274. };
  275. </script>