【前端】智能库房综合管理系统前端项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

488 lines
16 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div>
  3. <div class="head-container">
  4. <el-button class="iconfont icon-fabu-fanbai" size="mini" @click="handleSend">发布</el-button>
  5. <el-button icon="el-icon-edit" size="mini" :disabled="!(selections.length === 1)" @click="handleEdit">修改</el-button>
  6. <el-button icon="el-icon-delete" size="mini" :disabled="!selections.length" @click="handleDel">删除</el-button>
  7. </div>
  8. <div class="app-container container-wrap">
  9. <span class="right-top-line" />
  10. <span class="left-bottom-line" />
  11. <!--表格渲染-->
  12. <el-table
  13. ref="table"
  14. v-loading="isLoading"
  15. :default-sort="{prop: 'create_time', order: 'descending'}"
  16. :data="tableData"
  17. style="width: 100%;"
  18. height="calc(100vh - 294px)"
  19. @row-click="clickRowHandler"
  20. @selection-change="selectionChangeHandler"
  21. >
  22. <el-table-column type="selection" width="55" align="center" />
  23. <el-table-column type="index" label="序号" width="100" align="center" />
  24. <el-table-column prop="noticeContent" :show-overflow-tooltip="true" label="通知内容" min-width="200" align="center" />
  25. <el-table-column prop="noticeType" label="消息类型" align="center" min-width="150">
  26. <!-- <span v-if="scope.row.noticeType===1">系统消息</span> -->
  27. <span>系统消息</span>
  28. </el-table-column>
  29. <el-table-column prop="pushTo" :show-overflow-tooltip="true" label="推送对象" align="center" min-width="150">
  30. <template slot-scope="scope">
  31. <span v-if="typeof(scope.row.pushTo)==='string'">{{ scope.row.pushTo }}</span>
  32. <div v-if="!(typeof(scope.row.pushTo)==='string')" class="tag-hidden">
  33. <!-- <el-tag v-for="(item,i) in scope.row.pushTo" :key="i" style="margin-left:3px;color: #fff">{{ item }}</el-tag> -->
  34. {{ scope.row.pushTo.join(',') }}
  35. </div>
  36. </template>
  37. </el-table-column>
  38. <el-table-column prop="update_by" label="推送人" align="center" min-width="150" />
  39. <el-table-column prop="create_time" :sortable="true" label="推送时间" align="center" min-width="180">
  40. <template slot-scope="scope">
  41. <div>{{ scope.row.create_time | parseTime }}</div>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. <el-pagination
  46. :page-size.sync="page.size"
  47. :total="page.total"
  48. :current-page.sync="page.page"
  49. style="margin-top: 8px;"
  50. layout="total, prev, pager, next, sizes"
  51. @size-change="sizeChangeHandler($event)"
  52. @current-change="pageChangeHandler"
  53. />
  54. <!-- 发布 -->
  55. <el-dialog append-to-body :close-on-click-modal="false" :visible.sync="sendVisible" title="发布通知" @close="handleClose">
  56. <span class="dialog-right-top" />
  57. <span class="dialog-left-bottom" />
  58. <div class="setting-dialog">
  59. <el-form ref="formDom" :rules="rules" :model="sendForm" size="small" label-width="80px" style="margin-left:85px">
  60. <el-form-item label="消息类型" prop="msgType" class="down-select">
  61. <el-select v-model="noticeType" placeholder="请选择" style="width:315px">
  62. <el-option
  63. v-for="item in msgTypeOptions"
  64. :key="item.name"
  65. :label="item.label"
  66. :value="item.value"
  67. :disabled="item.disabled"
  68. />
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="发布内容" prop="notification" style="margin-bottom:8px">
  72. <textarea v-model="sendForm.notification" cols="38" rows="6" />
  73. </el-form-item>
  74. <el-form-item label="推送对象" prop="">
  75. <el-radio-group v-model="pushObj" @change="pushObjChange">
  76. <el-radio label="用户">用户</el-radio>
  77. <el-radio label="设备">设备</el-radio>
  78. </el-radio-group>
  79. </el-form-item>
  80. <el-form-item label="选择对象" prop="paramName">
  81. <el-select ref="selectBox" v-model="selectOptions" multiple :collapse-tags="showTags" clearable placeholder="请选择" style="width:315px" @change="changeSelect">
  82. <!-- <el-option key="全选" label="全选" value="全选" /> -->
  83. <el-option v-for="item in sendObjOptions" :key="item.value" :label="item.label" :value="item.value" />
  84. </el-select>
  85. </el-form-item>
  86. </el-form>
  87. <div slot="footer" class="dialog-footer">
  88. <el-button v-loading="btnloading" type="primary" @click="handleSave">保存</el-button>
  89. </div>
  90. </div>
  91. </el-dialog>
  92. <!-- 删除 -->
  93. <el-dialog :visible.sync="delVisible" title="提示">
  94. <span class="dialog-right-top" />
  95. <span class="dialog-left-bottom" />
  96. <div class="setting-dialog">
  97. <p class="delMsg">确定删除所选消息吗</p>
  98. <div slot="footer" class="dialog-footer">
  99. <el-button type="primary" @click="handleDelConfirm">确定</el-button>
  100. </div>
  101. </div>
  102. </el-dialog>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. import { noticeCreate, getAllDev, getAllUser, getNoticeList, noticeDel } from '@/api/system/logs'
  108. export default {
  109. name: 'NotifyManage',
  110. inject: ['reload'],
  111. data() {
  112. return {
  113. isLoading: false,
  114. tableData: [],
  115. selections: [],
  116. sendVisible: false,
  117. delVisible: false,
  118. sendForm: {
  119. // msgType: 1,
  120. notification: '',
  121. // pushObj: '用户',
  122. sendObj: ['全选']
  123. },
  124. pushObj: '用户',
  125. checked: '',
  126. noticeType: 1,
  127. msgTypeOptions: [
  128. { value: 1, label: '系统通知' }
  129. // { value: 2, label: '报警消息', disabled: true },
  130. // { value: 3, label: '借还消息', disabled: true },
  131. // { value: 4, label: '下载消息', disabled: true }
  132. ],
  133. userOptions: [],
  134. devOptions: [],
  135. selectOptions: [],
  136. oldSelect: null,
  137. showTags: true,
  138. rules: {
  139. // msgType: [
  140. // { required: true, message: '请选择类型', trigger: 'blur' }
  141. // ],
  142. notification: [
  143. { required: true, message: '请填写内容', trigger: 'blur' }
  144. ],
  145. pushObj: [
  146. { required: true, message: '请选择推送对象', trigger: 'blur' }
  147. ]
  148. },
  149. allUser: null,
  150. allDev: null,
  151. page: {
  152. total: 0,
  153. size: 10,
  154. page: 1
  155. },
  156. btnloading: false,
  157. isEdit: null
  158. }
  159. },
  160. computed: {
  161. sendObjOptions() {
  162. if (this.pushObj === '用户') {
  163. return this.userOptions
  164. } else {
  165. return this.devOptions
  166. }
  167. }
  168. },
  169. async created() {
  170. await this.getUser()
  171. await this.getDev()
  172. this.getTableData()
  173. },
  174. methods: {
  175. getParams() {
  176. const params = {
  177. page: null,
  178. size: null,
  179. sort: 'createTime,desc'
  180. }
  181. params.page = this.page.page - 1
  182. params.size = this.page.size
  183. return params
  184. },
  185. getTableData() {
  186. this.isLoading = true
  187. getNoticeList(this.getParams()).then(res => { // 获取列表
  188. console.log(res, 'res')
  189. const table = res.content
  190. this.page.total = res.totalElements
  191. table.forEach(item => {
  192. item.pushTo = null
  193. item.pushVal = null
  194. if (item.pushType === 2) { // 推送对象为设备
  195. item.pushVal = item.noticeDevices.map(i => { return i.deviceInfoId })
  196. item.pushTo = item.noticeDevices.map(i => {
  197. let dev = null
  198. this.devOptions.forEach(val => {
  199. if (val.value === i.deviceInfoId) {
  200. dev = val.label
  201. }
  202. })
  203. return dev
  204. })
  205. } else if (item.pushType === 1) { // 推送对象为用户
  206. item.pushVal = item.noticeUsers.map(i => { return i.userId })
  207. item.pushTo = item.noticeUsers.map(i => {
  208. let user = null
  209. this.userOptions.forEach(val => {
  210. if (val.value === i.userId) {
  211. user = val.label
  212. }
  213. })
  214. return user
  215. })
  216. }
  217. // 去重
  218. const arrTo = []
  219. const arrVal = []
  220. item.pushTo.forEach(i => {
  221. if (arrTo.indexOf(i) === -1 && i !== null) {
  222. arrTo.push(i)
  223. }
  224. })
  225. item.pushVal.forEach(i => {
  226. if (arrVal.indexOf(i) === -1 && i !== null) {
  227. arrVal.push(i)
  228. }
  229. })
  230. item.pushVal = arrVal
  231. if (item.pushType === 1) { // 用户
  232. item.pushTo = arrVal.length === this.userOptions.length - 1 ? '全部用户' : arrTo
  233. } else {
  234. item.pushTo = arrVal.length === this.devOptions.length - 1 ? '全部设备' : arrTo
  235. }
  236. })
  237. this.tableData = table
  238. this.isLoading = false
  239. })
  240. },
  241. // 获取用户
  242. async getUser() {
  243. await getAllUser().then(res => {
  244. const arr0 = [{ value: 0, label: '全部用户' }]
  245. const arr = res.map(item => {
  246. const val = item.id
  247. const lab = item.dept.name + '-' + item.username
  248. const obj = {
  249. value: val,
  250. label: lab
  251. }
  252. return obj
  253. })
  254. this.userOptions = arr0.concat(arr)
  255. })
  256. },
  257. // 获取设备
  258. async getDev() {
  259. await getAllDev().then(res => {
  260. const arr0 = [{ value: 0, label: '全部设备' }]
  261. const arr = res.map(item => {
  262. const val = item.id
  263. const lab = item.deviceName
  264. const obj = {
  265. value: val,
  266. label: lab
  267. }
  268. return obj
  269. })
  270. this.devOptions = arr0.concat(arr)
  271. })
  272. },
  273. // 每页条数改变
  274. sizeChangeHandler(e) {
  275. this.loading = true
  276. this.page.size = e
  277. this.page.page = 1
  278. this.getTableData()
  279. this.loading = false
  280. },
  281. // 当前页改变
  282. pageChangeHandler(e) {
  283. this.loading = true
  284. this.page.page = e
  285. this.getTableData()
  286. this.loading = false
  287. },
  288. clickRowHandler(row) {
  289. // this.$refs.table.clearSelection()
  290. this.$refs.table.toggleRowSelection(row) // 单选选中
  291. },
  292. selectionChangeHandler(val) {
  293. this.selections = val
  294. console.log(val)
  295. },
  296. // 发布
  297. handleSend() {
  298. this.defaultSelAll()
  299. this.isEdit = false
  300. this.sendVisible = true
  301. },
  302. // 修改
  303. handleEdit() {
  304. this.isEdit = true
  305. this.sendForm.notification = this.selections[0].noticeContent
  306. const temp = this.selections[0].pushVal
  307. if (this.selections[0].pushType === 1) {
  308. this.pushObj = '用户'
  309. this.selectOptions = temp.length === this.userOptions.length - 1 ? [0, ...temp] : temp
  310. } else {
  311. this.pushObj = '设备'
  312. this.selectOptions = temp.length === this.devOptions.length - 1 ? [0, ...temp] : temp
  313. }
  314. this.sendVisible = true
  315. },
  316. // 保存
  317. handleSave() {
  318. this.$refs.formDom.validate((valid) => {
  319. if (valid) {
  320. this.noticeSend(this.getPushParams())
  321. } else {
  322. return false
  323. }
  324. })
  325. },
  326. getPushParams() { // 发布消息参数
  327. const params = {}
  328. params.noticeType = this.noticeType
  329. params.noticeContent = this.sendForm.notification
  330. //* ************** */
  331. if (this.pushObj === '用户') { // 选择用户
  332. params.pushType = 1
  333. params.userId = this.selectOptions.filter(item => item !== 0)
  334. } else { // 选择设备
  335. params.pushType = 2
  336. params.deviceInfoId = this.selectOptions.filter(item => item !== 0)
  337. }
  338. if (this.isEdit) {
  339. params.id = this.selections[0].id
  340. }
  341. console.log(params, '参数')
  342. return params
  343. },
  344. // 调用发布接口
  345. noticeSend(params) {
  346. noticeCreate(params).then(res => {
  347. if (res === 'SUCCESS') {
  348. this.btnloading = false
  349. this.sendVisible = false
  350. // this.getTableData()
  351. this.reload()
  352. this.$message({
  353. message: '发布成功',
  354. type: 'success'
  355. })
  356. this.$refs.formDom.resetFields()
  357. this.$refs.formDom.clearValidate()
  358. } else {
  359. this.btnloading = false
  360. this.$message.error('发布失败')
  361. }
  362. })
  363. },
  364. handleClose() {
  365. this.$refs.formDom.resetFields()
  366. this.$refs.formDom.clearValidate()
  367. this.sendForm.notification = ''
  368. this.pushObj = '用户'
  369. this.noticeType = 1
  370. },
  371. // 删除
  372. handleDel() {
  373. this.delVisible = true
  374. },
  375. // 删除确认
  376. handleDelConfirm() {
  377. const params = this.selections.map(item => { return item.id })
  378. noticeDel(params).then(res => {
  379. if (res === 'SUCCESS') {
  380. // this.getTableData()
  381. this.delVisible = false
  382. this.reload()
  383. this.$message({
  384. message: '删除成功',
  385. type: 'success'
  386. })
  387. } else {
  388. this.$message.error('删除失败')
  389. }
  390. })
  391. },
  392. // 选择器 推送对象
  393. handelChange(val) {
  394. if (val.length === this.sendObjOptions.length) {
  395. this.checked = true
  396. } else {
  397. this.checked = false
  398. }
  399. },
  400. // 默认全选
  401. defaultSelAll() {
  402. this.selectOptions = this.sendObjOptions.map(item => { return item.value })
  403. this.oldSelect = this.selectOptions
  404. this.showTags = true
  405. },
  406. changeSelect(val) {
  407. if (val[val.length - 1] === 0) { // 选中全选
  408. this.defaultSelAll()
  409. this.$refs.selectBox.$el.querySelector('.el-input__inner').style.height = '34px'
  410. } else {
  411. const arr1 = this.oldSelect.filter(item => item !== 0)
  412. const arr2 = val.filter(item => item !== 0)
  413. if (arr1.length === arr2.length) { // 取消全选
  414. this.selectOptions = []
  415. } else if (arr1.length < arr2.length && arr2.length === this.sendObjOptions.length - 1) {
  416. this.defaultSelAll() // 除全选时都选中 此时加入全选
  417. this.$refs.selectBox.$el.querySelector('.el-input__inner').style.height = '34px'
  418. } else {
  419. this.selectOptions = this.selectOptions.filter(item => item !== 0) // 取消其他选项时 去除全选
  420. this.showTags = false
  421. }
  422. this.oldSelect = this.selectOptions
  423. }
  424. },
  425. pushObjChange(val) {
  426. if (val) {
  427. this.defaultSelAll()
  428. this.showTags = true
  429. }
  430. }
  431. }
  432. }
  433. </script>
  434. <style lang="scss" scoped>
  435. @import '~@/assets/styles/lend-manage.scss';
  436. .head-container{
  437. padding-bottom: 0;
  438. }
  439. .container-wrap{
  440. min-height: calc(100vh - 242px)
  441. }
  442. textarea{
  443. background-color: #021941;
  444. border: 1px solid #339CFF;
  445. border-radius: 3px;
  446. &:focus{
  447. outline: none;
  448. }
  449. caret-color: #fff;
  450. color: #fff;
  451. padding: 10px 12px;
  452. font-size: 14px;
  453. }
  454. ::v-deep .el-radio-group{
  455. width: 315px;
  456. height: 32px;
  457. border: 1px solid #339CFF;
  458. border-radius: 3px;
  459. padding-left: 14px;
  460. display: flex;
  461. label{
  462. display: flex;
  463. align-items: center;
  464. margin-right: 50px;
  465. span{
  466. color: #3A99FD;
  467. margin-left: 10px;
  468. }
  469. }
  470. }
  471. .el-checkbox{
  472. display: flex;
  473. justify-content: right;
  474. align-items: center;
  475. padding-right: 20px;
  476. }
  477. ::v-deep .el-form-item__error{
  478. top: 93%;
  479. }
  480. .tag-hidden{
  481. width: 100%;
  482. overflow: hidden;
  483. text-overflow:ellipsis;
  484. white-space: nowrap;
  485. }
  486. </style>