header.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?php
  2. ?>
  3. <style>
  4. .mall-header {
  5. margin-left: 30px;
  6. /*background-color: #24303c;*/
  7. background-color: #313131;
  8. /*background-color: #FFFFFF;*/
  9. }
  10. .mall-header .mall-name {
  11. max-width: 120px;
  12. display: inline-block;
  13. overflow: hidden;
  14. text-overflow: ellipsis;
  15. }
  16. .mall-header .el-menu.el-menu--horizontal {
  17. border-bottom: 0;
  18. }
  19. .mall-header-menu .el-menu--popup {
  20. min-width: 1px;
  21. }
  22. .mall-header-menu .el-menu--popup .is-disabled {
  23. opacity: .65;
  24. cursor: default;
  25. }
  26. .el-menu--horizontal.el-menu {
  27. background-color: #313131;
  28. }
  29. .lianxikefu{
  30. background-color: #313131 !important;
  31. }
  32. .el-menu-item:hover{
  33. background: #FFF !important;
  34. color: #333 !important;
  35. }
  36. .el-menu--horizontal>.el-menu-item,
  37. .el-menu--horizontal>.el-submenu .el-submenu__title,
  38. .el-submenu__title i {
  39. color: #FFFFFF !important;
  40. }
  41. .el-menu--horizontal>.el-submenu:hover .el-submenu__title{
  42. color: #303133 !important;
  43. }
  44. .lianxikefu:hover>.lianxikefu2 {
  45. color: #333 !important;
  46. display: inline-block;
  47. }
  48. </style>
  49. <template id="mall-header">
  50. <div>
  51. <header class="mall-header" flex="box:last">
  52. <el-menu class="el-menu-demo" mode="horizontal" menu-trigger="click">
  53. <!-- <el-menu-item v-for="(nav, index) in navs" :key="index" :index="'' + index" @click="$navigate(nav.url, nav.new_window?true:false)">{{nav.name}}
  54. </el-menu-item> -->
  55. </el-menu>
  56. <el-menu :default-active="activeIndex" mode="horizontal" class="el-menu-demo" @select="handleSelect" menu-trigger="click">
  57. </el-menu-item>
  58. <el-submenu v-if="mch_id == 0 && courseMenu.children && courseMenu.children.length > 0" index="3" v-if="courseMenu" popper-class="mall-header-menu">
  59. <template slot="title">
  60. <span :title="courseMenu.name" class="mall-name">{{courseMenu.name}}</span>
  61. </template>
  62. <el-menu-item @click="navigateClick({r: item.route})" v-for="(item, index) in courseMenu.children" :key="index" :index="'1-' + index">
  63. {{item.name}}
  64. </el-menu-item>
  65. </el-submenu>
  66. <el-submenu index="2" v-if="mall && user" popper-class="mall-header-menu">
  67. <template slot="title">
  68. <span :title="mall.name" class="mall-name">{{mall.name}}</span>
  69. </template>
  70. <el-menu-item index="1-1" :disabled="true">{{mall.name}}</el-menu-item>
  71. <el-menu-item index="1-2" :disabled="true">{{user.username}}</el-menu-item>
  72. <el-menu-item v-if="(user.admin_type == 2 || user.admin_type == 3) && updatePasswordStatus" index="2-3" @click="updatePassword">修改密码
  73. </el-menu-item>
  74. <el-menu-item index="2-2" @click="logout">注销
  75. </el-menu-item>
  76. </el-submenu>
  77. </el-menu>
  78. </header>
  79. <el-dialog title="修改密码" :visible.sync="dialogFormVisible" width="30%">
  80. <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px">
  81. <el-form-item label="旧密码" prop="old_pass">
  82. <el-input type="password" v-model="ruleForm.old_pass" placeholder="请输入旧密码" auto-complete="off" required></el-input>
  83. </el-form-item>
  84. <el-form-item label="新密码" prop="new_pass">
  85. <el-input type="password" v-model="ruleForm.new_pass" placeholder="请输入新密码" auto-complete="off" required></el-input>
  86. </el-form-item>
  87. <el-form-item label="确认密码" prop="check_pass">
  88. <el-input type="password" v-model="ruleForm.check_pass" placeholder="请输入确认密码" auto-complete="off" required></el-input>
  89. </el-form-item>
  90. </el-form>
  91. <div slot="footer" class="dialog-footer">
  92. <el-button @click="dialogFormVisible = false">取 消</el-button>
  93. <el-button :loading="btnLoading" type="primary" @click="updatePasswordSubmit('ruleForm')">确 定
  94. </el-button>
  95. </div>
  96. </el-dialog>
  97. </div>
  98. </template>
  99. <script>
  100. Vue.component('mall-header', {
  101. template: '#mall-header',
  102. data() {
  103. var validatePass = (rule, value, callback) => {
  104. if (value === '') {
  105. callback(new Error('请再次输入密码'));
  106. } else if (value !== this.ruleForm.new_pass) {
  107. callback(new Error('两次输入密码不一致!'));
  108. } else {
  109. callback();
  110. }
  111. };
  112. return {
  113. user: null,
  114. navs: [],
  115. mall: null,
  116. dialogFormVisible: false,
  117. ruleForm: {
  118. pass: '',
  119. checkPass: '',
  120. },
  121. loading: false, //默认不在请求中
  122. services_url: '', //默认客服链接为'',question_url
  123. course_url:'',//教程中心链接
  124. question_url:'',//常见链接
  125. is_services_show: false, //默认没有客服链接
  126. btnLoading: false,
  127. rules: {
  128. old_pass: [{
  129. required: true,
  130. message: '请输入旧密码',
  131. trigger: 'blur'
  132. },
  133. ],
  134. new_pass: [{
  135. required: true,
  136. message: '请输入新密码',
  137. trigger: 'blur'
  138. },
  139. ],
  140. check_pass: [{
  141. required: true,
  142. message: '请输入确认密码',
  143. trigger: 'blur'
  144. },
  145. {
  146. validator: validatePass,
  147. trigger: 'blur'
  148. }
  149. ]
  150. },
  151. updatePasswordStatus: 1,
  152. courseMenu: {
  153. children: [],
  154. },
  155. mch_id:0,
  156. activeIndex: "-1",
  157. };
  158. },
  159. created() {
  160. const cacheKey = '_MALL_MENUS';
  161. let data = localStorage.getItem(cacheKey);
  162. if (data) {
  163. try {
  164. data = JSON.parse(data);
  165. this.courseMenu = data.courseMenu;
  166. } catch (e) {
  167. data = false;
  168. }
  169. }
  170. this.loadData();
  171. let headerData = localStorage.getItem('mall_header_data');
  172. console.log(111111)
  173. console.log(headerData)
  174. if (headerData) {
  175. try {
  176. headerData = JSON.parse(headerData);
  177. this.user = headerData.user;
  178. this.navs = headerData.navs;
  179. this.mall = headerData.mall;
  180. // this.updatePasswordStatus = headerData.update_password_status;
  181. _aside.mall = headerData.mall;
  182. } catch (e) {
  183. headerData = false;
  184. }
  185. }
  186. },
  187. methods: {
  188. // 0.1 跳转客服
  189. toServices() {
  190. window.location.href = this.services_url;
  191. },
  192. handleOpen() {},
  193. handleClose() {},
  194. getUser() {
  195. let self = this;
  196. self.btnLoading = true;
  197. request({
  198. params: {
  199. r: 'admin/index/user'
  200. },
  201. method: 'get',
  202. data: {}
  203. }).then(e => {
  204. self.btnLoading = false;
  205. self.user = e.data.data.admin_info;
  206. }).catch(e => {
  207. console.log(e);
  208. });
  209. },
  210. getMenus() {
  211. const cacheKey = '_ADMIN_MENUS';
  212. let data = localStorage.getItem(cacheKey);
  213. if (data) {
  214. try {
  215. data = JSON.parse(data);
  216. } catch (e) {
  217. data = false;
  218. }
  219. }
  220. if (data && data.menus) {
  221. this.menus = data.menus;
  222. this.currentRouteInfo = data.currentRouteInfo;
  223. this.setActiveMenu();
  224. }
  225. },
  226. setActiveMenu() {
  227. if (!this.activeMenuId) this.activeMenuId = localStorage.getItem('_ADMIN_LAST_ACTIVE_MENU_ID');
  228. if (!this.activeSubMenuId) this.activeSubMenuId = localStorage.getItem('_ADMIN_LAST_ACTIVE_SUB_MENU_ID');
  229. if (!this.activeMenuId || !this.activeSubMenuId) return;
  230. for (let i in this.menus) {
  231. if (this.menus[i].id == this.activeMenuId) {
  232. this.subMenus = this.menus[i].children;
  233. for (let j in this.subMenus) {
  234. if (this.subMenus[j].id == this.activeSubMenuId) this.subMenus[j].active = true;
  235. }
  236. }
  237. }
  238. },
  239. loadData() {
  240. let data = localStorage.getItem('mall_header_data');
  241. if (data) {
  242. try {
  243. data = JSON.parse(data);
  244. } catch (e) {
  245. data = false;
  246. }
  247. }
  248. if (data && data.user && data.navs && data.mall){
  249. this.user = data.user;
  250. this.navs = data.navs;
  251. this.mall = data.mall;
  252. // this.updatePasswordStatus = data.update_password_status;
  253. _aside.mall = data.mall;
  254. if (data.services.length != 0) {
  255. this.services_url = decodeURIComponent(data.services.web_service_url.value);
  256. this.course_url = decodeURIComponent(data.services.course_url);
  257. this.question_url = decodeURIComponent(data.services.question_url);
  258. this.is_services_show = true;
  259. }
  260. }else{
  261. this.$request({
  262. params: {r: 'mch/client/index/header'},
  263. method: 'get',
  264. }).then(e => {
  265. localStorage.setItem('mall_header_data', JSON.stringify(e.data.data));
  266. this.user = e.data.data.user;
  267. this.navs = e.data.data.navs;
  268. this.mall = e.data.data.mall;
  269. // this.updatePasswordStatus = e.data.data.update_password_status;
  270. _aside.mall = e.data.data.mall;
  271. var data = e.data.data;
  272. if (data.services.length != 0) {
  273. //console.log(data.services);
  274. this.services_url = decodeURIComponent(data.services.web_service_url.value);
  275. this.course_url = decodeURIComponent(data.services.course_url);
  276. this.question_url = decodeURIComponent(data.services.question_url);
  277. this.is_services_show = true;
  278. }
  279. }).catch(e => {
  280. console.log(e);
  281. });
  282. }
  283. },
  284. logout() {
  285. let self = this;
  286. this.$request({
  287. params: {
  288. r: 'mch/client/auth/logout'
  289. },
  290. method: 'get',
  291. data: {}
  292. }).then(e => {
  293. // 在当前页面打开
  294. localStorage.setItem('user_key', '');
  295. localStorage.setItem('admin_menus', '');
  296. localStorage.setItem('mall_header_data', '');
  297. localStorage.setItem('mall_menus', '');
  298. localStorage.setItem('mall_info', '');
  299. console.log(1111);
  300. console.log(e.data.data.url);
  301. window.location.href=e.data.data.url;
  302. }).catch(e => {
  303. console.log(e);
  304. });
  305. },
  306. goBackToSystem() {
  307. if (_isWe7 == true) {
  308. this.$navigate({
  309. r: 'admin/account/info'
  310. });
  311. } else { //返回商城列表
  312. this.$navigate({
  313. r: 'admin/mall/index'
  314. });
  315. }
  316. },
  317. updatePassword() {
  318. this.dialogFormVisible = true;
  319. },
  320. updatePasswordSubmit(formName) {
  321. this.$refs[formName].validate((valid) => {
  322. if (valid) {
  323. this.btnLoading = true;
  324. this.$request({
  325. params: {
  326. r: 'mch/client/setting/update-password'
  327. },
  328. method: 'post',
  329. data: {
  330. old_pass: this.ruleForm.old_pass,
  331. new_pass: this.ruleForm.new_pass,
  332. check_pass: this.ruleForm.check_pass,
  333. }
  334. }).then(e => {
  335. this.btnLoading = false;
  336. if (e.data.code == 0) {
  337. this.dialogFormVisible = false;
  338. this.$message.success(e.data.msg);
  339. window.location.reload();
  340. } else {
  341. this.$message.error(e.data.msg);
  342. }
  343. }).catch(e => {
  344. console.log(e);
  345. });
  346. } else {
  347. console.log('error submit!!');
  348. return false;
  349. }
  350. });
  351. },
  352. navigateClick(params) {
  353. this.clearMenuStorage();
  354. this.$navigate(params);
  355. },
  356. clearMenuStorage() {
  357. localStorage.removeItem('open_menu_1_id');
  358. localStorage.removeItem('open_menu_2_id');
  359. localStorage.removeItem('open_menu_3_id');
  360. localStorage.removeItem('unfold_id_1');
  361. localStorage.removeItem('unfold_id_2');
  362. },
  363. handleSelect(index){
  364. console.info(index);
  365. let that = this;
  366. setTimeout(() => {
  367. that.activeIndex = -1;
  368. }, 1000);
  369. }
  370. },
  371. });
  372. </script>