index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div class="app-container">
  3. <div>
  4. <el-form
  5. ref="form"
  6. :model="activationCode"
  7. :rules="rulesActivationCode"
  8. label-width="80px"
  9. >
  10. <el-form-item label="租户信息" prop="tenantCode">
  11. <el-select
  12. v-model="activationCode.tenantCode"
  13. placeholder="请选择"
  14. filterable
  15. >
  16. <el-option
  17. v-for="item in tenantList"
  18. :key="item.tenantId"
  19. :label="item.tenantName"
  20. :value="item.tenantId"
  21. >
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item
  26. label="充值时间"
  27. prop="tenantExpirationDate"
  28. style="width: 300px"
  29. >
  30. <el-input
  31. v-model="activationCode.tenantExpirationDate"
  32. placeholder="请输入充值天数"
  33. ></el-input>
  34. </el-form-item>
  35. </el-form>
  36. <div slot="footer" class="dialog-footer">
  37. <el-button type="primary" @click="crateCode">生成激活码</el-button>
  38. <el-button @click="cancel">取 消</el-button>
  39. </div>
  40. <!-- 激活码生成成功-->
  41. <el-dialog
  42. :title="title"
  43. :visible.sync="activationCodeForm"
  44. width="500px"
  45. append-to-body
  46. >
  47. <span v-html="actCode"></span>
  48. <div slot="footer" class="dialog-footer">
  49. <el-button type="primary" @click="copyToClipboard"
  50. >一键复制</el-button
  51. >
  52. <el-button @click="activationCodeForm = false">取 消</el-button>
  53. </div>
  54. </el-dialog>
  55. </div>
  56. <div style="margin-top: 30px">
  57. <!--搜索条件表单-->
  58. <el-form
  59. :model="queryParams"
  60. ref="queryForm"
  61. size="small"
  62. :inline="true"
  63. v-show="showSearch"
  64. label-width="68px"
  65. >
  66. <el-form-item label="登录地址" prop="ipAddress">
  67. <el-input
  68. v-model="queryParams.ipAddress"
  69. placeholder="请输入登录地址"
  70. clearable
  71. style="width: 240px"
  72. @keyup.enter.native="handleQuery"
  73. />
  74. </el-form-item>
  75. <el-form-item label="操作人员" prop="operator">
  76. <el-input
  77. v-model="queryParams.operator"
  78. placeholder="请输入操作人员"
  79. clearable
  80. style="width: 240px"
  81. @keyup.enter.native="handleQuery"
  82. />
  83. </el-form-item>
  84. <el-form-item label="操作时间">
  85. <el-date-picker
  86. v-model="dateRange"
  87. style="width: 240px"
  88. value-format="yyyy-MM-dd HH:mm:ss"
  89. type="daterange"
  90. range-separator="-"
  91. start-placeholder="开始日期"
  92. end-placeholder="结束日期"
  93. :default-time="['00:00:00', '23:59:59']"
  94. ></el-date-picker>
  95. </el-form-item>
  96. <el-form-item>
  97. <el-button
  98. type="primary"
  99. icon="el-icon-search"
  100. size="mini"
  101. @click="handleQuery"
  102. >搜索</el-button
  103. >
  104. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  105. >重置</el-button
  106. >
  107. </el-form-item>
  108. </el-form>
  109. <!--表格-->
  110. <el-table
  111. ref="tables"
  112. v-loading="loading"
  113. :data="list"
  114. @selection-change="handleSelectionChange"
  115. :default-sort="defaultSort"
  116. @sort-change="handleSortChange"
  117. style="margin-top: 20px"
  118. >
  119. <el-table-column type="selection" width="50" align="center" />
  120. <el-table-column label="日志编号" align="center" prop="logId" />
  121. <el-table-column label="操作人员" align="center" prop="operator" />
  122. <el-table-column
  123. label="操作ip地址"
  124. align="center"
  125. prop="ipAddress"
  126. :show-overflow-tooltip="true"
  127. />
  128. <el-table-column
  129. label="操作日期"
  130. align="center"
  131. prop="generationTime"
  132. sortable="custom"
  133. :sort-orders="['descending', 'ascending']"
  134. >
  135. <template slot-scope="scope">
  136. <span>{{ parseTime(scope.row.generationTime) }}</span>
  137. </template>
  138. </el-table-column>
  139. <el-table-column label="备注" align="center" prop="note">
  140. </el-table-column>
  141. </el-table>
  142. <!--分页器-->
  143. <pagination
  144. v-show="total > 0"
  145. :total="total"
  146. :page.sync="queryParams.pageNum"
  147. :limit.sync="queryParams.pageSize"
  148. @pagination="getCodeLogList"
  149. />
  150. </div>
  151. </div>
  152. </template>
  153. <script>
  154. import { listTenant, createTenantCode } from "@/api/system/tenant";
  155. import {
  156. list,
  157. delActivationLog,
  158. cleanActivationLog,
  159. } from "@/api/monitor/activationcode";
  160. import Clipboard from "clipboard";
  161. export default {
  162. name: "TenantCode",
  163. data() {
  164. return {
  165. options: [],
  166. //表单校验
  167. rulesActivationCode: {
  168. tenantCode: [
  169. { required: true, message: "未选择租户信息", trigger: "change" },
  170. ],
  171. tenantExpirationDate: [
  172. { required: true, message: "租户到期时间未设置", trigger: "blur" },
  173. ],
  174. },
  175. activationCode: {},
  176. //租户信息表格数据
  177. tenantList: [],
  178. activationCodeForm: false,
  179. actCode: "",
  180. title: "激活码生成成功",
  181. // 遮罩层
  182. loading: true,
  183. // 选中数组
  184. ids: [],
  185. // 非多个禁用
  186. multiple: true,
  187. // 显示搜索条件
  188. showSearch: true,
  189. // 总条数
  190. total: 0,
  191. // 表格数据
  192. list: [],
  193. // 是否显示弹出层
  194. open: false,
  195. // 日期范围
  196. dateRange: [],
  197. // 默认排序
  198. defaultSort: { prop: "operTime", order: "descending" },
  199. // 表单参数
  200. form: {},
  201. // 查询参数
  202. queryParams: {
  203. pageNum: 1,
  204. pageSize: 10,
  205. operator: undefined,
  206. ipAddress: undefined,
  207. isEnablePaging:false,
  208. },
  209. };
  210. },
  211. computed: {},
  212. created() {
  213. this.getList();
  214. this.getCodeLogList();
  215. },
  216. methods: {
  217. //查询租户信息列表
  218. getList() {
  219. listTenant({ isEnablePaging: false }).then((response) => {
  220. this.tenantList = response.rows;
  221. });
  222. },
  223. //创建激活码
  224. crateCode() {
  225. this.$refs.form.validate((valid) => {
  226. if (valid) {
  227. createTenantCode(this.activationCode).then((response) => {
  228. this.activationCodeForm = true;
  229. this.actCode = response.msg;
  230. });
  231. } else {
  232. return false;
  233. }
  234. });
  235. },
  236. //激活码复制操作
  237. copyToClipboard() {
  238. //创建一个新 Clipboard 实例,将目标元素和复制成功时的回调传递给它
  239. const clipboard = new Clipboard("button", {
  240. text: () => this.actCode, //在这里替换为你要复制的文本
  241. });
  242. clipboard.on("success", () => {
  243. this.activationCodeForm = false;
  244. this.$message({
  245. showClose: true,
  246. message: "文本已成功复制到剪贴板",
  247. type: "success",
  248. });
  249. clipboard.destroy(); //清除 Clipboard 实例
  250. });
  251. clipboard.on("error", () => {
  252. console.error("复制失败");
  253. clipboard.destroy(); //清除 Clipboard 实例
  254. });
  255. //触发按钮点击事件,开始复制操作
  256. clipboard.onClick({
  257. action: "copy",
  258. });
  259. },
  260. //取消按钮
  261. cancel() {
  262. this.open = false;
  263. this.reset();
  264. },
  265. //激活码日志信息
  266. getCodeLogList() {
  267. this.loading = true;
  268. list(this.addDateRange(this.queryParams, this.dateRange)).then(
  269. (response) => {
  270. this.list = response.rows;
  271. this.total = response.total;
  272. this.loading = false;
  273. }
  274. );
  275. },
  276. /** 重置按钮操作 */
  277. resetQuery() {
  278. this.dateRange = [];
  279. this.resetForm("queryForm");
  280. this.queryParams.pageNum = 1;
  281. this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order);
  282. this.handleQuery();
  283. },
  284. /** 多选框选中数据 */
  285. handleSelectionChange(selection) {
  286. this.ids = selection.map((item) => item.logId);
  287. this.multiple = !selection.length;
  288. },
  289. /** 排序触发事件 */
  290. handleSortChange(column, prop, order) {
  291. this.queryParams.orderByColumn = column.prop;
  292. this.queryParams.isAsc = column.order;
  293. this.getList();
  294. },
  295. /** 搜索按钮操作 */
  296. handleQuery() {
  297. this.queryParams.pageNum = 1;
  298. this.getCodeLogList();
  299. },
  300. },
  301. };
  302. </script>