Navbar.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div class="navbar">
  3. <!--<hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />-->
  4. <breadcrumb
  5. id="breadcrumb-container"
  6. class="breadcrumb-container"
  7. v-if="!topNav"
  8. />
  9. <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" />
  10. <logo class="logo_style" />
  11. <div class="right-menu">
  12. <template v-if="device !== 'mobile'">
  13. <search id="header-search" class="right-menu-item" />
  14. <!--<el-tooltip content="源码地址" effect="dark" placement="bottom">-->
  15. <!--<ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />-->
  16. <!--</el-tooltip>-->
  17. <!--<el-tooltip content="文档地址" effect="dark" placement="bottom">-->
  18. <!--<ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />-->
  19. <!--</el-tooltip>-->
  20. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  21. <!--<el-tooltip content="布局大小" effect="dark" placement="bottom">-->
  22. <!--<size-select id="size-select" class="right-menu-item hover-effect" />-->
  23. <!--</el-tooltip>-->
  24. </template>
  25. <el-dropdown
  26. class="avatar-container right-menu-item hover-effect"
  27. trigger="click"
  28. >
  29. <div class="avatar-wrapper">
  30. <img :src="avatar" class="user-avatar" />
  31. <i class="el-icon-caret-bottom" />
  32. </div>
  33. <el-dropdown-menu slot="dropdown">
  34. <router-link to="/user/profile">
  35. <el-dropdown-item>个人中心</el-dropdown-item>
  36. </router-link>
  37. <!--<el-dropdown-item @click.native="setting = true">-->
  38. <!--<span>布局设置</span>-->
  39. <!--</el-dropdown-item>-->
  40. <el-dropdown-item divided @click.native="logout">
  41. <span>退出登录</span>
  42. </el-dropdown-item>
  43. </el-dropdown-menu>
  44. </el-dropdown>
  45. <div class="deptName">
  46. {{
  47. user.userData.userType === "00"
  48. ? user.userData.dept.deptName
  49. : user.userData.nickName
  50. }}
  51. </div>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import {mapGetters, mapState} from "vuex";
  57. import Breadcrumb from "@/components/Breadcrumb";
  58. import TopNav from "@/components/TopNav";
  59. import Hamburger from "@/components/Hamburger";
  60. import Screenfull from "@/components/Screenfull";
  61. import SizeSelect from "@/components/SizeSelect";
  62. import Search from "@/components/HeaderSearch";
  63. import RuoYiGit from "@/components/RuoYi/Git";
  64. import RuoYiDoc from "@/components/RuoYi/Doc";
  65. import Logo from "../../layout/components/Sidebar/Logo";
  66. import { decryptData_ECB, decryptRowData_ECB } from "@/api/tool/sm4";
  67. import mqtt from 'mqtt'
  68. import { getUuid } from '@/utils'
  69. export default {
  70. components: {
  71. Breadcrumb,
  72. TopNav,
  73. Logo,
  74. Hamburger,
  75. Screenfull,
  76. SizeSelect,
  77. Search,
  78. RuoYiGit,
  79. RuoYiDoc,
  80. },
  81. data(){
  82. return{
  83. client:'',
  84. options: {
  85. connectTimeout: 6000, // 超时时间
  86. clientId: '',
  87. // endpoint: "/mqtt",
  88. // host: "jdgl.ccsckj.com",
  89. // port: 443,
  90. username: "admin", // 用户名
  91. password: "sckj@2023", // 密码
  92. cleanSession: false,
  93. // clean: false, // 保留会话(避免重复订阅)
  94. keepAlive: 60, // 心跳值,心跳值太大可能会连接不成功,这个参考文档
  95. },
  96. subscription: {
  97. topic: "/Radar60FL/#",
  98. qos: 0,
  99. },
  100. }
  101. },
  102. computed: {
  103. ...mapGetters(["sidebar", "avatar", "device"]),
  104. ...mapState(["user"]),
  105. setting: {
  106. get() {
  107. return this.$store.state.settings.showSettings;
  108. },
  109. set(val) {
  110. this.$store.dispatch("settings/changeSetting", {
  111. key: "showSettings",
  112. value: val,
  113. });
  114. },
  115. },
  116. topNav: {
  117. get() {
  118. return this.$store.state.settings.topNav;
  119. },
  120. },
  121. isCollapse() {
  122. return !this.sidebar.opened;
  123. },
  124. },
  125. mounted() {
  126. this.options.clientId="znyl_" + getUuid();
  127. // console.log(this.user);
  128. let levelData=0;
  129. let ancestors=this.user.userData.dept.ancestors;
  130. if(ancestors)
  131. {
  132. levelData=ancestors.split(',').length
  133. }
  134. console.log(levelData,'levelData');
  135. if(levelData===4)
  136. {
  137. this.createConnection();
  138. }
  139. },
  140. destroyed() {
  141. if (this.client.end)
  142. {
  143. console.log('中断连接')
  144. this.client.end();
  145. }
  146. },
  147. methods: {
  148. createConnection() {
  149. console.log("正在连接...");
  150. try {
  151. this.client = mqtt.connect(
  152. // "wss://121.36.73.159:8083/mqtt",
  153. "wss://jdgl.ccsckj.com/mqtt",
  154. // "ws://121.36.73.159:8083/mqtt",
  155. this.options
  156. );
  157. } catch (error) {
  158. console.log("mqtt连接失败: ", error);
  159. }
  160. this.client.on("connect", (e) => {
  161. console.log("连接成功");
  162. this.doSubscribe(); // 订阅主题
  163. });
  164. // 接收消息处理
  165. this.client.on('message', this.message_str)
  166. // this.client.on("message",(topic, message) => {
  167. // //监听消息函数
  168. // console.log("收到来自主题:" + topic + "的消息:" + message.toString());
  169. // // var messageTextArea = document.getElementById("messageTextArea"); //获取textarea元素
  170. // // messageTextArea.value += "收到来自主题:"+topic+"的消息:"+message.toString()+"\n"; //将新的文本追加到 value
  171. // if (topic.includes("sys/property/post")) {
  172. // let msgobj = JSON.parse(message.toString());
  173. // this.$store.dispatch('mqtt/getMqttParams',msgobj)
  174. // }
  175. // });
  176. // 连接错误处理
  177. this.client.on("error", (error) => {
  178. if (this.client) {
  179. this.client.end();
  180. }
  181. console.log("连接出错: ", error);
  182. });
  183. // 重新连接处理
  184. // this.client.on('reconnect', () => {
  185. // console.log('重新连接...')
  186. // })
  187. // 断线重连
  188. this.client.on("reconnect", (error) => {
  189. console.log("正在重连:", new Date().getTime(), error);
  190. console.log(this.options.clientId,'this.options.clientId');
  191. });
  192. this.client.on("close", () => {
  193. console.log("监听断开连接");
  194. });
  195. },
  196. message_str(topic, message) {
  197. //监听消息函数
  198. console.log("收到来自主题:" + topic + "的消息:" + message.toString());
  199. // var messageTextArea = document.getElementById("messageTextArea"); //获取textarea元素
  200. // messageTextArea.value += "收到来自主题:"+topic+"的消息:"+message.toString()+"\n"; //将新的文本追加到 value
  201. if (topic.includes("sys/property/post")) {
  202. let msgobj = JSON.parse(message.toString());
  203. this.$store.dispatch('mqtt/getMqttParams',msgobj)
  204. }
  205. },
  206. // 订阅
  207. doSubscribe() {
  208. // console.log(this.currentCode,'区划编码');
  209. // console.log(this.user.jgId,'this.user');
  210. this.subscription.topic = "/Radar60FL/" + this.options.clientId + "/#";
  211. const { topic, qos } = this.subscription;
  212. let that=this;
  213. this.client.subscribe(topic, qos, (error) => {
  214. if (!error) {
  215. that.$store.dispatch('mqtt/getClientId',that.options.clientId)
  216. console.log("订阅成功");
  217. } else {
  218. console.log("订阅失败");
  219. }
  220. });
  221. },
  222. toggleSideBar() {
  223. this.$store.dispatch("app/toggleSideBar");
  224. },
  225. async logout() {
  226. this.$confirm("确定注销并退出系统吗?", "提示", {
  227. confirmButtonText: "确定",
  228. cancelButtonText: "取消",
  229. type: "warning",
  230. })
  231. .then(() => {
  232. this.$store.dispatch("LogOut").then(() => {
  233. sessionStorage.clear()
  234. location.href = process.env.NODE_ENV === 'production' ? '/gljt/' : '/index';
  235. });
  236. })
  237. .catch(() => {});
  238. },
  239. },
  240. };
  241. </script>
  242. <style lang="scss" scoped>
  243. @import "~@/assets/styles/variables.scss";
  244. $logoWidth: 300px;
  245. .navbar {
  246. height: $headerMenuHeight;
  247. overflow: hidden;
  248. position: relative;
  249. background: rgb(5, 122, 228);
  250. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  251. padding: 10px 0;
  252. .hamburger-container {
  253. line-height: 46px;
  254. height: 100%;
  255. float: left;
  256. cursor: pointer;
  257. transition: background 0.3s;
  258. -webkit-tap-highlight-color: transparent;
  259. &:hover {
  260. background: rgba(0, 0, 0, 0.025);
  261. }
  262. }
  263. .breadcrumb-container {
  264. float: left;
  265. }
  266. .topmenu-container {
  267. position: absolute;
  268. left: $logoWidth;
  269. background: rgb(5, 122, 228);
  270. }
  271. .errLog-container {
  272. display: inline-block;
  273. vertical-align: top;
  274. }
  275. .right-menu {
  276. float: right;
  277. height: 100%;
  278. line-height: 50px;
  279. display: flex;
  280. &:focus {
  281. outline: none;
  282. }
  283. .right-menu-item {
  284. display: inline-block;
  285. padding: 0 8px;
  286. height: 100%;
  287. font-size: 18px;
  288. color: #ffffff;
  289. vertical-align: text-bottom;
  290. &.hover-effect {
  291. cursor: pointer;
  292. transition: background 0.3s;
  293. &:hover {
  294. background: rgba(0, 0, 0, 0.025);
  295. }
  296. }
  297. }
  298. .avatar-container {
  299. margin-right: 30px;
  300. .avatar-wrapper {
  301. margin-top: 5px;
  302. position: relative;
  303. .user-avatar {
  304. cursor: pointer;
  305. width: 40px;
  306. height: 40px;
  307. border-radius: 10px;
  308. }
  309. .el-icon-caret-bottom {
  310. cursor: pointer;
  311. position: absolute;
  312. right: -20px;
  313. top: 25px;
  314. font-size: 12px;
  315. }
  316. }
  317. }
  318. }
  319. }
  320. .logo_style {
  321. float: left;
  322. width: $logoWidth;
  323. }
  324. .deptName {
  325. margin-right: 10px;
  326. color: #fff;
  327. }
  328. </style>