main-navbar.vue 11 KB

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