main-navbar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
  3. <div class="site-navbar__header">
  4. <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
  5. <a class="site-navbar__brand-lg" href="javascript:;">墨轩云商系统管理平台</a>
  6. <a class="site-navbar__brand-mini" href="javascript:;">
  7. <img src="~@/assets/img/avatar.png" style="width: 25px;border-radius: 50%;">
  8. </a>
  9. </h1>
  10. </div>
  11. <div class="site-navbar__body clearfix">
  12. <el-menu class="site-navbar__menu" mode="horizontal">
  13. <el-menu-item class="site-navbar__switch" index="0" @click="sidebarFold = !sidebarFold">
  14. <icon-svg name="zhedie"></icon-svg>
  15. </el-menu-item>
  16. </el-menu>
  17. <el-menu class="site-navbar__menu site-navbar__menu--right" mode="horizontal">
  18. <!-- <el-menu-item index="1" style="position: relative;" @click="$router.push({ name: 'missionSm' })" v-if="show">
  19. <template slot="title">
  20. <span class="left-number" v-if="chatNum">{{chatNum}}</span>
  21. <icon-svg name="xiaoxi" class="el-icon-setting" style="font-size: 28px;"></icon-svg>
  22. <audio id="audio1" autoplay="autoplay" v-if="chatNum>0"
  23. src="https://pw.xianmxkj.com/file/uploadPath/2022/01/12/01beb0bc15549b9aa4d18027a7751bae.mp3" ref='audio'
  24. controls hidden></audio>
  25. </template>
  26. </el-menu-item> -->
  27. <el-menu-item index="10" style="position: relative;" @click="$router.push({ name: 'downList' })">
  28. <template slot="title">
  29. <icon-svg name="xiazai" class="el-icon-setting" style="font-size: 22px;"></icon-svg>
  30. </template>
  31. </el-menu-item>
  32. <el-menu-item index="1" style="position: relative;" @click="$router.push({ name: 'vueMchat' })">
  33. <template slot="title">
  34. <span class="left-number" v-if="chatNum2">{{chatNum2}}</span>
  35. <icon-svg name="xiaoxi" class="el-icon-setting" style="font-size: 28px;"></icon-svg>
  36. <audio id="audio" autoplay="autoplay" v-if="chatNum2==1"
  37. src="https://pw.xianmxkj.com/file/uploadPath/2022/01/19/0753211f78d718d44ee6372e33eae9ee.mp3" ref='audio'
  38. controls hidden></audio>
  39. </template>
  40. </el-menu-item>
  41. <!-- <el-menu-item index="1" @click="$router.push({ name: 'theme' })">
  42. <template slot="title">
  43. <el-badge value="new">
  44. <icon-svg name="shezhi" class="el-icon-setting"></icon-svg>
  45. </el-badge>
  46. </template>
  47. </el-menu-item> -->
  48. <el-menu-item class="site-navbar__avatar" index="3">
  49. <el-dropdown :show-timeout="0" placement="bottom">
  50. <span class="el-dropdown-link">
  51. <img src="~@/assets/img/avatar.png" :alt="userName">{{ userName }}
  52. </span>
  53. <el-dropdown-menu slot="dropdown">
  54. <!-- <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item> -->
  55. <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>
  56. </el-dropdown-menu>
  57. </el-dropdown>
  58. </el-menu-item>
  59. </el-menu>
  60. </div>
  61. <!-- 弹窗, 修改密码 -->
  62. <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
  63. </nav>
  64. </template>
  65. <script>
  66. import UpdatePassword from './main-navbar-update-password'
  67. import {
  68. clearLoginInfo
  69. } from '@/utils'
  70. export default {
  71. data() {
  72. return {
  73. updatePassowrdVisible: false,
  74. chatNum: 0,
  75. chatNum2: 0,
  76. intervalId: 0,
  77. errCount: 0,
  78. shopIds: [],
  79. show: false,
  80. storeId: 0,
  81. }
  82. },
  83. components: {
  84. UpdatePassword
  85. },
  86. computed: {
  87. navbarLayoutType: {
  88. get() {
  89. return this.$store.state.common.navbarLayoutType
  90. }
  91. },
  92. sidebarFold: {
  93. get() {
  94. return this.$store.state.common.sidebarFold
  95. },
  96. set(val) {
  97. this.$store.commit('common/updateSidebarFold', val)
  98. }
  99. },
  100. mainTabs: {
  101. get() {
  102. return this.$store.state.common.mainTabs
  103. },
  104. set(val) {
  105. this.$store.commit('common/updateMainTabs', val)
  106. }
  107. },
  108. userName: {
  109. get() {
  110. return this.$store.state.user.name
  111. }
  112. }
  113. },
  114. mounted() {
  115. this.chatSelect()
  116. var userId = this.$cookie.get('userId')
  117. this.$http({
  118. url: this.$http.adornUrl(`sys/user/info`),
  119. method: 'get',
  120. params: this.$http.adornParams()
  121. }).then(({
  122. data
  123. }) => {
  124. if (data && data.code === 0) {
  125. var shows = 1
  126. for (var i in data.user.roleIdList) {
  127. if (data.user.roleIdList[i] == 12) {
  128. shows = 2
  129. } else {
  130. shows = 1
  131. }
  132. }
  133. // console.log('shows', shows)
  134. if (shows == 2) {
  135. this.show = true
  136. }
  137. if (shows == 1) {
  138. this.show = false
  139. }
  140. if (this.show == true) {
  141. this.dataSelect()
  142. }
  143. }
  144. })
  145. },
  146. methods: {
  147. // 修改密码
  148. updatePasswordHandle() {
  149. this.updatePassowrdVisible = true
  150. this.$nextTick(() => {
  151. this.$refs.updatePassowrd.init()
  152. })
  153. },
  154. // 退出
  155. logoutHandle() {
  156. this.$confirm(`确定进行[退出]操作?`, '提示', {
  157. confirmButtonText: '确定',
  158. cancelButtonText: '取消',
  159. type: 'warning'
  160. }).then(() => {
  161. this.$http({
  162. url: this.$http.adornUrl('sys/logout'),
  163. method: 'post',
  164. data: this.$http.adornData()
  165. }).then(({
  166. data
  167. }) => {
  168. if (data && data.code === 0) {
  169. clearLoginInfo()
  170. this.$cookie.set('token', '')
  171. sessionStorage.clear()
  172. clearInterval(this.chatNum)
  173. clearInterval(this.chatNum2)
  174. this.$router.push({
  175. name: 'login'
  176. })
  177. }
  178. })
  179. }).catch(() => {})
  180. },
  181. // 消息提醒
  182. newsSelect() {
  183. var _this = this
  184. this.$http({
  185. url: this.$http.adornUrl('admin/ordermessage/selectReadFlagCount'),
  186. method: 'post',
  187. params: this.$http.adornParams({
  188. 'shopIds': this.shopIds.toString()
  189. })
  190. }).then(({
  191. data
  192. }) => {
  193. if (data.code == 0) {
  194. if (data.data > 0) {
  195. if (this.errCount != data.data) {
  196. this.$notify.info({
  197. title: '消息',
  198. dangerouslyUseHTMLString: true,
  199. message: '有' + data.data + '条订单,请前往订单中心处理。',
  200. offset: 80,
  201. duration: 0,
  202. type: "warning",
  203. onClose() {
  204. _this.defineCallBack();
  205. }
  206. });
  207. this.errCount = data.data
  208. this.chatNum = data.data
  209. }
  210. } else {
  211. this.errCount = 0
  212. this.chatNum = 0
  213. }
  214. }
  215. })
  216. },
  217. defineCallBack() {
  218. this.$http({
  219. url: this.$http.adornUrl('admin/ordermessage/allcheckOrderMessage'),
  220. method: 'post',
  221. params: this.$http.adornParams({
  222. 'shopIds': this.shopIds.toString()
  223. })
  224. }).then(({
  225. data
  226. }) => {
  227. if (data.code === 0) {
  228. this.errCount = 0
  229. this.chatNum = 0
  230. this.$router.replace({
  231. name: 'missionSm'
  232. })
  233. }
  234. console.log('清空请求', data.data)
  235. })
  236. },
  237. aplayAudio() {
  238. const audio = document.getElementById('audio')
  239. console.log(audio);
  240. if(audio){
  241. audio.play()
  242. }
  243. console.log('语音提示')
  244. },
  245. // 获取店铺数据
  246. dataSelect() {
  247. this.tableDataLoading = true
  248. this.$http({
  249. url: this.$http.adornUrl('admin/goods/selectAllShop'),
  250. method: 'get',
  251. params: this.$http.adornParams({
  252. 'page': 1,
  253. 'limit': 10,
  254. 'shopName': ''
  255. })
  256. }).then(({
  257. data
  258. }) => {
  259. this.tableDataLoading = false
  260. var arr = []
  261. for (var i in data.data.list) {
  262. if (data.data.list[i].shopId) {
  263. arr.push(data.data.list[i].shopId)
  264. }
  265. }
  266. let returnData = data.data
  267. this.shopIds = arr
  268. this.newsSelect()
  269. })
  270. },
  271. // 获取聊天消息
  272. chatSelect() {
  273. // console.log(this.storeId,'p')
  274. this.$http({
  275. url: this.$http.adornUrl('chats/count'),
  276. method: 'get',
  277. params: this.$http.adornParams({
  278. 'storeId': this.storeId
  279. })
  280. }).then(({
  281. data
  282. }) => {
  283. // console.log(data,'pcc')
  284. this.code = data.code
  285. if (data.data > 0) {
  286. if (this.errCount != data.data) {
  287. this.$notify.info({
  288. title: '消息',
  289. dangerouslyUseHTMLString: true,
  290. message: '您有' + data.data + '条未读消息。',
  291. offset: 80,
  292. duration: 2500,
  293. type: "warning"
  294. });
  295. this.chatNum2 = data.data
  296. this.errCount = data.data
  297. }
  298. } else {
  299. this.chatNum2 = 0
  300. this.errCount = 0
  301. }
  302. if (this.chatNum == 0) {
  303. this.isshow = false
  304. } else {
  305. this.isshow = true
  306. }
  307. // console.log('this.chatNum2', this.chatNum2)
  308. })
  309. },
  310. },
  311. created() {
  312. // console.log('this.show', this.show)
  313. // if(this.show==true){
  314. // setInterval(() => {
  315. // this.newsSelect()
  316. // }, 10000)
  317. // }
  318. // setInterval(() => {
  319. // this.newsSelect()
  320. // }, 10000)
  321. this.chatNum2 = setInterval(() => {
  322. var token = this.$cookie.get('token')
  323. if (token !== '') {
  324. this.chatSelect()
  325. } else {
  326. clearInterval(this.chatNum2)
  327. }
  328. }, 6000)
  329. },
  330. beforeDestroy() {
  331. clearInterval(this.chatNum)
  332. },
  333. watch: {
  334. 'chatNum': function() {
  335. this.aplayAudio()
  336. },
  337. 'chatNum2': function() {
  338. this.aplayAudio()
  339. }
  340. }
  341. }
  342. </script>
  343. <style scoped="scoped">
  344. .site-navbar__avatar .el-dropdown-link>img {
  345. height: 36px;
  346. }
  347. .left-number {
  348. position: absolute;
  349. top: 0;
  350. right: 20px;
  351. width: 18px;
  352. height: 18px;
  353. line-height: 18px;
  354. border-radius: 50%;
  355. background: #ff4949;
  356. color: #ffffff;
  357. text-align: center;
  358. font-size: 10px;
  359. font-family: PingFang SC, PingFang SC-Regular;
  360. font-weight: 400;
  361. margin-top: 5px;
  362. }
  363. </style>