UserApiKeyManager.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div id="app" style="width: 100%">
  3. <div class="page-header" style="margin-bottom: 0">
  4. <div class="page-title">
  5. <el-page-header @back="goBack" content="ApiKey列表"></el-page-header>
  6. </div>
  7. <div class="page-header-btn">
  8. <el-button icon="el-icon-plus" size="mini" style="margin-right: 1rem;" type="primary" @click="addUserApiKey">
  9. 添加ApiKey
  10. </el-button>
  11. </div>
  12. </div>
  13. <!--ApiKey列表-->
  14. <el-table :data="userList" style="width: 100%;font-size: 12px;" :height="winHeight"
  15. header-row-class-name="table-header">
  16. <el-table-column prop="user.username" label="用户名" min-width="120"/>
  17. <el-table-column prop="app" label="应用名" min-width="160"/>
  18. <el-table-column label="ApiKey" :show-overflow-tooltip="true" min-width="300">
  19. <template #default="scope">
  20. <!-- <el-button style="float: right;" type="primary" size="mini" icon="el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.apiKey" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></el-button>-->
  21. <i class="cpoy-btn el-icon-document-copy" title="点击拷贝" v-clipboard="scope.row.apiKey" @success="$message({type:'success', message:'成功拷贝到粘贴板'})"></i>
  22. <span>{{scope.row.apiKey}}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column prop="enable" label="启用" width="120">
  26. <template #default="scope">
  27. <el-tag v-if="scope.row.enable">
  28. 启用
  29. </el-tag>
  30. <el-tag v-else type="info">
  31. 停用
  32. </el-tag>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="expiredAt" label="过期时间" width="160"/>
  36. <el-table-column prop="remark" label="备注信息" min-width="160"/>
  37. <el-table-column label="操作" min-width="260" fixed="right">
  38. <template #default="scope">
  39. <el-button v-if="scope.row.enable"
  40. size="medium" icon="el-icon-circle-close" type="text" @click="disableUserApiKey(scope.row)">
  41. 停用
  42. </el-button>
  43. <el-button v-else
  44. size="medium" icon="el-icon-circle-check" type="text" @click="enableUserApiKey(scope.row)">
  45. 启用
  46. </el-button>
  47. <el-divider direction="vertical"></el-divider>
  48. <el-button size="medium" icon="el-icon-refresh" type="text" @click="resetUserApiKey(scope.row)">
  49. 重置
  50. </el-button>
  51. <el-divider direction="vertical"></el-divider>
  52. <el-button size="medium" icon="el-icon-edit" type="text" @click="remarkUserApiKey(scope.row)">
  53. 备注
  54. </el-button>
  55. <el-divider direction="vertical"></el-divider>
  56. <el-button size="medium" icon="el-icon-delete" type="text" @click="deleteUserApiKey(scope.row)"
  57. style="color: #f56c6c">
  58. 删除
  59. </el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <addUserApiKey ref="addUserApiKey"></addUserApiKey>
  64. <remarkUserApiKey ref="remarkUserApiKey"></remarkUserApiKey>
  65. <el-pagination
  66. style="float: right"
  67. @size-change="handleSizeChange"
  68. @current-change="currentChange"
  69. :current-page="currentPage"
  70. :page-size="count"
  71. :page-sizes="[15, 25, 35, 50]"
  72. layout="total, sizes, prev, pager, next"
  73. :total="total">
  74. </el-pagination>
  75. </div>
  76. </template>
  77. <script>
  78. import uiHeader from '../layout/UiHeader.vue'
  79. import addUserApiKey from "./dialog/addUserApiKey.vue";
  80. import remarkUserApiKey from './dialog/remarkUserApiKey.vue'
  81. export default {
  82. name: 'userApiKeyManager',
  83. components: {
  84. uiHeader,
  85. addUserApiKey,
  86. remarkUserApiKey
  87. },
  88. data() {
  89. return {
  90. userList: [], //设备列表
  91. currentUser: {}, //当前操作设备对象
  92. winHeight: window.innerHeight - 200,
  93. currentPage: 1,
  94. count: 15,
  95. total: 0,
  96. getUserApiKeyListLoading: false
  97. };
  98. },
  99. mounted() {
  100. this.initParam();
  101. this.initData();
  102. },
  103. methods: {
  104. goBack() {
  105. this.$router.back()
  106. },
  107. initParam() {
  108. this.userId = this.$route.params.userId;
  109. },
  110. initData() {
  111. this.getUserApiKeyList();
  112. },
  113. currentChange(val) {
  114. this.currentPage = val;
  115. this.getUserApiKeyList();
  116. },
  117. handleSizeChange(val) {
  118. this.count = val;
  119. this.getUserApiKeyList();
  120. },
  121. getUserApiKeyList() {
  122. let that = this;
  123. this.getUserApiKeyListLoading = true;
  124. this.$axios({
  125. method: 'get',
  126. url: `/api/userApiKey/userApiKeys`,
  127. params: {
  128. page: that.currentPage,
  129. count: that.count
  130. }
  131. }).then((res) => {
  132. if (res.data.code === 0) {
  133. that.total = res.data.data.total;
  134. that.userList = res.data.data.list;
  135. }
  136. that.getUserApiKeyListLoading = false;
  137. }).catch((error) => {
  138. that.getUserApiKeyListLoading = false;
  139. });
  140. },
  141. addUserApiKey() {
  142. this.$refs.addUserApiKey.openDialog(this.userId, () => {
  143. this.$refs.addUserApiKey.close();
  144. this.$message({
  145. showClose: true,
  146. message: "ApiKey添加成功",
  147. type: "success",
  148. });
  149. setTimeout(this.getUserApiKeyList, 200)
  150. })
  151. },
  152. remarkUserApiKey(row) {
  153. this.$refs.remarkUserApiKey.openDialog(row.id, () => {
  154. this.$refs.remarkUserApiKey.close();
  155. this.$message({
  156. showClose: true,
  157. message: "备注修改成功",
  158. type: "success",
  159. });
  160. setTimeout(this.getUserApiKeyList, 200)
  161. })
  162. },
  163. enableUserApiKey(row) {
  164. let msg = "确定启用此ApiKey?"
  165. if (row.online !== 0) {
  166. msg = "<strong>确定启用此ApiKey?</strong>"
  167. }
  168. this.$confirm(msg, '提示', {
  169. dangerouslyUseHTMLString: true,
  170. confirmButtonText: '确定',
  171. cancelButtonText: '取消',
  172. center: true,
  173. type: 'warning'
  174. }).then(() => {
  175. this.$axios({
  176. method: 'post',
  177. url: `/api/userApiKey/enable?id=${row.id}`
  178. }).then((res) => {
  179. this.$message({
  180. showClose: true,
  181. message: '启用成功',
  182. type: 'success'
  183. });
  184. this.getUserApiKeyList();
  185. }).catch((error) => {
  186. this.$message({
  187. showClose: true,
  188. message: '启用失败',
  189. type: 'error'
  190. });
  191. console.error(error);
  192. });
  193. }).catch(() => {
  194. });
  195. },
  196. disableUserApiKey(row) {
  197. let msg = "确定停用此ApiKey?"
  198. if (row.online !== 0) {
  199. msg = "<strong>确定停用此ApiKey?</strong>"
  200. }
  201. this.$confirm(msg, '提示', {
  202. dangerouslyUseHTMLString: true,
  203. confirmButtonText: '确定',
  204. cancelButtonText: '取消',
  205. center: true,
  206. type: 'warning'
  207. }).then(() => {
  208. this.$axios({
  209. method: 'post',
  210. url: `/api/userApiKey/disable?id=${row.id}`
  211. }).then((res) => {
  212. this.$message({
  213. showClose: true,
  214. message: '停用成功',
  215. type: 'success'
  216. });
  217. this.getUserApiKeyList();
  218. }).catch((error) => {
  219. this.$message({
  220. showClose: true,
  221. message: '停用失败',
  222. type: 'error'
  223. });
  224. console.error(error);
  225. });
  226. }).catch(() => {
  227. });
  228. },
  229. resetUserApiKey(row) {
  230. let msg = "确定重置此ApiKey?"
  231. if (row.online !== 0) {
  232. msg = "<strong>确定重置此ApiKey?</strong>"
  233. }
  234. this.$confirm(msg, '提示', {
  235. dangerouslyUseHTMLString: true,
  236. confirmButtonText: '确定',
  237. cancelButtonText: '取消',
  238. center: true,
  239. type: 'warning'
  240. }).then(() => {
  241. this.$axios({
  242. method: 'post',
  243. url: `/api/userApiKey/reset?id=${row.id}`
  244. }).then((res) => {
  245. this.$message({
  246. showClose: true,
  247. message: '重置成功',
  248. type: 'success'
  249. });
  250. this.getUserApiKeyList();
  251. }).catch((error) => {
  252. this.$message({
  253. showClose: true,
  254. message: '重置失败',
  255. type: 'error'
  256. });
  257. console.error(error);
  258. });
  259. }).catch(() => {
  260. });
  261. },
  262. deleteUserApiKey(row) {
  263. let msg = "确定删除此ApiKey?"
  264. if (row.online !== 0) {
  265. msg = "<strong>确定删除此ApiKey?</strong>"
  266. }
  267. this.$confirm(msg, '提示', {
  268. dangerouslyUseHTMLString: true,
  269. confirmButtonText: '确定',
  270. cancelButtonText: '取消',
  271. center: true,
  272. type: 'warning'
  273. }).then(() => {
  274. this.$axios({
  275. method: 'delete',
  276. url: `/api/userApiKey/delete?id=${row.id}`
  277. }).then((res) => {
  278. this.$message({
  279. showClose: true,
  280. message: '删除成功',
  281. type: 'success'
  282. });
  283. this.getUserApiKeyList();
  284. }).catch((error) => {
  285. this.$message({
  286. showClose: true,
  287. message: '删除失败',
  288. type: 'error'
  289. });
  290. console.error(error);
  291. });
  292. }).catch(() => {
  293. });
  294. },
  295. }
  296. }
  297. </script>
  298. <style>
  299. </style>