index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div class="search" v-show="showSearch">
  5. <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
  6. <el-form-item label="客户端key" prop="clientKey">
  7. <el-input v-model="queryParams.clientKey" placeholder="请输入客户端key" clearable @keyup.enter="handleQuery" />
  8. </el-form-item>
  9. <el-form-item label="客户端秘钥" prop="clientSecret">
  10. <el-input v-model="queryParams.clientSecret" placeholder="请输入客户端秘钥" clearable @keyup.enter="handleQuery" />
  11. </el-form-item>
  12. <el-form-item label="状态" prop="status">
  13. <el-select v-model="queryParams.status" placeholder="状态" clearable>
  14. <el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  19. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  20. </el-form-item>
  21. </el-form>
  22. </div>
  23. </transition>
  24. <el-card shadow="never">
  25. <template #header>
  26. <el-row :gutter="10" class="mb8">
  27. <el-col :span="1.5">
  28. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:client:add']">新增</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:client:edit']">修改</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:client:remove']">删除</el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:client:export']">导出</el-button>
  38. </el-col>
  39. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  40. </el-row>
  41. </template>
  42. <el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange">
  43. <el-table-column type="selection" width="55" align="center" />
  44. <el-table-column label="id" align="center" prop="id" v-if="true" />
  45. <el-table-column label="客户端id" align="center" prop="clientId" />
  46. <el-table-column label="客户端key" align="center" prop="clientKey" />
  47. <el-table-column label="客户端秘钥" align="center" prop="clientSecret" />
  48. <el-table-column label="授权类型" align="center">
  49. <template #default="scope">
  50. <div>
  51. <template v-for="type in scope.row.grantTypeList">
  52. <dict-tag class="el-check-tag" :options="sys_grant_type" :value="type" />
  53. </template>
  54. </div>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="Token活跃超时时间" align="center" prop="activityTimeout" />
  58. <el-table-column label="Token固定超时时间" align="center" prop="timeout" />
  59. <el-table-column label="状态" align="center" key="status">
  60. <template #default="scope">
  61. <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  65. <template #default="scope">
  66. <el-tooltip content="修改" placement="top">
  67. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:client:edit']"></el-button>
  68. </el-tooltip>
  69. <el-tooltip content="删除" placement="top">
  70. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:client:remove']"></el-button>
  71. </el-tooltip>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <pagination
  76. v-show="total>0"
  77. :total="total"
  78. v-model:page="queryParams.pageNum"
  79. v-model:limit="queryParams.pageSize"
  80. @pagination="getList"
  81. />
  82. </el-card>
  83. <!-- 添加或修改客户端管理对话框 -->
  84. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  85. <el-form ref="clientFormRef" :model="form" :rules="rules" label-width="100px">
  86. <el-form-item label="客户端key" prop="clientKey">
  87. <el-input v-model="form.clientKey" :disabled="form.id != null" placeholder="请输入客户端key" />
  88. </el-form-item>
  89. <el-form-item label="客户端秘钥" prop="clientSecret">
  90. <el-input v-model="form.clientSecret" :disabled="form.id != null" placeholder="请输入客户端秘钥" />
  91. </el-form-item>
  92. <el-form-item label="授权类型" prop="grantTypeList">
  93. <el-select v-model="form.grantTypeList" multiple placeholder="请输入授权类型">
  94. <el-option
  95. v-for="dict in sys_grant_type"
  96. :key="dict.value" :label="dict.label" :value="dict.value"
  97. ></el-option>
  98. </el-select>
  99. </el-form-item>
  100. <el-form-item prop="activityTimeout" label-width="auto">
  101. <template #label>
  102. <span>
  103. <el-tooltip content="指定时间无操作则过期(单位:秒),默认30分钟(1800秒)" placement="top">
  104. <el-icon><question-filled /></el-icon>
  105. </el-tooltip>
  106. Token活跃超时时间
  107. </span>
  108. </template>
  109. <el-input v-model="form.activityTimeout" placeholder="请输入Token活跃超时时间" />
  110. </el-form-item>
  111. <el-form-item prop="timeout" label-width="auto">
  112. <template #label>
  113. <span>
  114. <el-tooltip content="指定时间必定过期(单位:秒),默认七天(604800秒)" placement="top">
  115. <el-icon><question-filled /></el-icon>
  116. </el-tooltip>
  117. Token固定超时时间
  118. </span>
  119. </template>
  120. <el-input v-model="form.timeout" placeholder="请输入Token固定超时时间" />
  121. </el-form-item>
  122. <el-form-item label="状态">
  123. <el-radio-group v-model="form.status">
  124. <el-radio v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.value">
  125. {{ dict.label }}
  126. </el-radio>
  127. </el-radio-group>
  128. </el-form-item>
  129. </el-form>
  130. <template #footer>
  131. <div class="dialog-footer">
  132. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  133. <el-button @click="cancel">取 消</el-button>
  134. </div>
  135. </template>
  136. </el-dialog>
  137. </div>
  138. </template>
  139. <script setup name="Client" lang="ts">
  140. import { listClient, getClient, delClient, addClient, updateClient, changeStatus } from '@/api/system/client';
  141. import { ClientVO, ClientQuery, ClientForm } from '@/api/system/client/types';
  142. import { ComponentInternalInstance } from 'vue';
  143. import { ElForm } from 'element-plus';
  144. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  145. const { sys_normal_disable } = toRefs<any>(proxy?.useDict("sys_normal_disable"));
  146. const { sys_grant_type } = toRefs<any>(proxy?.useDict("sys_grant_type"));
  147. const clientList = ref<ClientVO[]>([]);
  148. const buttonLoading = ref(false);
  149. const loading = ref(true);
  150. const showSearch = ref(true);
  151. const ids = ref<Array<string | number>>([]);
  152. const single = ref(true);
  153. const multiple = ref(true);
  154. const total = ref(0);
  155. const queryFormRef = ref(ElForm);
  156. const clientFormRef = ref(ElForm);
  157. const dialog = reactive<DialogOption>({
  158. visible: false,
  159. title: ''
  160. });
  161. const initFormData: ClientForm = {
  162. id: undefined,
  163. clientId: undefined,
  164. clientKey: undefined,
  165. clientSecret: undefined,
  166. grantTypeList: undefined,
  167. activityTimeout: undefined,
  168. timeout: undefined,
  169. status: undefined,
  170. }
  171. const data = reactive<PageData<ClientForm, ClientQuery>>({
  172. form: {...initFormData},
  173. queryParams: {
  174. pageNum: 1,
  175. pageSize: 10,
  176. clientId: undefined,
  177. clientKey: undefined,
  178. clientSecret: undefined,
  179. grantType: undefined,
  180. activityTimeout: undefined,
  181. timeout: undefined,
  182. status: undefined,
  183. },
  184. rules: {
  185. id: [
  186. { required: true, message: "id不能为空", trigger: "blur" }
  187. ],
  188. clientId: [
  189. { required: true, message: "客户端id不能为空", trigger: "blur" }
  190. ],
  191. clientKey: [
  192. { required: true, message: "客户端key不能为空", trigger: "blur" }
  193. ],
  194. clientSecret: [
  195. { required: true, message: "客户端秘钥不能为空", trigger: "blur" }
  196. ],
  197. grantTypeList: [
  198. { required: true, message: "授权类型不能为空", trigger: "change" }
  199. ],
  200. }
  201. });
  202. const { queryParams, form, rules } = toRefs(data);
  203. /** 查询客户端管理列表 */
  204. const getList = async () => {
  205. loading.value = true;
  206. const res = await listClient(queryParams.value);
  207. clientList.value = res.rows;
  208. total.value = res.total;
  209. loading.value = false;
  210. }
  211. /** 取消按钮 */
  212. const cancel = () => {
  213. reset();
  214. dialog.visible = false;
  215. }
  216. /** 表单重置 */
  217. const reset = () => {
  218. form.value = {...initFormData};
  219. clientFormRef.value.resetFields();
  220. }
  221. /** 搜索按钮操作 */
  222. const handleQuery = () => {
  223. queryParams.value.pageNum = 1;
  224. getList();
  225. }
  226. /** 重置按钮操作 */
  227. const resetQuery = () => {
  228. queryFormRef.value.resetFields();
  229. handleQuery();
  230. }
  231. /** 多选框选中数据 */
  232. const handleSelectionChange = (selection: ClientVO[]) => {
  233. ids.value = selection.map(item => item.id);
  234. single.value = selection.length != 1;
  235. multiple.value = !selection.length;
  236. }
  237. /** 新增按钮操作 */
  238. const handleAdd = () => {
  239. dialog.visible = true;
  240. dialog.title = "添加客户端管理";
  241. nextTick(() => {
  242. reset();
  243. });
  244. }
  245. /** 修改按钮操作 */
  246. const handleUpdate = (row?: ClientVO) => {
  247. loading.value = true
  248. dialog.visible = true;
  249. dialog.title = "修改客户端管理";
  250. nextTick(async () => {
  251. reset();
  252. const _id = row?.id || ids.value[0]
  253. const res = await getClient(_id);
  254. loading.value = false;
  255. Object.assign(form.value, res.data);
  256. });
  257. }
  258. /** 提交按钮 */
  259. const submitForm = () => {
  260. clientFormRef.value.validate(async (valid: boolean) => {
  261. if (valid) {
  262. buttonLoading.value = true;
  263. if (form.value.id) {
  264. await updateClient(form.value).finally(() => buttonLoading.value = false);
  265. } else {
  266. await addClient(form.value).finally(() => buttonLoading.value = false);
  267. }
  268. proxy?.$modal.msgSuccess("修改成功");
  269. dialog.visible = false;
  270. await getList();
  271. }
  272. });
  273. }
  274. /** 删除按钮操作 */
  275. const handleDelete = async (row?: ClientVO) => {
  276. const _ids = row?.id || ids.value;
  277. await proxy?.$modal.confirm('是否确认删除客户端管理编号为"' + _ids + '"的数据项?').finally(() => loading.value = false);
  278. await delClient(_ids);
  279. proxy?.$modal.msgSuccess("删除成功");
  280. await getList();
  281. }
  282. /** 导出按钮操作 */
  283. const handleExport = () => {
  284. proxy?.download('system/client/export', {
  285. ...queryParams.value
  286. }, `client_${new Date().getTime()}.xlsx`)
  287. }
  288. /** 状态修改 */
  289. const handleStatusChange = async (row: ClientVO) => {
  290. let text = row.status === "0" ? "启用" : "停用"
  291. try {
  292. await proxy?.$modal.confirm('确认要"' + text + '"吗?');
  293. await changeStatus(row.id, row.status);
  294. proxy?.$modal.msgSuccess(text + "成功");
  295. } catch (err) {
  296. row.status = row.status === "0" ? "1" : "0";
  297. }
  298. }
  299. onMounted(() => {
  300. getList();
  301. });
  302. </script>