index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. :inline="true"
  7. v-show="showSearch"
  8. >
  9. <el-form-item label="KEY" prop="groupKey">
  10. <el-input
  11. v-model="queryParams.groupKey"
  12. placeholder="请输入用户key"
  13. clearable
  14. size="small"
  15. @keyup.enter.native="handleQuery"
  16. />
  17. </el-form-item>
  18. <el-form-item label="分组名称" prop="groupName">
  19. <el-input
  20. v-model="queryParams.groupName"
  21. placeholder="请输入分组名称"
  22. clearable
  23. size="small"
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <el-form-item label="是否可用" prop="enabled">
  28. <el-select
  29. v-model="queryParams.enabled"
  30. placeholder="请选择"
  31. clearable
  32. size="small"
  33. >
  34. <el-option label="可用" :value="true"> </el-option>
  35. <el-option label="禁用" :value="true"> </el-option>
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button
  40. type="cyan"
  41. icon="el-icon-search"
  42. size="mini"
  43. @click="handleQuery"
  44. >搜索</el-button
  45. >
  46. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  47. >重置</el-button
  48. >
  49. </el-form-item>
  50. </el-form>
  51. <el-row :gutter="10" class="mb8">
  52. <el-col :span="1.5">
  53. <el-button
  54. type="primary"
  55. icon="el-icon-plus"
  56. size="mini"
  57. @click="handleAdd"
  58. >新增</el-button
  59. >
  60. </el-col>
  61. <right-toolbar
  62. :showSearch.sync="showSearch"
  63. @queryTable="getList"
  64. ></right-toolbar>
  65. </el-row>
  66. <el-table v-loading="loading" :data="keyList">
  67. <el-table-column
  68. prop="groupKey"
  69. label="用户KEY"
  70. width="200"
  71. ></el-table-column>
  72. <el-table-column prop="groupName" label="分组名称"></el-table-column>
  73. <el-table-column label="是否可用" align="center" prop="enabled">
  74. <template slot-scope="scope">
  75. <span>{{ scope.row.enabled ? "可用" : "禁用" }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column
  79. label="操作"
  80. align="center"
  81. class-name="small-padding fixed-width"
  82. >
  83. <template slot-scope="scope">
  84. <el-button
  85. size="mini"
  86. type="text"
  87. icon="el-icon-view"
  88. @click="handleLook(scope.row)"
  89. >查看日志</el-button
  90. >
  91. <el-button
  92. size="mini"
  93. type="text"
  94. icon="el-icon-s-promotion"
  95. @click="handleSend(scope.row)"
  96. >发送日志</el-button
  97. >
  98. <el-button
  99. size="mini"
  100. type="text"
  101. icon="el-icon-edit"
  102. @click="handleUpdate(scope.row)"
  103. >修改</el-button
  104. >
  105. <div style="width: 10px; display: inline-block"></div>
  106. <el-popconfirm
  107. title="确定删除吗?"
  108. @confirm="handleDelete(scope.row)"
  109. >
  110. <el-button
  111. size="mini"
  112. type="text"
  113. icon="el-icon-delete"
  114. slot="reference"
  115. >删除</el-button
  116. >
  117. </el-popconfirm>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <pagination
  122. v-show="total > 0"
  123. :total="total"
  124. :page.sync="queryParams.pageNum"
  125. :limit.sync="queryParams.pageSize"
  126. @pagination="getList"
  127. />
  128. <!-- 新增或修改 -->
  129. <el-dialog
  130. :title="title"
  131. :visible.sync="openScope"
  132. width="550px"
  133. append-to-body
  134. >
  135. <el-form
  136. :model="form"
  137. label-width="80px"
  138. label-position="top"
  139. :rules="rules"
  140. ref="form"
  141. >
  142. <el-row :gutter="20">
  143. <el-col :span="12">
  144. <el-form-item label="分组名称" prop="groupName">
  145. <el-input
  146. v-model="form.groupName"
  147. placeholder="请输入分组名称"
  148. clearable
  149. size="small"
  150. />
  151. </el-form-item>
  152. </el-col>
  153. <el-col :span="12">
  154. <el-form-item label="分组KEY" prop="groupKey">
  155. <el-input
  156. v-model="form.groupKey"
  157. placeholder="请输入分组KEY"
  158. clearable
  159. size="small"
  160. :disabled="title === '修改消息分组'"
  161. />
  162. </el-form-item>
  163. </el-col>
  164. </el-row>
  165. <el-row :gutter="20">
  166. <el-col :span="16">
  167. <!-- <el-form-item label="归属部门" prop="deptList">
  168. <treeselect
  169. v-model="form.deptList"
  170. :options="deptOptions"
  171. :disable-branch-nodes="true"
  172. :show-count="true"
  173. :normalizer="normalizer"
  174. multiple
  175. placeholder="请选择归属部门"
  176. />
  177. </el-form-item> -->
  178. <el-form-item label="归属部门" prop="deptList">
  179. <el-tree
  180. :data="deptOptions"
  181. show-checkbox
  182. ref="deptRef"
  183. node-key="deptId"
  184. check-strictly
  185. default-expand-all
  186. empty-text="加载中,请稍后"
  187. :props="defaultProps"
  188. @check="handleCheckChange"
  189. ></el-tree>
  190. </el-form-item>
  191. </el-col>
  192. <el-col :span="8">
  193. <el-form-item label="是否可用" prop="enabled">
  194. <el-switch v-model="form.enabled" />
  195. </el-form-item>
  196. </el-col>
  197. </el-row>
  198. <el-form-item label="用户" prop="userList">
  199. <el-transfer
  200. class="transfer"
  201. filterable
  202. filter-placeholder="请输入组员"
  203. v-model="form.userList"
  204. :titles="['所有人', '组员']"
  205. :data="userList"
  206. >
  207. </el-transfer>
  208. </el-form-item>
  209. </el-form>
  210. <div slot="footer" class="dialog-footer">
  211. <el-button type="primary" @click="submitScope">确 定</el-button>
  212. <el-button @click="cancelScope">取 消</el-button>
  213. </div>
  214. </el-dialog>
  215. <!-- 日志 -->
  216. <el-dialog
  217. title="日志"
  218. :visible.sync="logOpen"
  219. width="750px"
  220. append-to-body
  221. >
  222. <el-table :data="logData" :loading="logLoading" style="width: 100%" max-height="450">
  223. <el-table-column prop="msgContext" label="发送消息"/>
  224. <el-table-column prop="createTime" label="创建时间"/>
  225. <el-table-column prop="sendTime" label="发送时间"/>
  226. </el-table>
  227. <pagination
  228. v-show="logTotal > 0"
  229. :total="logTotal"
  230. :page.sync="formLog.pageNum"
  231. :limit.sync="formLog.pageSize"
  232. @pagination="getLogList"
  233. />
  234. <div slot="footer" class="dialog-footer">
  235. <el-button @click="logOpen = false">取 消</el-button>
  236. </div>
  237. </el-dialog>
  238. </div>
  239. </template>
  240. <script>
  241. import {
  242. getUserKeyList,
  243. addUserKey,
  244. editUserKey,
  245. delUserKey,
  246. sendMassage,
  247. lookLog,
  248. } from "@/api/system/userKey";
  249. import { listDept } from "@/api/system/dept";
  250. import { allUser } from "@/api/system/user";
  251. import Treeselect from "@riophae/vue-treeselect";
  252. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  253. export default {
  254. name: "UserKey",
  255. components: { Treeselect },
  256. data() {
  257. return {
  258. normalizer(node) {
  259. return {
  260. id: node.deptId,
  261. label: node.deptName,
  262. children: node.children,
  263. };
  264. },
  265. // 查询参数
  266. queryParams: {
  267. pageSize: 20,
  268. pageNum: 1,
  269. },
  270. // 显示搜索条件
  271. showSearch: true,
  272. // loading
  273. loading: false,
  274. // 新增修改dailogtitle
  275. title: "",
  276. // 新增参数
  277. form: { enabled: true },
  278. // 控制新增弹窗
  279. openScope: false,
  280. // 表单校验
  281. rules: {
  282. groupName: [
  283. { required: true, message: "分组名称不能为空", trigger: "blur" },
  284. ],
  285. groupKey: [
  286. { required: true, message: "用户key不能为空", trigger: "blur" },
  287. ],
  288. },
  289. // 表格数据
  290. keyList: [],
  291. // 列表个数
  292. total: 0,
  293. // 绑定表格数据
  294. userList: [],
  295. // 保存选中的人员
  296. selectionUsers: [],
  297. // 保存点击绑定人员的keyID
  298. keyId: null,
  299. //
  300. selectUserList: [],
  301. // 部门树选项
  302. deptOptions: undefined,
  303. // 获取日志参数
  304. formLog: {
  305. pageSize: 20,
  306. pageNum: 1,
  307. msgGroupId: null,
  308. },
  309. // 查看日志弹窗控制
  310. logOpen: false,
  311. // 日志数据
  312. logData: [],
  313. logLoading: false,
  314. logTotal: 0,
  315. defaultProps: {
  316. children: "children",
  317. label: "deptName",
  318. value: 'deptId'
  319. }
  320. };
  321. },
  322. created() {
  323. this.getTreeselect();
  324. this.getList();
  325. this.getUserList();
  326. },
  327. methods: {
  328. cancelMenu() {
  329. if (this.$refs.deptRef != undefined) {
  330. this.$refs.deptRef.setCheckedKeys([]);
  331. }
  332. },
  333. /** 归属岗位 */
  334. handleCheckChange(checkedNode, checkedKeys) {
  335. console.log(checkedNode, checkedKeys);
  336. this.$set(this.form, 'deptList', checkedKeys.checkedKeys)
  337. },
  338. // 所有菜单节点数据
  339. getMenuAllCheckedKeys() {
  340. // 目前被选中的菜单节点
  341. let checkedKeys = [], halfCheckedKeys = []
  342. if (this.$refs.deptRef != undefined) {
  343. checkedKeys = this.$refs.deptRef.getHalfCheckedKeys();
  344. halfCheckedKeys = this.$refs.deptRef.getCheckedKeys();
  345. }
  346. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  347. return [...checkedKeys];
  348. },
  349. /** 查看日志 */
  350. handleLook(row) {
  351. this.formLog = {
  352. ...this.formLog,
  353. msgGroupId: row.id,
  354. };
  355. this.logOpen = true;
  356. this.getLogList();
  357. },
  358. /** 获取日志 */
  359. getLogList() {
  360. this.logLoading = true;
  361. lookLog(this.formLog).then((res) => {
  362. this.logData = res.data.records;
  363. this.logLoading = false;
  364. this.logTotal = res.data.total
  365. });
  366. },
  367. /** 查询部门下拉树结构 */
  368. getTreeselect() {
  369. listDept().then((response) => {
  370. this.deptOptions = this.changeTree(response.data);
  371. });
  372. },
  373. changeTree(tree) {
  374. if (Array.isArray(tree) && tree.length > 0) {
  375. let tre = tree.map((item) => {
  376. let { children, ...ite } = item;
  377. if (children.length > 0) {
  378. let ee = this.changeTree(children);
  379. return {
  380. children: ee,
  381. ...ite,
  382. };
  383. } else {
  384. return ite;
  385. }
  386. });
  387. return tre;
  388. } else {
  389. return tree;
  390. }
  391. },
  392. /** 搜索 */
  393. handleQuery() {
  394. let { startTime, endTime } = this.queryParams;
  395. if (startTime) {
  396. startTime = this.parserTime(startTime);
  397. }
  398. if (endTime) {
  399. endTime = this.parserTime(endTime);
  400. }
  401. this.queryParams = { ...this.queryParams, startTime, endTime };
  402. this.getList();
  403. },
  404. /** 时间转换 */
  405. parserTime(time) {
  406. const d = new Date(time);
  407. const resDate =
  408. d.getFullYear() +
  409. "-" +
  410. this.p(d.getMonth() + 1) +
  411. "-" +
  412. this.p(d.getDate());
  413. return resDate;
  414. },
  415. p(s) {
  416. return s < 10 ? "0" + s : s;
  417. },
  418. /** 重置 */
  419. resetQuery() {
  420. this.resetForm("queryForm");
  421. this.handleQuery();
  422. },
  423. /** 新增 */
  424. handleAdd() {
  425. this.form = { enabled: true }
  426. this.getTreeselect();
  427. this.openScope = true;
  428. this.title = "新增消息分组";
  429. },
  430. /** 查询菜单列表 */
  431. getList() {
  432. this.loading = true;
  433. getUserKeyList(this.queryParams).then((response) => {
  434. this.keyList = response.data.records;
  435. this.total = response.data.total;
  436. this.loading = false;
  437. });
  438. },
  439. /** 新增弹窗确定 */
  440. submitScope() {
  441. this.$refs["form"].validate((valid) => {
  442. if (valid) {
  443. if (this.form.id != undefined) {
  444. console.log(this.form);
  445. editUserKey(this.form).then((response) => {
  446. if (response.data) {
  447. this.msgSuccess("修改成功");
  448. this.openScope = false;
  449. this.form = {};
  450. this.getList();
  451. this.cancelMenu()
  452. }
  453. });
  454. } else {
  455. addUserKey(this.form).then((response) => {
  456. if (response.data) {
  457. this.msgSuccess("新增成功");
  458. this.openScope = false;
  459. this.form = {};
  460. this.getList();
  461. this.cancelMenu()
  462. }
  463. });
  464. }
  465. }
  466. });
  467. },
  468. /** 新增弹窗取消 */
  469. cancelScope() {
  470. this.form = { enabled: true };
  471. this.openScope = false;
  472. this.cancelMenu()
  473. },
  474. /** 修改数据 */
  475. handleUpdate(row) {
  476. console.log(row.deptList);
  477. this.getTreeselect();
  478. this.$nextTick(()=>{
  479. setTimeout(() => {
  480. if (row.deptList) {
  481. row.deptList.forEach((element) => {
  482. let node = this.$refs.deptRef.getNode(element);
  483. console.log(node.isLeaf);
  484. // if (node.isLeaf) {
  485. this.$refs.deptRef.setChecked(node, true);
  486. // }
  487. });
  488. }
  489. }, 100)
  490. })
  491. this.form = { ...row };
  492. this.openScope = true;
  493. this.title = "修改消息分组";
  494. },
  495. /** 发送日志 */
  496. handleSend(row) {
  497. this.$prompt('请输入"' + row.groupName + '"要发的消息', "提示", {
  498. confirmButtonText: "确定",
  499. cancelButtonText: "取消",
  500. })
  501. .then(({ value }) => {
  502. sendMassage(row.id, value).then((response) => {
  503. if (response.code === 200) {
  504. this.msgSuccess("发送成功,发送的消息是:" + value);
  505. }
  506. });
  507. })
  508. .catch((e) => {
  509. console.log(e);
  510. });
  511. },
  512. /** 删除数据 */
  513. handleDelete(row) {
  514. console.log(row.id);
  515. delUserKey(row.id).then((res) => {
  516. if (res.data) {
  517. this.msgSuccess("删除成功");
  518. this.getList();
  519. }
  520. });
  521. },
  522. /** 获取人员 */
  523. getUserList() {
  524. allUser().then((res) => {
  525. this.selectUserList = res.data.map((item) => ({
  526. id: item.userId,
  527. name: item.nickname,
  528. remark: item.remark,
  529. }));
  530. let resData = res.data.filter((item) => item.userId !== 0);
  531. this.userList = resData.map((item) => ({
  532. key: item.userId,
  533. label: item.nickname,
  534. }));
  535. });
  536. },
  537. },
  538. };
  539. </script>
  540. <style lang="scss">
  541. .transfer {
  542. & > .el-transfer__buttons {
  543. display: inline-flex !important;
  544. flex-direction: column !important;
  545. padding: 0 10px !important;
  546. .el-button + .el-button {
  547. margin-left: 0;
  548. }
  549. }
  550. }
  551. </style>