RiskTipDialog.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <vue-drag-resize
  3. id="drag"
  4. class="drag-container"
  5. :isActive="true"
  6. w="auto"
  7. h="auto"
  8. :x="left"
  9. :y="top"
  10. :z="zIndex"
  11. :isResizable="false"
  12. :parent-limitation="true"
  13. v-if="dialogConfig.show"
  14. @clicked="setZIndex(dialogConfig.dialogId)"
  15. >
  16. <div
  17. class="slot-container"
  18. :style="{ width: width + 'rem', height: height + 'rem' }"
  19. >
  20. <div class="bg-container">
  21. <!-- 拼接背景图案 -->
  22. <img
  23. class="leftTop"
  24. :src="require('@/assets/imgs/dialog/base/pop_bg1@2x.png')"
  25. alt=""
  26. />
  27. <img
  28. class="rightTop"
  29. :src="require('@/assets/imgs/dialog/base/pop_bg2@2x.png')"
  30. alt=""
  31. />
  32. <img
  33. class="leftBottom"
  34. :src="require('@/assets/imgs/dialog/base/pop_bg4@2x.png')"
  35. alt=""
  36. />
  37. <img
  38. class="rightBottom"
  39. :src="require('@/assets/imgs/dialog/base/pop_bg3@2x.png')"
  40. alt=""
  41. />
  42. <img
  43. class="bottomCenter"
  44. :src="require('@/assets/imgs/dialog/base/img_guang@2x.png')"
  45. alt=""
  46. />
  47. <div
  48. class="topBorder"
  49. :style="{
  50. width:
  51. width - (2.182292 - 0.041667) - (0.317708 - 0.041667) + 'rem',
  52. right: 0.317708 - 0.041667 + 'rem',
  53. }"
  54. ></div>
  55. <div
  56. class="rightBorder"
  57. :style="{
  58. height:
  59. height - (0.4375 - 0.239583) - (0.390625 - 0.177083) + 'rem',
  60. top: 0.4375 - 0.239583 + 'rem',
  61. }"
  62. ></div>
  63. <div
  64. class="bottomBorder"
  65. :style="{
  66. width:
  67. width - (0.317708 - 0.041667) - (0.317708 - 0.041667) + 'rem',
  68. right: 0.317708 - 0.041667 + 'rem',
  69. }"
  70. ></div>
  71. <div
  72. class="leftBorder"
  73. :style="{
  74. height:
  75. height - (0.4375 - 0.239583) - (0.390625 - 0.177083) + 'rem',
  76. top: 0.4375 - 0.239583 + 'rem',
  77. }"
  78. ></div>
  79. <div
  80. class="center-bg"
  81. :style="{
  82. width:
  83. width - (0.260417 - 0.041667) - (0.260417 - 0.041667) + 'rem',
  84. height:
  85. height - (0.4375 - 0.239583) - (0.390625 - 0.177083) + 'rem',
  86. top: 0.4375 - 0.239583 + 'rem',
  87. right: 0.260417 - 0.041667 + 'rem',
  88. }"
  89. ></div>
  90. </div>
  91. <div class="dialog-content">
  92. <!-- 弹窗标题 -->
  93. <div class="title-box">
  94. <div class="dialog-title">{{ dialogConfig.title }}</div>
  95. <div class="dialog-close" @click="handleClose">
  96. <img
  97. :src="require('@/assets/imgs/dialog/icon_guanbi2@2x.png')"
  98. alt=""
  99. />
  100. </div>
  101. </div>
  102. <div class="main-content" style="height: calc(100% - 55px)">
  103. <!-- 弹窗内容插槽 -->
  104. <el-form
  105. ref="form"
  106. :model="dialogConfig.data"
  107. size="small"
  108. label-width="80px"
  109. inline
  110. >
  111. <!-- <el-form-item label="事件类型" prop="TypeId">
  112. <el-input v-model="dialogConfig.data.TypeId" size="small" style="width: 180px" disabled />
  113. </el-form-item>
  114. <el-form-item label="事件等级" prop="Level">
  115. <el-input v-model="dialogConfig.data.Level" size="small" style="width: 180px" disabled />
  116. </el-form-item> -->
  117. <el-form-item label="事件时间" prop="EventTime">
  118. <el-input
  119. v-model="eventTime"
  120. size="small"
  121. style="width: 360px"
  122. disabled
  123. />
  124. </el-form-item>
  125. <!-- <el-form-item label="切换方式" prop="TriggerType">
  126. <el-input v-model="dialogConfig.data.TriggerType" size="small" style="width: 180px" disabled />
  127. </el-form-item> -->
  128. <el-form-item label="事件内容" prop="Content">
  129. <el-input
  130. v-model="dialogConfig.data.content"
  131. type="textarea"
  132. rows="5"
  133. size="small"
  134. style="width: 360px"
  135. disabled
  136. />
  137. </el-form-item>
  138. </el-form>
  139. <div class="btn-box">
  140. <el-button class="btn-cancel" size="mini" @click="handleClose"
  141. >取消</el-button
  142. >
  143. <el-button class="btn-handle" size="mini" @click="handleDeal"
  144. >确认</el-button
  145. >
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </vue-drag-resize>
  151. </template>
  152. <script>
  153. import { mapGetters } from "vuex";
  154. import { eliminateRisk } from "@/API/risk.js";
  155. import { dealAlarm } from "@/API/alarm";
  156. import Dayjs from "dayjs";
  157. export default {
  158. name: "RiskTipDialog",
  159. props: {
  160. dialogConfig: {
  161. type: Object,
  162. default: () => {
  163. return {
  164. dialogId: "",
  165. show: false, //是否显示
  166. title: "新窗口-请指定URL",
  167. width: 960, //px宽度
  168. height: 540, //px高度
  169. left: 0, //
  170. top: 0, //
  171. bottom: 0, //
  172. right: 0, //
  173. center: true, //是否居中定位
  174. data: {},
  175. zIndex: 5,
  176. };
  177. },
  178. },
  179. },
  180. data() {
  181. return {
  182. width: 0,
  183. height: 0,
  184. top: 0,
  185. left: 0,
  186. animationName: "yel",
  187. animationStyle: `@keyframes yel{
  188. 0% {
  189. box-shadow: 0 0 0px #ffffff;
  190. }
  191. 50% {
  192. box-shadow: #F8E71C 0px 0px 100px;
  193. }
  194. 100% {
  195. box-shadow: 0 0 0px #ffffff;
  196. }
  197. }`,
  198. shadowColors: {
  199. ["306001"]: { name: "重大级别", color: "#FF3636", anmationName: "red" },
  200. ["306002"]: { name: "较大级别", color: "#FF9F00", anmationName: "ora" },
  201. ["306003"]: { name: "一般级别", color: "#F8E71C", anmationName: "yel" },
  202. ["306004"]: { name: "低级别", color: "#53A3FF", anmationName: "blue" },
  203. ["024001"]: { name: "一级", color: "#FF3636", anmationName: "red" },
  204. ["024002"]: { name: "二级", color: "#FF9F00", anmationName: "ora" },
  205. ["024003"]: { name: "三级", color: "#53A3FF", anmationName: "blue" },
  206. },
  207. };
  208. },
  209. watch: {
  210. "dialogConfig.show"(newVal) {
  211. console.log(newVal);
  212. // 弹窗打开关闭时,更新全局变量
  213. console.log("将要移除" + this.dialogConfig.dialogId);
  214. this.$store.dispatch("dialog/removeRiskDialog", this.dialogConfig);
  215. },
  216. },
  217. created() {
  218. this.pxToRem();
  219. setTimeout(() => {
  220. this.updateShadow();
  221. }, 200);
  222. },
  223. mounted() {
  224. window.addEventListener("resize", this.pxToRem);
  225. },
  226. computed: {
  227. ...mapGetters(["riskDialogs", "alarmAudio"]),
  228. zIndex() {
  229. const config = this.riskDialogs.find(
  230. (e) => e.dialogId === this.dialogConfig?.dialogId
  231. );
  232. return config?.zIndex || 1;
  233. },
  234. eventTime() {
  235. return Dayjs(this.dialogConfig.data?.eventTime).format(
  236. "YYYY-MM-DD HH:mm:ss"
  237. );
  238. },
  239. },
  240. methods: {
  241. // 将传入的px值转换为rem值
  242. pxToRem() {
  243. // 当前窗口大小px值
  244. let width = document.documentElement.clientWidth;
  245. let height = document.documentElement.clientHeight;
  246. // console.log("client", width, height);
  247. // 当前1rem的值
  248. let rem = width / 10;
  249. // console.log(rem);
  250. // 通过默认 1rem=192 计算得出当前窗口大小rem值
  251. this.width = this.dialogConfig.width / 192;
  252. this.height = this.dialogConfig.height / 192;
  253. // console.log("dialog", this.width, this.height);
  254. // 通过当前的1rem值计算出窗口初始的定位px值
  255. if (this.dialogConfig.center) {
  256. this.left = (width - this.width * rem) / 2;
  257. this.top = (height - this.height * rem) / 2;
  258. } else {
  259. if (this.dialogConfig.bottom) {
  260. this.top =
  261. height -
  262. ((this.dialogConfig.bottom + this.dialogConfig.height) / 192) * rem;
  263. } else {
  264. this.top = (this.dialogConfig.top / 192) * rem;
  265. }
  266. if (this.dialogConfig.right) {
  267. this.left =
  268. width -
  269. ((this.dialogConfig.right + this.dialogConfig.width) / 192) * rem;
  270. } else {
  271. this.left = (this.dialogConfig.left / 192) * rem;
  272. }
  273. }
  274. // console.log('pos', this.left, this.top)
  275. // console.log(this.top);
  276. },
  277. handleClose() {
  278. this.dialogConfig.show = false;
  279. //this.$store.dispatch('home/setNavActive', this.dialogConfig.title)
  280. this.$store.dispatch("globalConfig/setAlarmAudio", {
  281. show: false,
  282. alarmType: "all",
  283. });
  284. },
  285. async handleDeal() {
  286. try {
  287. const { code, msg } = await eliminateRisk([this.dialogConfig.data.id]);
  288. // this.$message({
  289. // type: code == 20000 ? "success" : "danger",
  290. // message: msg,
  291. // });
  292. this.$store.dispatch("globalConfig/setDrawRiskTime", Dayjs(new Date()));
  293. this.handleClose();
  294. } catch (error) {
  295. console.log(error);
  296. }
  297. },
  298. setZIndex(val) {
  299. // 点击时根据id,动态改变zindex值
  300. this.$store.dispatch("dialog/setDialogZIndex", val);
  301. },
  302. updateShadow() {
  303. if (this.alarmAudio.show && this.dialogConfig.data && this.dialogConfig.data.level) {
  304. this.anmationName =
  305. this.shadowColors[this.dialogConfig.data.level].anmationName;
  306. this.animationStyle = `@keyframes ${this.anmationName}{
  307. 0% {
  308. box-shadow: 0 0 0px #ffffff;
  309. }
  310. 50% {
  311. box-shadow:${
  312. this.shadowColors[this.dialogConfig.data.level].color
  313. } 0px 0px 100px;
  314. }
  315. 100% {
  316. box-shadow: 0 0 0px #ffffff;
  317. }
  318. }`;
  319. document.styleSheets[0].insertRule(this.animationStyle, 0);
  320. document.getElementById("drag").style.animation =
  321. this.anmationName + " 1s infinite";
  322. // console.log("Animation", this.animationStyle, this.animationName);
  323. }
  324. },
  325. },
  326. };
  327. </script>
  328. <style lang="less" scoped>
  329. .drag-container {
  330. box-shadow: 0 0 0px rgba(255, 255, 255, 0), 0 0 0px rgba(255, 255, 255, 0);
  331. animation: glow 2s infinite;
  332. pointer-events: auto;
  333. .slot-container {
  334. position: relative;
  335. .bg-container {
  336. width: 100%;
  337. height: 100%;
  338. position: absolute;
  339. // (0.317708-0.041667)
  340. img {
  341. position: absolute;
  342. &.leftTop {
  343. width: 2.182292rem /* 419/192 */;
  344. height: 0.4375rem /* 84/192 */;
  345. top: -0.239583rem /* 46/192 */;
  346. left: -0.041667rem /* 8/192 */;
  347. }
  348. &.rightTop {
  349. width: 0.317708rem /* 61/192 */;
  350. height: 0.4375rem /* 84/192 */;
  351. top: -0.239583rem /* 46/192 */;
  352. right: -0.041667rem /* 8/192 */;
  353. }
  354. &.leftBottom {
  355. width: 0.317708rem /* 61/192 */;
  356. height: 0.390625rem /* 75/192 */;
  357. bottom: -0.177083rem /* 34/192 */;
  358. left: -0.041667rem /* 8/192 */;
  359. }
  360. &.rightBottom {
  361. width: 0.317708rem /* 61/192 */;
  362. height: 0.390625rem /* 75/192 */;
  363. bottom: -0.177083rem /* 34/192 */;
  364. right: -0.041667rem /* 8/192 */;
  365. }
  366. &.bottomCenter {
  367. width: 1.442708rem /* 277/192 */;
  368. height: 0.359375rem /* 69/192 */;
  369. bottom: -0.177083rem /* 34/192 */;
  370. left: 50%;
  371. transform: translate(-50%, 0);
  372. }
  373. }
  374. .topBorder {
  375. // width: 100%;
  376. height: 0.4375rem /* 84/192 */;
  377. position: absolute;
  378. top: -0.239583rem /* 46/192 */;
  379. background-image: url(~@/assets/imgs/dialog/base/pop_bg5@2x.png);
  380. background-repeat: repeat-x;
  381. background-size: contain;
  382. }
  383. .bottomBorder {
  384. // width: 100%;
  385. height: 0.390625rem /* 75/192 */;
  386. position: absolute;
  387. bottom: -0.177083rem /* 34/192 */;
  388. background-image: url(~@/assets/imgs/dialog/base/pop_bg6@2x.png);
  389. background-repeat: repeat-x;
  390. background-size: contain;
  391. }
  392. .leftBorder {
  393. width: 0.260417rem /* 50/192 */;
  394. // height: 0.390625rem /* 75/192 */;
  395. position: absolute;
  396. left: -0.041667rem /* 8/192 */;
  397. background-image: url(~@/assets/imgs/dialog/base/pop_bg7@2x.png);
  398. background-repeat: repeat-y;
  399. background-size: contain;
  400. }
  401. .rightBorder {
  402. width: 0.260417rem /* 50/192 */;
  403. // height: 0.390625rem /* 75/192 */;
  404. position: absolute;
  405. right: -0.041667rem /* 8/192 */;
  406. background-image: url(~@/assets/imgs/dialog/base/pop_bg8@2x.png);
  407. background-repeat: repeat-y;
  408. background-size: contain;
  409. }
  410. .center-bg {
  411. position: absolute;
  412. // top: 50%;
  413. // left: 50%;
  414. // transform: translate(-50%, -50%);
  415. background-image: url(~@/assets/imgs/dialog/base/pop_bg9@2x.png);
  416. background-repeat: repeat;
  417. background-size: contain;
  418. }
  419. }
  420. .dialog-content {
  421. width: 100%;
  422. height: 100%;
  423. position: absolute;
  424. padding: 0 0.104167rem /* 20/192 */;
  425. .title-box {
  426. display: flex;
  427. justify-content: space-between;
  428. width: 100%;
  429. height: 0.166667rem /* 32/192 */;
  430. line-height: 0.166667rem /* 32/192 */;
  431. color: #fff;
  432. .dialog-title {
  433. font-size: 0.09375rem /* 18/192 */;
  434. margin-top: -0.083333rem /* 16/192 */;
  435. }
  436. .dialog-close {
  437. width: 0.09375rem /* 18/192 */;
  438. height: 0.09375rem /* 18/192 */;
  439. position: absolute;
  440. top: 0.020833rem /* 4/192 */;
  441. right: 0.052083rem /* 10/192 */;
  442. cursor: pointer;
  443. img {
  444. width: 100%;
  445. height: 100%;
  446. }
  447. }
  448. }
  449. .main-content {
  450. padding-top: 10px;
  451. ::v-deep .el-form-item__label {
  452. color: #fff;
  453. }
  454. .btn-box {
  455. width: 100%;
  456. height: 40px;
  457. text-align: center;
  458. position: absolute;
  459. bottom: 30px;
  460. left: 50%;
  461. transform: translate(-50%, 0);
  462. .el-button {
  463. width: 100px;
  464. height: 32px;
  465. box-sizing: border-box;
  466. margin-top: 0.015625rem /* 3/192 */;
  467. color: #fff;
  468. padding: 0;
  469. border-color: #5bd6ff;
  470. // border-radius: 0;
  471. &:hover {
  472. border-color: #ccc;
  473. }
  474. }
  475. .btn-handle.el-button {
  476. background: rgba(0, 159, 221, 0.8);
  477. }
  478. .btn-cancel.el-button {
  479. background: rgba(7, 51, 121, 0.1);
  480. }
  481. }
  482. }
  483. }
  484. .contentiframe {
  485. width: 100%;
  486. height: 100%;
  487. padding: 0;
  488. border: 0;
  489. }
  490. }
  491. }
  492. .vdr.active:before {
  493. outline: 0;
  494. }
  495. </style>