index.vue 8.4 KB

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