index.vue 12 KB

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