Navbar.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="navbar">
  3. <hamburger
  4. :is-active="sidebar.opened"
  5. class="hamburger-container"
  6. @toggleClick="toggleSideBar"
  7. />
  8. <breadcrumb class="breadcrumb-container" v-if="showBreadcrumb" />
  9. <!-- <NavMenu class="navmenu" /> -->
  10. <div class="right-menu">
  11. <!-- <div class="right-menu-item hover-effect">
  12. <el-tooltip effect="dark" content="家用工程机登录" placement="bottom">
  13. <i
  14. class="el-icon-s-platform"
  15. style="font-size: 24px; line-height: 50px"
  16. @click="toEngine"
  17. ></i>
  18. </el-tooltip>
  19. </div> -->
  20. <div class="right-menu-item hover-effect" @click="toEngine">
  21. <i class="el-icon-s-platform" style="font-size: 18px;"></i>
  22. <span style="font-size: 16px; margin-left: 6px;">家用工程机登录</span>
  23. </div>
  24. <el-badge
  25. :value="noticeCount"
  26. :max="10"
  27. :hidden="!noticeVisible"
  28. class="right-menu-item hover-effect"
  29. >
  30. <el-tooltip effect="dark" content="系统消息" placement="bottom">
  31. <i
  32. class="el-icon-message-solid"
  33. @click="goNotice"
  34. style="font-size: 24px; line-height: 50px"
  35. ></i>
  36. </el-tooltip>
  37. <!-- <el-button icon="el-icon-message-solid" type="text" class="notice-icon" @click="goNotice"></el-button> -->
  38. </el-badge>
  39. <template v-if="device !== 'mobile'">
  40. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  41. </template>
  42. <el-dropdown class="user-container" trigger="click">
  43. <div class="user right-menu-item hover-effect">
  44. <i class="el-icon-user-solid"></i>
  45. <span>{{ name }}</span>
  46. </div>
  47. <el-dropdown-menu slot="dropdown" class="user-dropdown">
  48. <router-link to="/setting/personal">
  49. <el-dropdown-item>个人信息</el-dropdown-item>
  50. </router-link>
  51. <el-dropdown-item divided @click.native="logout">
  52. <span style="display: block">退出登录</span>
  53. </el-dropdown-item>
  54. </el-dropdown-menu>
  55. </el-dropdown>
  56. </div>
  57. <el-dialog
  58. title="绑定工程机系统"
  59. :visible.sync="dialogFormVisible"
  60. :modal="false"
  61. width="30%"
  62. >
  63. <el-form ref="engineForm" :model="engineForm" :rules="engineFormRules">
  64. <el-form-item label="账号" :label-width="formLabelWidth" prop="account">
  65. <el-input
  66. v-model="engineForm.account"
  67. placeholder="请输入账号"
  68. autocomplete="off"
  69. ></el-input>
  70. </el-form-item>
  71. <el-form-item
  72. label="密码"
  73. :label-width="formLabelWidth"
  74. prop="password"
  75. >
  76. <el-input
  77. v-model="engineForm.password"
  78. placeholder="请输入密码"
  79. autocomplete="off"
  80. show-password
  81. ></el-input>
  82. </el-form-item>
  83. </el-form>
  84. <div slot="footer" class="dialog-footer">
  85. <el-button @click="dialogFormVisible = false">取 消</el-button>
  86. <el-button type="primary" @click="submitForm">确 定</el-button>
  87. </div>
  88. </el-dialog>
  89. <!-- 工程机多帐号-->
  90. <!-- <el-dialog-->
  91. <!-- title="绑定工程机系统"-->
  92. <!-- :visible.sync="dialogFormVisible"-->
  93. <!-- :modal="false"-->
  94. <!-- width="60%"-->
  95. <!-- >-->
  96. <!-- <el-form ref="engineForm" :model="engineForm">-->
  97. <!-- <el-row v-for="(row, index) in engineForm.engineList" :key="row.id" :gutter="20">-->
  98. <!-- <el-col :span="8">-->
  99. <!-- <el-form-item-->
  100. <!-- :label="'账号' + (index+1)"-->
  101. <!-- :label-width="formLabelWidth"-->
  102. <!-- :prop="'engineList.' + index + '.enginUserName'"-->
  103. <!-- :rules="{required: true, message: '请输入工程机账号', trigger: 'blur'}"-->
  104. <!-- >-->
  105. <!-- <el-input v-model="row.enginUserName" placeholder="请输入账号" autocomplete="off"></el-input>-->
  106. <!-- </el-form-item>-->
  107. <!-- </el-col>-->
  108. <!-- <el-col :span="8">-->
  109. <!-- <el-form-item-->
  110. <!-- :label="'密码' + (index+1)"-->
  111. <!-- :label-width="formLabelWidth"-->
  112. <!-- :prop="'engineList.' + index + '.enginPassword'"-->
  113. <!-- :rules="{required: true, message: '请输入工程机密码', trigger: 'blur'}"-->
  114. <!-- >-->
  115. <!-- <el-input v-model="row.enginPassword" placeholder="请输入密码" autocomplete="off" show-password></el-input>-->
  116. <!-- </el-form-item>-->
  117. <!-- </el-col>-->
  118. <!-- <el-col :span="8">-->
  119. <!-- <template v-if="row.adminUserId">-->
  120. <!-- <el-button @click="submitForm(index)">重验</el-button>-->
  121. <!-- </template>-->
  122. <!-- <template v-else>-->
  123. <!-- <el-button @click="submitForm(index)">验证</el-button>-->
  124. <!-- </template>-->
  125. <!-- <el-button v-if="row.adminUserId" @click="toEngine(index)">打开</el-button>-->
  126. <!-- <el-button @click="delAccountForm(index)">删除</el-button>-->
  127. <!-- </el-col>-->
  128. <!-- </el-row>-->
  129. <!-- </el-form>-->
  130. <!-- <div slot="footer" class="dialog-footer">-->
  131. <!-- <el-button @click="addRowEngine">新增账号</el-button>-->
  132. <!-- <el-button @click="dialogFormVisible = false">取 消</el-button>-->
  133. <!-- </div>-->
  134. <!-- </el-dialog>-->
  135. </div>
  136. </template>
  137. <script>
  138. import { getRebateOrderMsg } from "@/api/dashboard";
  139. import { mapGetters } from "vuex";
  140. import Breadcrumb from "@/components/Breadcrumb";
  141. import Hamburger from "@/components/Hamburger";
  142. import Screenfull from "@/components/Screenfull";
  143. import NavMenu from "@/components/NavMenu";
  144. import { getNoticeListCount } from "@/api/notice";
  145. import {
  146. checkEngineAccount,
  147. bindEngineAccount,
  148. delEngineAccount,
  149. } from "@/api/setting";
  150. import request from "@/utils/request";
  151. export default {
  152. data() {
  153. return {
  154. intivalId: "",
  155. timer: "",
  156. noticeCount: 0,
  157. userInfo: "",
  158. engineForm: {
  159. account: "",
  160. password: "",
  161. // engineList: []
  162. },
  163. engineFormRules: {
  164. account: [
  165. { required: true, message: "请输入工程机账号", trigger: "blur" },
  166. ],
  167. password: [
  168. { required: true, message: "请输入工程机密码", trigger: "blur" },
  169. ],
  170. },
  171. formLabelWidth: "100px",
  172. dialogFormVisible: false,
  173. };
  174. },
  175. mounted() {
  176. const that = this;
  177. // 开定时器轮询未读消息接口(写在全局vuex里比较好)
  178. // that.initNotice();
  179. that.tcMessage();
  180. this.intivalId = setInterval(function () {
  181. that.tcMessage();
  182. }, 5000);
  183. // this.timer = setInterval(function () {
  184. // that.initNotice();
  185. // }, 3000);
  186. },
  187. created() {
  188. this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  189. },
  190. beforeDestroy() {
  191. window.clearInterval(this.intivalId);
  192. window.clearInterval(this.timer);
  193. console.log("退出清理定时器" + this.timer);
  194. },
  195. components: {
  196. Breadcrumb,
  197. Hamburger,
  198. Screenfull,
  199. NavMenu,
  200. },
  201. computed: {
  202. showBreadcrumb() {
  203. return this.$store.state.settings.breadcrumb;
  204. },
  205. noticeVisible() {
  206. return this.noticeCount > 0;
  207. },
  208. ...mapGetters(["sidebar", "avatar", "device", "name"]),
  209. },
  210. methods: {
  211. toggleSideBar() {
  212. this.$store.dispatch("app/toggleSideBar");
  213. },
  214. async logout() {
  215. await this.$store.dispatch("user/logout");
  216. // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  217. this.$router.push(`/login`);
  218. },
  219. initNotice() {
  220. getNoticeListCount().then((res) => {
  221. if (res.data > 0 && this.noticeCount !== res.data) {
  222. this.noticeCount = res.data;
  223. } else if (res.data === 0 && this.noticeCount !== res.data) {
  224. this.noticeCount = 0;
  225. }
  226. });
  227. },
  228. async tcMessage() {
  229. let res = await getRebateOrderMsg();
  230. if (res.data.hasMessage) {
  231. this.$notify.info({
  232. title: "消息",
  233. message: res.data.messages,
  234. position: "bottom-right",
  235. duration: 4000,
  236. showClose: false,
  237. });
  238. }
  239. },
  240. goNotice() {
  241. this.$router.push("/notice/index");
  242. },
  243. openEngineAccount() {
  244. this.engineForm.engineList = this.userInfo.bindEnginList;
  245. this.dialogFormVisible = true;
  246. },
  247. toEngine() {
  248. const userInfoCopy = this.userInfo;
  249. if (userInfoCopy && userInfoCopy.bindEngin) {
  250. checkEngineAccount().then((res) => {
  251. if (res.code === 200) {
  252. // this.$refs.engineSubmit.click()
  253. const { href } = this.$router.resolve({
  254. name: "open_engin",
  255. });
  256. window.open(href, "_blank");
  257. } else {
  258. this.$errorMsg("账号密码错误,请重新绑定");
  259. this.dialogFormVisible = true;
  260. }
  261. });
  262. } else {
  263. this.dialogFormVisible = true;
  264. }
  265. },
  266. // toEngine(index) {
  267. // 工程机多帐号
  268. // const { href } = this.$router.resolve({
  269. // name: "open_engin",
  270. // query: {
  271. // index: index
  272. // }
  273. // });
  274. // window.open(href, "_blank");
  275. // },
  276. // addRowEngine() {
  277. // this.engineForm.engineList.push({
  278. // adminUserId: '',
  279. // enginPassword: '',
  280. // enginUserName: '',
  281. // status: '',
  282. // })
  283. // },
  284. submitForm() {
  285. this.$refs.engineForm.validate((valid) => {
  286. if (valid) {
  287. const params = {
  288. enginUserName: this.engineForm.account,
  289. enginPassword: this.engineForm.password,
  290. };
  291. bindEngineAccount(params).then((res) => {
  292. if (res.code === 200) {
  293. this.$successMsg("绑定成功,正在打开工程机系统");
  294. this.dialogFormVisible = false;
  295. this.$store.dispatch("user/getInfo").then(() => {
  296. this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  297. const { href } = this.$router.resolve({
  298. name: "open_engin",
  299. });
  300. window.open(href, "_blank");
  301. });
  302. } else {
  303. this.$errorMsg(res.message);
  304. }
  305. });
  306. }
  307. });
  308. },
  309. // submitForm(index) {
  310. // 工程机多帐号
  311. // this.$refs.engineForm.validate((valid) => {
  312. // if (valid) {
  313. // const params = {
  314. // enginUserName: this.engineForm.engineList[index].enginUserName,
  315. // enginPassword: this.engineForm.engineList[index].enginPassword,
  316. // isReset: this.engineForm.engineList[index].adminUserId !== ''
  317. // };
  318. // bindEngineAccount(params).then((res) => {
  319. // if (res.code === 200) {
  320. // this.$successMsg("绑定成功,工程机系统");
  321. // this.$store.dispatch("user/getInfo").then(() => {
  322. // this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  323. // this.engineForm.engineList = this.userInfo.bindEnginList
  324. // });
  325. // } else {
  326. // this.$errorMsg(res.message);
  327. // }
  328. // });
  329. // }
  330. // });
  331. // },
  332. // delAccountForm(index) {
  333. // if (this.engineForm.engineList[index].id) {
  334. // this.$confirm('此操作将删除账号, 是否继续?', '提示', {
  335. // confirmButtonText: '确定',
  336. // cancelButtonText: '取消',
  337. // type: 'warning',
  338. // center: true
  339. // }).then(() => {
  340. // delEngineAccount({id: this.engineForm.engineList[index].id}).then(() => {
  341. // this.$store.dispatch("user/getInfo").then(() => {
  342. // this.userInfo = JSON.parse(localStorage.getItem("supply_user"));
  343. // this.engineForm.engineList = this.userInfo.bindEnginList
  344. // });
  345. // this.$successMsg("删除成功");
  346. // })
  347. // }).catch(() => {
  348. // });
  349. // } else {
  350. // this.engineForm.engineList.splice(index, 1)
  351. // }
  352. // }
  353. },
  354. };
  355. </script>
  356. <style lang="scss" scoped>
  357. @import "~@/styles/variables.scss";
  358. .navbar {
  359. width: 100%;
  360. height: 50px;
  361. overflow: hidden;
  362. background: #{$navbarBg};
  363. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  364. .hamburger-container {
  365. line-height: 46px;
  366. height: 100%;
  367. color: #{$navbarText};
  368. float: left;
  369. cursor: pointer;
  370. transition: background 0.3s;
  371. -webkit-tap-highlight-color: transparent;
  372. border-right: 1px solid #eaeaea;
  373. &:hover {
  374. background: rgba(0, 0, 0, 0.025);
  375. }
  376. }
  377. .navmenu {
  378. float: left;
  379. }
  380. .breadcrumb-container {
  381. float: left;
  382. }
  383. .right-menu {
  384. float: right;
  385. height: 100%;
  386. line-height: 50px;
  387. & > div {
  388. float: left;
  389. }
  390. &:focus {
  391. outline: none;
  392. }
  393. .user-container {
  394. height: 50px;
  395. .user {
  396. i {
  397. font-size: 18px;
  398. margin-right: 5px;
  399. }
  400. span {
  401. font-size: 16px;
  402. }
  403. }
  404. }
  405. .right-menu-item {
  406. display: inline-block;
  407. padding: 0 15px;
  408. height: 100%;
  409. font-size: 18px;
  410. color: #{$navbarText};
  411. vertical-align: text-bottom;
  412. border-left: 1px solid #eaeaea;
  413. &.hover-effect {
  414. cursor: pointer;
  415. transition: background 0.3s;
  416. &:hover {
  417. background: rgba(0, 0, 0, 0.025);
  418. }
  419. }
  420. .notice-icon {
  421. padding-top: 0;
  422. padding-bottom: 0;
  423. }
  424. }
  425. }
  426. }
  427. </style>
  428. <style lang="scss">
  429. .navbar {
  430. .right-menu {
  431. .right-menu-item {
  432. .notice-icon > i {
  433. font-size: 18px;
  434. }
  435. sup {
  436. top: 12px;
  437. right: 25px;
  438. }
  439. }
  440. }
  441. }
  442. </style>