多媒体信息发布平台
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.

530 lines
17 KiB

  1. <template>
  2. <div class="list_warp">
  3. <el-row :gutter="15">
  4. <el-col>
  5. <!-- v-loading="crud.loading" -->
  6. <el-table ref="table" :data="urgentMessage" :header-cell-style="{ background: '#3a8aeb', color: '#fff' }" @selection-change="handleSelectionChange">
  7. <el-table-column type="selection" width="55" />
  8. <!-- prop="name" -->
  9. <el-table-column label="序号" type="index" align="center" width="50" />
  10. <el-table-column label="发布内容" align="center" prop="context" width="400">
  11. <template slot-scope="{ row }">
  12. <div>{{ row.context }}</div>
  13. </template>
  14. </el-table-column>
  15. <el-table-column label="通知时间" align="center" prop="create_time">
  16. <template slot-scope="{ row }">
  17. <div>{{ row.create_time | parseTime }}</div>
  18. </template>
  19. </el-table-column>
  20. <el-table-column label="发布人" align="center" prop="creater_name" />
  21. <el-table-column label="状态" align="center" prop="is_state">
  22. <template slot-scope="{ row }">
  23. <div :class="{ stop_txt: row.is_state }">
  24. {{ row.is_state == 1 ? "发布中" : "停止" }}
  25. </div>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="操作" width="120px" align="center" fixed="right">
  29. <template slot-scope="scope">
  30. <el-button type="primary" class="edit_btn" @click="editFormData(scope.row)">编辑</el-button>
  31. <el-button type="primary" :class="['start_btn', { stop_btn: scope.row.is_state == 1 }]" @click="isStopHandle(scope.$index, scope.row)">{{ scope.row.is_state == 1 ? "停止" : "恢复" }}</el-button>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. </el-col>
  36. </el-row>
  37. <!-- 分页器 -->
  38. <el-pagination style="margin-top: 20px;" background :current-page="queryInfo.page" :total="total" :page-size="queryInfo.size" :pager-count="5" :page-sizes="[3, 5, 10]" layout="prev, pager, next, jumper,->,sizes,total" @current-change="getUrgentMessage" @size-change="handleSizeChange" />
  39. <!-- 编辑紧急通知 -->
  40. <div class="publish_layer">
  41. <el-dialog :title="form.notice_id==null? '紧急发布':'编辑'" :close-on-click-modal="false" :show-close="false" :visible.sync="messageVisible" width="872px">
  42. <el-form ref="form" :model="form" size="small" label-width="100px">
  43. <el-form-item
  44. label="文本颜色"
  45. prop="context_color"
  46. :rules="[
  47. { required: true, message: '请选择文本颜色', trigger: '' },
  48. ]"
  49. >
  50. <colorPicker v-model="form.context_color" class="txt_color" @change="headleChangeColor" />
  51. <el-input v-show="false" v-model="form.context_color" />
  52. </el-form-item>
  53. <el-form-item
  54. label="文本内容"
  55. prop="context"
  56. :rules="[
  57. { required: true, message: '请输入文本内容', trigger: 'blur' },
  58. ]"
  59. >
  60. <el-input v-model="form.context" type="textarea" rows="6" style="width: 674px" />
  61. </el-form-item>
  62. <el-form-item
  63. label="文本大小"
  64. prop="context_size_name"
  65. :rules="[
  66. { required: true, message: '请选择文本大小', trigger: 'change' },
  67. ]"
  68. >
  69. <el-select v-model="form.context_size_name" size="small" class="filter-item" @change="selectSize">
  70. <el-option v-for="item in sizeData" :key="item.key" :label="item.name" :value="item" />
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item
  74. label="文本位置"
  75. prop="context_position_name"
  76. :rules="[
  77. { required: true, message: '请选择文本位置', trigger: 'change' },
  78. ]"
  79. >
  80. <el-select v-model="form.context_position_name" size="small" value-key="name" class="filter-item" @change="selectPosition">
  81. <el-option v-for="item in positionData" :key="item.key" :label="item.name" :value="item" />
  82. </el-select>
  83. </el-form-item>
  84. <el-form-item
  85. label="滚动速度"
  86. prop="context_speed_name"
  87. :rules="[
  88. { required: true, message: '请选择滚动速度', trigger: 'change' },
  89. ]"
  90. >
  91. <el-select v-model="form.context_speed_name" size="small" class="filter-item" @change="selectSpeed">
  92. <el-option v-for="item in speedData" :key="item.key" :label="item.name" :value="item" />
  93. </el-select>
  94. </el-form-item>
  95. <el-form-item
  96. label="选择设备"
  97. prop="notice_device"
  98. :rules="[
  99. { required: true, message: '请选择设备', trigger: 'change' },
  100. ]"
  101. >
  102. <el-radio-group v-model="form.notice_device" @change="clearCheckbox()">
  103. <el-radio :label="1" value="all">所有设备</el-radio>
  104. <el-radio :label="2" value="other">部分设备<i v-if="form.notice_device === 2" class="radio_tip" @click="addDeviceTag()">添加</i></el-radio>
  105. </el-radio-group>
  106. </el-form-item>
  107. <div v-if="form.notice_device == 1" class="select_all_tip">
  108. 所有设备都将被发送
  109. </div>
  110. <div v-if="deviceTags.length > 0 && form.notice_device == 2" class="select_other">
  111. <el-row>
  112. <el-col :span="10" class="other_tip">以下设备都将被发送<span>总计{{ deviceTags.length }}个设备</span></el-col>
  113. <el-col :span="4">
  114. <el-button round class="delt_btn" @click="clearDevice()">清空</el-button>
  115. </el-col>
  116. </el-row>
  117. <el-tag v-for="tag in deviceTags" :key="tag.device_id" closable :disable-transitions="true" :hit="false" context_color="#cbe3ff" @close="handleClose(tag)">
  118. {{ tag.device_name }}
  119. </el-tag>
  120. </div>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <!-- :loading="crud.status.cu === 2"
  124. @click="crud.submitCU"-->
  125. <el-button type="primary" round @click="submit">保存</el-button>
  126. <el-button round @click="closeDialog">关闭</el-button>
  127. </div>
  128. </el-dialog>
  129. </div>
  130. <!-- 添加发布的设备 -->
  131. <div class="add_device_layer">
  132. <el-dialog title="请选择设备" :close-on-click-modal="false" :visible.sync="selectDeviceVisible" width="400px">
  133. <el-tag v-for="tag in deviceList" :key="tag.device_id" :disable-transitions="true" :hit="false" color="#cbe3ff" class="all_tags" @click="tagHandle(tag)">
  134. {{ tag.device_name }}
  135. </el-tag>
  136. </el-dialog>
  137. </div>
  138. </div>
  139. </template>
  140. <script>
  141. import { parseTime } from '@/utils/index.js'
  142. import { ReqDeviceList } from '@/api/device/deviceList.js'
  143. import {
  144. reqUrgentMessage,
  145. reqQueryMessage,
  146. reqEditMessage,
  147. reqChangeMessage
  148. } from '@/api/publish/urgentMessage'
  149. export default {
  150. name: 'UrgentMessage',
  151. filters: {
  152. parseTime(time, cFormat) {
  153. return parseTime(time, cFormat)
  154. }
  155. },
  156. data() {
  157. return {
  158. isAddEdit: false,
  159. form: {
  160. context_color: '#ff0000', // 文本的颜色
  161. context: '', // 文本的内容
  162. context_position: null, // 文本的位置
  163. context_position_name: null,
  164. context_speed_name: null,
  165. context_speed: null, // 文本的速度
  166. context_size_name: null,
  167. context_size: null, // 文字的大小
  168. // create_by:'', //发布人
  169. notice_device: null,
  170. notice_devices: [],
  171. notice_id: '', // 紧急通知的id
  172. orga_id: '133221333123111'
  173. },
  174. queryInfo: {
  175. notice_name: '',
  176. orga_id: '133221333123111',
  177. page: 1,
  178. size: 10
  179. },
  180. total: 0,
  181. messageVisible: false,
  182. selectDeviceVisible: false,
  183. sizeData: [
  184. { key: 0, name: 16 },
  185. { key: 1, name: 22 },
  186. { key: 2, name: 24 },
  187. { key: 3, name: 30 }
  188. ],
  189. positionData: [
  190. { key: 1, name: '顶部' },
  191. { key: 2, name: '中间' },
  192. { key: 3, name: '底部' }
  193. ],
  194. speedData: [
  195. { key: 0, name: '1s' },
  196. { key: 1, name: '2s' },
  197. { key: 2, name: '3s' }
  198. ],
  199. selectedList: [],
  200. // 部分设备列表的数据
  201. deviceList: [],
  202. // newArr:[],
  203. deviceTags: [],
  204. // 紧急通知列表
  205. urgentMessage: []
  206. }
  207. },
  208. mounted() {
  209. this.getUrgentMessage()
  210. this.getDevice()
  211. },
  212. methods: {
  213. // 获取紧急通知的列表
  214. getUrgentMessage(pager = 1) {
  215. this.queryInfo.page = pager
  216. const params = this.queryInfo
  217. reqUrgentMessage(params).then((res) => {
  218. if (res.code == 200) {
  219. this.urgentMessage = res.data.content
  220. this.total = res.data.totalElements
  221. // console.log(this.urgentMessage);
  222. }
  223. })
  224. },
  225. // 获取设备列表的信息
  226. getDevice() {
  227. const params = this.queryInfo
  228. ReqDeviceList(params).then((res) => {
  229. if (res.code == 200) {
  230. this.deviceList = res.data.content
  231. } else {
  232. return this.$message.error('获取设备列表失败!')
  233. }
  234. })
  235. },
  236. // 紧急通知的状态 is_state为1 发布中 2 停止
  237. // row.is_state == 1 ? "停止" : "恢复"
  238. isStopHandle(index, row) {
  239. console.log(row)
  240. // console.log(index)
  241. if (row.is_state == 1) {
  242. row.is_state = 2
  243. } else {
  244. row.is_state = 1
  245. }
  246. const params = {
  247. id: row.notice_id,
  248. state: row.is_state
  249. }
  250. reqChangeMessage(params).then(res => {
  251. // console.log(res)
  252. if (res.code == 200) {
  253. if (params.state == 1) {
  254. this.$message({
  255. type: 'success',
  256. message: '已发布成功!'
  257. })
  258. } else {
  259. this.$message({
  260. type: 'success',
  261. message: '已停止!'
  262. })
  263. }
  264. } else {
  265. return this.$message.error('失败了~~~~')
  266. }
  267. })
  268. },
  269. // 编辑
  270. editFormData(row) {
  271. this.messageVisible = true
  272. // 根据id查询返回的紧急通知的数据
  273. const params = {
  274. notice_id: row.notice_id
  275. }
  276. reqQueryMessage(params).then((res) => {
  277. if (res.code == 200) {
  278. this.form.notice_device = res.data.notice.noticeDevice
  279. this.deviceTags = res.data.noticeDeviceDetailsVO
  280. this.form.context_color = res.data.notice.contextColor
  281. this.form.context = res.data.notice.context
  282. this.form.context_speed = res.data.notice.contextSpeed
  283. this.form.context_position = res.data.notice.contextPosition
  284. this.form.context_size = res.data.notice.contextSize
  285. this.form.notice_id = row.notice_id
  286. // 判断文字位置
  287. if (this.form.context_position == 1) {
  288. this.form.context_position_name = '顶部'
  289. } else if (this.form.context_position == 2) {
  290. this.form.context_position_name = '中部'
  291. } else {
  292. this.form.context_position_name = '底部'
  293. }
  294. // 判断速度
  295. if (this.form.context_speed == 0) {
  296. this.form.context_speed_name = '1s'
  297. } else if (this.form.context_speed == 1) {
  298. this.form.context_speed_name = '2s'
  299. } else {
  300. this.form.context_speed_name = '3s'
  301. }
  302. // 判断文字大小
  303. if (this.form.context_size == 0) {
  304. this.form.context_size_name = '16'
  305. } else if (this.form.context_size == 1) {
  306. this.form.context_size_name = '22'
  307. } else if (this.form.context_size == 2) {
  308. this.form.context_size_name = '24'
  309. } else {
  310. this.form.context_size_name = '30'
  311. }
  312. }
  313. })
  314. },
  315. // 新增
  316. addFormData() {
  317. this.messageVisible = true
  318. this.$nextTick(() => {
  319. this.form.notice_id = null
  320. })
  321. },
  322. // 提交
  323. submit() {
  324. this.$refs.form.validate((valid) => {
  325. console.log(this.deviceTags)
  326. console.log(this.form.notice_devices)
  327. if (this.form.notice_device == 2) {
  328. if (this.deviceTags.length != 0) {
  329. this.deviceTags.forEach(item => {
  330. this.form.notice_devices.push({ deviceId: item.device_id })
  331. })
  332. } else {
  333. this.$message.error('请添加设备!')
  334. return
  335. }
  336. }
  337. // 修改
  338. if (valid) {
  339. const params = {
  340. context: this.form.context,
  341. context_color: this.form.context_color,
  342. context_position: this.form.context_position,
  343. context_size: this.form.context_size,
  344. context_speed: this.form.context_speed,
  345. notice_device: this.form.notice_device,
  346. notice_devices: this.form.notice_devices,
  347. notice_id: this.form.notice_id,
  348. orga_id: '133221333123111'
  349. }
  350. console.log(params)
  351. reqEditMessage(params).then((res) => {
  352. if (res.code == 200) {
  353. this.$message({
  354. type: 'success',
  355. message: this.form.notice_id
  356. ? '修改紧急通知成功'
  357. : '添加紧急通知成功'
  358. })
  359. this.messageVisible = false
  360. this.$refs.form.resetFields()
  361. this.getUrgentMessage(this.queryInfo.page)
  362. }
  363. })
  364. }
  365. })
  366. },
  367. // 所有设备和部分设备的切换数据处理
  368. clearCheckbox() {
  369. if (this.form.notice_device == 1) {
  370. this.form.notice_devices = []
  371. }
  372. },
  373. // 多选框
  374. handleSelectionChange(val) {
  375. this.selectedList = val
  376. // if (val.length > 0) {
  377. // this.clearBtnDisabled = false;
  378. // } else {
  379. // this.clearBtnDisabled = true;
  380. // }
  381. },
  382. // 改变文字的颜色
  383. headleChangeColor() {
  384. this.form.context_size
  385. },
  386. // 改变文字的大小
  387. selectSize(selVal) {
  388. this.form.context_size = selVal.key
  389. this.form.context_size_name = selVal.name
  390. },
  391. // 改变文字的位置
  392. selectPosition(selVal) {
  393. console.log(selVal)
  394. this.form.context_position = selVal.key
  395. this.form.context_position_name = selVal.name
  396. },
  397. // 速度
  398. selectSpeed(selVal) {
  399. this.form.context_speed = selVal.key
  400. this.form.context_speed_name = selVal.name
  401. },
  402. // 添加设备的对话框
  403. addDeviceTag() {
  404. this.selectDeviceVisible = true
  405. },
  406. // 添加设备
  407. tagHandle(tag) {
  408. // 添加设备不能重复 不重复才添加
  409. if (this.deviceTags.length == 0) {
  410. this.deviceTags.push(tag)
  411. } else {
  412. const current =
  413. this.deviceTags &&
  414. this.deviceTags.some((item) => item.device_id == tag.device_id)
  415. if (!current) {
  416. this.deviceTags.push(tag)
  417. } else {
  418. this.$message('请勿添加重复的设备!')
  419. }
  420. }
  421. },
  422. // 单独删除某一个设备
  423. handleClose(tag) {
  424. this.deviceTags.splice(this.deviceTags.indexOf(tag), 1)
  425. },
  426. // 清空设备
  427. clearDevice() {
  428. this.deviceTags = []
  429. this.form.notice_devices = []
  430. },
  431. // 关闭重置表单
  432. closeDialog() {
  433. this.messageVisible = false
  434. this.$refs.form.resetFields()
  435. },
  436. // 每条显示数据改变时的事件
  437. handleSizeChange(size) {
  438. // 整理参数
  439. this.queryInfo.size = size
  440. this.getUrgentMessage()
  441. }
  442. }
  443. }
  444. </script>
  445. <style lang="scss" scoped>
  446. .list_warp {
  447. padding: 0 24px;
  448. .stop_txt {
  449. color: #3a8aeb;
  450. }
  451. }
  452. .txt_color {
  453. margin-top: 12px;
  454. }
  455. ::v-deep .el-radio-group {
  456. display: block;
  457. .el-radio {
  458. position: relative;
  459. line-height: 40px;
  460. .radio_tip {
  461. position: absolute;
  462. right: -45px;
  463. top: 0;
  464. display: block;
  465. width: 42px;
  466. height: 21px;
  467. line-height: 21px;
  468. font-size: 12px;
  469. text-align: center;
  470. color: #fff;
  471. background: url(~@/assets/images/an-tj.png) no-repeat;
  472. background-size: 42px 21px;
  473. }
  474. }
  475. }
  476. .select_all_tip {
  477. width: 336px;
  478. height: 32px;
  479. line-height: 32px;
  480. margin: -20px 0 0 100px;
  481. padding: 0 14px;
  482. font-size: 12px;
  483. color: #999;
  484. background: #fff;
  485. box-shadow: 0 0 5px rgba(0, 0, 0, 0.14);
  486. }
  487. .select_other {
  488. width: 600px;
  489. margin: -20px 0 0 100px;
  490. padding: 18px 23px;
  491. background: #f8f8f8;
  492. border: 1px solid #dcdde3;
  493. border-radius: 4px;
  494. .other_tip {
  495. line-height: 24px;
  496. span {
  497. display: inline-block;
  498. margin-left: 20px;
  499. }
  500. }
  501. .el-button {
  502. padding: 5px 8px;
  503. border: none !important;
  504. }
  505. .delt_btn {
  506. color: #fff;
  507. background-color: #ee5747 !important;
  508. }
  509. }
  510. .el-tag--small {
  511. height: 28px;
  512. line-height: 26px;
  513. padding: 0 24px;
  514. margin: 18px 16px 0 0;
  515. font-size: 14px;
  516. // color: #3a8aeb;
  517. ::v-deep .el-icon-close {
  518. font-size: 16px;
  519. }
  520. }
  521. .add_device_layer {
  522. ::v-deep .el-dialog__body {
  523. padding: 0 20px 30px 20px;
  524. }
  525. }
  526. </style>