Navbar.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <div class="navbar">
  3. <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  4. <breadcrumb class="breadcrumb-container" v-if="showBreadcrumb" />
  5. <!-- <NavMenu class="navmenu" /> -->
  6. <div class="right-menu">
  7. <!-- <div class="right-menu-item hover-effect">
  8. <el-tooltip effect="dark" content="家用工程机登录" placement="bottom">
  9. <i
  10. class="el-icon-s-platform"
  11. style="font-size: 24px; line-height: 50px"
  12. @click="toEngine"
  13. ></i>
  14. </el-tooltip>
  15. </div> -->
  16. <div class="right-menu-item hover-effect" @click="handleNotice" style="display: flex;">
  17. <el-badge value="示">
  18. <i class="el-icon-message-solid" style="font-size: 24px; line-height: 50px"></i>
  19. </el-badge>
  20. <span style="font-size: 16px; margin-left: 15px;">到货通知</span>
  21. </div>
  22. <div class="right-menu-item hover-effect" @click="toEngine">
  23. <i class="el-icon-s-platform" style="font-size: 18px;"></i>
  24. <span style="font-size: 16px; margin-left: 6px;">家用工程机登录</span>
  25. </div>
  26. <el-badge :value="noticeCount" :max="10" :hidden="!noticeVisible" class="right-menu-item hover-effect">
  27. <el-tooltip effect="dark" content="系统消息" placement="bottom">
  28. <i class="el-icon-message-solid" @click="goNotice" style="font-size: 24px; line-height: 50px"></i>
  29. </el-tooltip>
  30. <!-- <el-button icon="el-icon-message-solid" type="text" class="notice-icon" @click="goNotice"></el-button> -->
  31. </el-badge>
  32. <template v-if="device !== 'mobile'">
  33. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  34. </template>
  35. <el-dropdown class="user-container" trigger="click">
  36. <div class="user right-menu-item hover-effect">
  37. <i class="el-icon-user-solid"></i>
  38. <span>{{ name }}</span>
  39. </div>
  40. <el-dropdown-menu slot="dropdown" class="user-dropdown">
  41. <router-link to="/setting/personal">
  42. <el-dropdown-item>个人信息</el-dropdown-item>
  43. </router-link>
  44. <el-dropdown-item divided @click.native="logout">
  45. <span style="display: block">退出登录</span>
  46. </el-dropdown-item>
  47. </el-dropdown-menu>
  48. </el-dropdown>
  49. </div>
  50. <el-dialog title="绑定工程机系统" :visible.sync="dialogFormVisible" :modal="false" width="30%">
  51. <el-form ref="engineForm" :model="engineForm" :rules="engineFormRules">
  52. <el-form-item label="账号" :label-width="formLabelWidth" prop="account">
  53. <el-input v-model="engineForm.account" placeholder="请输入账号" autocomplete="off"></el-input>
  54. </el-form-item>
  55. <el-form-item label="密码" :label-width="formLabelWidth" prop="password">
  56. <el-input v-model="engineForm.password" placeholder="请输入密码" autocomplete="off" show-password></el-input>
  57. </el-form-item>
  58. </el-form>
  59. <div slot="footer" class="dialog-footer">
  60. <el-button @click="dialogFormVisible = false">取 消</el-button>
  61. <el-button type="primary" @click="submitForm">确 定</el-button>
  62. </div>
  63. </el-dialog>
  64. <el-dialog title="到货通知" :modal="false" width="70%" :visible.sync="hasNotice" center @close="handleNotice(false)">
  65. <div class="mymain-container">
  66. <div class="table">
  67. <el-table :data="noticeList" v-loading="listLoading" border>
  68. <el-table-column property="materialOldNumber" align="left" min-width="120" label="产品编号" show-overflow-tooltip ></el-table-column>
  69. <el-table-column property="materialNumber" align="left" min-width="100" label="物料编码" show-overflow-tooltip></el-table-column>
  70. <el-table-column property="materialName" align="left" min-width="250" label="产品名称" show-overflow-tooltip></el-table-column>
  71. <el-table-column property="specification" align="left" min-width="350" label="规格型号" show-overflow-tooltip></el-table-column>
  72. <el-table-column property="stockName" align="left" min-width="100" label="到货仓库" show-overflow-tooltip></el-table-column>
  73. <el-table-column property="updateTime" align="left" min-width="200" label="到货通知时间" show-overflow-tooltip></el-table-column>
  74. </el-table>
  75. <div class="flex">
  76. <div></div>
  77. <div class="fr">
  78. <el-pagination
  79. @size-change="handleSizeChange"
  80. @current-change="handleCurrentChange"
  81. :current-page="currentPage"
  82. :page-sizes="[10, 20, 30, 50]"
  83. :page-size="10"
  84. layout="total, prev, pager, next"
  85. :total="listTotal"
  86. >
  87. </el-pagination>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </el-dialog>
  93. <!-- 工程机多帐号-->
  94. <!-- <el-dialog-->
  95. <!-- title="绑定工程机系统"-->
  96. <!-- :visible.sync="dialogFormVisible"-->
  97. <!-- :modal="false"-->
  98. <!-- width="60%"-->
  99. <!-- >-->
  100. <!-- <el-form ref="engineForm" :model="engineForm">-->
  101. <!-- <el-row v-for="(row, index) in engineForm.engineList" :key="row.id" :gutter="20">-->
  102. <!-- <el-col :span="8">-->
  103. <!-- <el-form-item-->
  104. <!-- :label="'账号' + (index+1)"-->
  105. <!-- :label-width="formLabelWidth"-->
  106. <!-- :prop="'engineList.' + index + '.enginUserName'"-->
  107. <!-- :rules="{required: true, message: '请输入工程机账号', trigger: 'blur'}"-->
  108. <!-- >-->
  109. <!-- <el-input v-model="row.enginUserName" placeholder="请输入账号" autocomplete="off"></el-input>-->
  110. <!-- </el-form-item>-->
  111. <!-- </el-col>-->
  112. <!-- <el-col :span="8">-->
  113. <!-- <el-form-item-->
  114. <!-- :label="'密码' + (index+1)"-->
  115. <!-- :label-width="formLabelWidth"-->
  116. <!-- :prop="'engineList.' + index + '.enginPassword'"-->
  117. <!-- :rules="{required: true, message: '请输入工程机密码', trigger: 'blur'}"-->
  118. <!-- >-->
  119. <!-- <el-input v-model="row.enginPassword" placeholder="请输入密码" autocomplete="off" show-password></el-input>-->
  120. <!-- </el-form-item>-->
  121. <!-- </el-col>-->
  122. <!-- <el-col :span="8">-->
  123. <!-- <template v-if="row.adminUserId">-->
  124. <!-- <el-button @click="submitForm(index)">重验</el-button>-->
  125. <!-- </template>-->
  126. <!-- <template v-else>-->
  127. <!-- <el-button @click="submitForm(index)">验证</el-button>-->
  128. <!-- </template>-->
  129. <!-- <el-button v-if="row.adminUserId" @click="toEngine(index)">打开</el-button>-->
  130. <!-- <el-button @click="delAccountForm(index)">删除</el-button>-->
  131. <!-- </el-col>-->
  132. <!-- </el-row>-->
  133. <!-- </el-form>-->
  134. <!-- <div slot="footer" class="dialog-footer">-->
  135. <!-- <el-button @click="addRowEngine">新增账号</el-button>-->
  136. <!-- <el-button @click="dialogFormVisible = false">取 消</el-button>-->
  137. <!-- </div>-->
  138. <!-- </el-dialog>-->
  139. </div>
  140. </template>
  141. <script>
  142. import { getRebateOrderMsg } from "@/api/dashboard";
  143. import { mapGetters } from "vuex";
  144. import Breadcrumb from "@/components/Breadcrumb";
  145. import Hamburger from "@/components/Hamburger";
  146. import Screenfull from "@/components/Screenfull";
  147. import NavMenu from "@/components/NavMenu";
  148. import { getNoticeListCount } from "@/api/notice";
  149. import {getNoticeList} from '@/api/stock'
  150. import { bindEngineAccount, checkEngineAccount } from "@/api/setting";
  151. import mixin from '@/mixin'
  152. export default {
  153. mixins:[mixin],
  154. data() {
  155. return {
  156. intivalId: "",
  157. timer: "",
  158. noticeCount: 0,
  159. userInfo: "",
  160. engineForm: {
  161. account: "",
  162. password: "",
  163. // engineList: []
  164. },
  165. engineFormRules: {
  166. account: [
  167. { required: true, message: "请输入工程机账号", trigger: "blur" },
  168. ],
  169. password: [
  170. { required: true, message: "请输入工程机密码", trigger: "blur" },
  171. ],
  172. },
  173. formLabelWidth: "100px",
  174. dialogFormVisible: false,
  175. //websocket错误连接次数
  176. wsConnectErrorTime: 1,
  177. websock: null,
  178. lockReconnect: false,
  179. noticeList:[]
  180. };
  181. },
  182. mounted() {
  183. const that = this;
  184. // 开定时器轮询未读消息接口(写在全局vuex里比较好)
  185. // that.initNotice();
  186. // that.tcMessage();
  187. // this.intivalId = setInterval(function () {
  188. // that.tcMessage();
  189. // }, 5000);
  190. // this.timer = setInterval(function () {
  191. // that.initNotice();
  192. // }, 3000);
  193. // 长链接
  194. // this.initWebSocket();
  195. },
  196. created() {
  197. this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  198. },
  199. beforeDestroy() {
  200. window.clearInterval(this.intivalId);
  201. window.clearInterval(this.timer);
  202. console.log("退出清理定时器" + this.timer);
  203. this.websocketOnclose();
  204. },
  205. components: {
  206. Breadcrumb,
  207. Hamburger,
  208. Screenfull,
  209. NavMenu,
  210. },
  211. computed: {
  212. showBreadcrumb() {
  213. return this.$store.state.settings.breadcrumb;
  214. },
  215. noticeVisible() {
  216. return this.noticeCount > 0;
  217. },
  218. hasNotice:{
  219. get(){
  220. return this.isNotice
  221. },
  222. set(e){
  223. return e
  224. }
  225. },
  226. ...mapGetters(["sidebar", "avatar", "device", "name","isNotice"]),
  227. },
  228. methods: {
  229. getList(){
  230. this.getNoticeList()
  231. }
  232. ,
  233. getNoticeList(){
  234. this.listLoading = true
  235. getNoticeList({
  236. pageNum:this.currentPage,
  237. pageSize:this.pageSize
  238. }).then(res=>{
  239. this.noticeList = res.data.records
  240. this.listTotal = res.data.total
  241. this.listLoading = false
  242. })
  243. },
  244. handleNotice(flag=true){
  245. if (flag) {
  246. this.getNoticeList()
  247. }
  248. this.$store.commit("user/SET_STATUS",!this.hasNotice);
  249. },
  250. toggleSideBar() {
  251. this.$store.dispatch("app/toggleSideBar");
  252. },
  253. async logout() {
  254. await this.$store.dispatch("user/logout");
  255. // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  256. this.$store.commit("tagsView/SET_RESET_VIES");
  257. this.$router.push(`/login`);
  258. },
  259. initNotice() {
  260. getNoticeListCount().then((res) => {
  261. if (res.data > 0 && this.noticeCount !== res.data) {
  262. this.noticeCount = res.data;
  263. } else if (res.data === 0 && this.noticeCount !== res.data) {
  264. this.noticeCount = 0;
  265. }
  266. });
  267. },
  268. // async tcMessage() {
  269. // // 长链接
  270. // // let data = {
  271. // // type: 'RebateOrderMsg',
  272. // // params: {
  273. // // }
  274. // // }
  275. // // this.websocketSend(JSON.stringify(data))
  276. // let res = await getRebateOrderMsg();
  277. // if (res.data.hasMessage) {
  278. // this.$notify.info({
  279. // title: "消息",
  280. // message: res.data.messages,
  281. // position: "bottom-right",
  282. // duration: 4000,
  283. // showClose: false,
  284. // });
  285. // }
  286. // },
  287. goNotice() {
  288. this.$router.push("/notice/index");
  289. },
  290. openEngineAccount() {
  291. this.engineForm.engineList = this.userInfo.bindEnginList;
  292. this.dialogFormVisible = true;
  293. },
  294. toEngine() {
  295. const userInfoCopy = this.userInfo;
  296. if (userInfoCopy && userInfoCopy.bindEngin) {
  297. checkEngineAccount().then((res) => {
  298. if (res.code === 200) {
  299. // this.$refs.engineSubmit.click()
  300. const { href } = this.$router.resolve({
  301. name: "open_engin",
  302. });
  303. window.open(href, "_blank");
  304. } else {
  305. this.$errorMsg("账号密码错误,请重新绑定");
  306. this.dialogFormVisible = true;
  307. }
  308. });
  309. } else {
  310. this.dialogFormVisible = true;
  311. }
  312. },
  313. // toEngine(index) {
  314. // 工程机多帐号
  315. // const { href } = this.$router.resolve({
  316. // name: "open_engin",
  317. // query: {
  318. // index: index
  319. // }
  320. // });
  321. // window.open(href, "_blank");
  322. // },
  323. // addRowEngine() {
  324. // this.engineForm.engineList.push({
  325. // adminUserId: '',
  326. // enginPassword: '',
  327. // enginUserName: '',
  328. // status: '',
  329. // })
  330. // },
  331. submitForm() {
  332. this.$refs.engineForm.validate((valid) => {
  333. if (valid) {
  334. const params = {
  335. enginUserName: this.engineForm.account,
  336. enginPassword: this.engineForm.password,
  337. };
  338. bindEngineAccount(params).then((res) => {
  339. if (res.code === 200) {
  340. this.$successMsg("绑定成功,正在打开工程机系统");
  341. this.dialogFormVisible = false;
  342. this.$store.dispatch("user/getInfo").then(() => {
  343. this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  344. const { href } = this.$router.resolve({
  345. name: "open_engin",
  346. });
  347. window.open(href, "_blank");
  348. });
  349. } else {
  350. this.$errorMsg(res.message);
  351. }
  352. });
  353. }
  354. });
  355. },
  356. // submitForm(index) {
  357. // 工程机多帐号
  358. // this.$refs.engineForm.validate((valid) => {
  359. // if (valid) {
  360. // const params = {
  361. // enginUserName: this.engineForm.engineList[index].enginUserName,
  362. // enginPassword: this.engineForm.engineList[index].enginPassword,
  363. // isReset: this.engineForm.engineList[index].adminUserId !== ''
  364. // };
  365. // bindEngineAccount(params).then((res) => {
  366. // if (res.code === 200) {
  367. // this.$successMsg("绑定成功,工程机系统");
  368. // this.$store.dispatch("user/getInfo").then(() => {
  369. // this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  370. // this.engineForm.engineList = this.userInfo.bindEnginList
  371. // });
  372. // } else {
  373. // this.$errorMsg(res.message);
  374. // }
  375. // });
  376. // }
  377. // });
  378. // },
  379. // delAccountForm(index) {
  380. // if (this.engineForm.engineList[index].id) {
  381. // this.$confirm('此操作将删除账号, 是否继续?', '提示', {
  382. // confirmButtonText: '确定',
  383. // cancelButtonText: '取消',
  384. // type: 'warning',
  385. // center: true
  386. // }).then(() => {
  387. // delEngineAccount({id: this.engineForm.engineList[index].id}).then(() => {
  388. // this.$store.dispatch("user/getInfo").then(() => {
  389. // this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  390. // this.engineForm.engineList = this.userInfo.bindEnginList
  391. // });
  392. // this.$successMsg("删除成功");
  393. // })
  394. // }).catch(() => {
  395. // });
  396. // } else {
  397. // this.engineForm.engineList.splice(index, 1)
  398. // }
  399. // }
  400. initWebSocket: function () {
  401. // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
  402. // var userId = this.$store.getters.userid;
  403. //
  404. // var url = process.env.VUE_APP_BASE_API.replace("https://","wss://").replace("http://","ws://").replace("api","supply")+"websocket/"+userId;
  405. // console.debug(userId, url);
  406. // let token = getToken()
  407. // this.websock = new WebSocket(url, [token]);
  408. // this.websock.onopen = this.websocketOnopen;
  409. // this.websock.onerror = this.websocketOnerror;
  410. // this.websock.onmessage = this.websocketOnmessage;
  411. // this.websock.onclose = this.websocketOnclose;
  412. },
  413. websocketOnopen: function () {
  414. console.debug("WebSocket连接成功");
  415. //心跳检测重置
  416. //this.heartCheck.reset().start();
  417. },
  418. websocketOnerror: function (e) {
  419. console.debug("WebSocket连接发生错误,第%s次", this.wsConnectErrorTime);
  420. this.wsConnectErrorTime = this.wsConnectErrorTime + 1;
  421. if (this.wsConnectErrorTime > 5) {
  422. console.debug("WebSocket连接错误超过5次,就不再重新连了!");
  423. this.lockReconnect = true;
  424. return;
  425. }
  426. this.reconnect();
  427. },
  428. websocketOnmessage: function (e) {
  429. console.debug("-----接收消息-------", e.data);
  430. let data = eval("(" + e.data + ")"); //解析对象
  431. if (data.type === "RebateOrderMsg") {
  432. if (data.res.hasMessage) {
  433. this.$notify.info({
  434. title: "消息",
  435. message: res.data.messages,
  436. position: "bottom-right",
  437. duration: 4000,
  438. showClose: false,
  439. });
  440. }
  441. }
  442. },
  443. websocketOnclose: function (e) {
  444. console.debug("connection closed (" + e + ")");
  445. if (e) {
  446. console.debug("connection closed (" + e.code + ")");
  447. }
  448. this.reconnect();
  449. },
  450. websocketSend(text) {
  451. // 数据发送
  452. try {
  453. this.websock.send(text);
  454. } catch (err) {
  455. console.debug("send failed (" + err.code + ")");
  456. }
  457. },
  458. reconnect() {
  459. var that = this;
  460. if (that.lockReconnect) return;
  461. that.lockReconnect = true;
  462. //没连接上会一直重连,设置延迟避免请求过多
  463. setTimeout(function () {
  464. console.debug("尝试重连...");
  465. that.initWebSocket();
  466. that.lockReconnect = false;
  467. }, 20000);
  468. },
  469. },
  470. };
  471. </script>
  472. <style lang="scss" scoped>
  473. @import "~@/styles/variables.scss";
  474. ::v-deep .is-fixed{
  475. right: 10px !important;
  476. }
  477. .flex{
  478. margin-top: 30px;
  479. display: flex;
  480. align-items: center;
  481. justify-content: space-between;
  482. }
  483. .navbar {
  484. width: 100%;
  485. height: 50px;
  486. overflow: hidden;
  487. background: #{$navbarBg};
  488. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  489. .hamburger-container {
  490. line-height: 46px;
  491. height: 100%;
  492. color: #{$navbarText};
  493. float: left;
  494. cursor: pointer;
  495. transition: background 0.3s;
  496. -webkit-tap-highlight-color: transparent;
  497. border-right: 1px solid #eaeaea;
  498. &:hover {
  499. background: rgba(0, 0, 0, 0.025);
  500. }
  501. }
  502. .navmenu {
  503. float: left;
  504. }
  505. .breadcrumb-container {
  506. float: left;
  507. }
  508. .right-menu {
  509. float: right;
  510. height: 100%;
  511. line-height: 50px;
  512. & > div {
  513. float: left;
  514. }
  515. &:focus {
  516. outline: none;
  517. }
  518. .user-container {
  519. height: 50px;
  520. .user {
  521. i {
  522. font-size: 18px;
  523. margin-right: 5px;
  524. }
  525. span {
  526. font-size: 16px;
  527. }
  528. }
  529. }
  530. .right-menu-item {
  531. display: inline-block;
  532. padding: 0 15px;
  533. height: 100%;
  534. font-size: 18px;
  535. color: #{$navbarText};
  536. vertical-align: text-bottom;
  537. border-left: 1px solid #eaeaea;
  538. &.hover-effect {
  539. cursor: pointer;
  540. transition: background 0.3s;
  541. &:hover {
  542. background: rgba(0, 0, 0, 0.025);
  543. }
  544. }
  545. .notice-icon {
  546. padding-top: 0;
  547. padding-bottom: 0;
  548. }
  549. }
  550. }
  551. }
  552. </style>
  553. <style lang="scss">
  554. .navbar {
  555. .right-menu {
  556. .right-menu-item {
  557. .notice-icon > i {
  558. font-size: 18px;
  559. }
  560. sup {
  561. top: 12px;
  562. right: 25px;
  563. }
  564. }
  565. }
  566. }
  567. </style>