header.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. if (headerData) {
  173. try {
  174. headerData = JSON.parse(headerData);
  175. this.user = headerData.user;
  176. this.navs = headerData.navs;
  177. this.mall = headerData.mall;
  178. // this.updatePasswordStatus = headerData.update_password_status;
  179. _aside.mall = headerData.mall;
  180. } catch (e) {
  181. headerData = false;
  182. }
  183. }
  184. },
  185. methods: {
  186. // 0.1 跳转客服
  187. toServices() {
  188. window.location.href = this.services_url;
  189. },
  190. handleOpen() {},
  191. handleClose() {},
  192. getUser() {
  193. let self = this;
  194. self.btnLoading = true;
  195. request({
  196. params: {
  197. r: 'admin/index/user'
  198. },
  199. method: 'get',
  200. data: {}
  201. }).then(e => {
  202. self.btnLoading = false;
  203. self.user = e.data.data.admin_info;
  204. }).catch(e => {
  205. console.log(e);
  206. });
  207. },
  208. getMenus() {
  209. const cacheKey = '_ADMIN_MENUS';
  210. let data = localStorage.getItem(cacheKey);
  211. if (data) {
  212. try {
  213. data = JSON.parse(data);
  214. } catch (e) {
  215. data = false;
  216. }
  217. }
  218. if (data && data.menus) {
  219. this.menus = data.menus;
  220. this.currentRouteInfo = data.currentRouteInfo;
  221. this.setActiveMenu();
  222. }
  223. },
  224. setActiveMenu() {
  225. if (!this.activeMenuId) this.activeMenuId = localStorage.getItem('_ADMIN_LAST_ACTIVE_MENU_ID');
  226. if (!this.activeSubMenuId) this.activeSubMenuId = localStorage.getItem('_ADMIN_LAST_ACTIVE_SUB_MENU_ID');
  227. if (!this.activeMenuId || !this.activeSubMenuId) return;
  228. for (let i in this.menus) {
  229. if (this.menus[i].id == this.activeMenuId) {
  230. this.subMenus = this.menus[i].children;
  231. for (let j in this.subMenus) {
  232. if (this.subMenus[j].id == this.activeSubMenuId) this.subMenus[j].active = true;
  233. }
  234. }
  235. }
  236. },
  237. loadData() {
  238. let data = localStorage.getItem('mall_header_data');
  239. if (data) {
  240. try {
  241. data = JSON.parse(data);
  242. } catch (e) {
  243. data = false;
  244. }
  245. }
  246. if (data && data.user && data.navs && data.mall){
  247. this.user = data.user;
  248. this.navs = data.navs;
  249. this.mall = data.mall;
  250. // this.updatePasswordStatus = data.update_password_status;
  251. _aside.mall = data.mall;
  252. if (data.services.length != 0) {
  253. this.services_url = decodeURIComponent(data.services.web_service_url.value);
  254. this.course_url = decodeURIComponent(data.services.course_url);
  255. this.question_url = decodeURIComponent(data.services.question_url);
  256. this.is_services_show = true;
  257. }
  258. }else{
  259. this.$request({
  260. params: {r: 'store/client/index/header'},
  261. method: 'get',
  262. }).then(e => {
  263. localStorage.setItem('mall_header_data', JSON.stringify(e.data.data));
  264. this.user = e.data.data.user;
  265. this.navs = e.data.data.navs;
  266. this.mall = e.data.data.mall;
  267. // this.updatePasswordStatus = e.data.data.update_password_status;
  268. _aside.mall = e.data.data.mall;
  269. var data = e.data.data;
  270. if (data.services.length != 0) {
  271. //console.log(data.services);
  272. this.services_url = decodeURIComponent(data.services.web_service_url.value);
  273. this.course_url = decodeURIComponent(data.services.course_url);
  274. this.question_url = decodeURIComponent(data.services.question_url);
  275. this.is_services_show = true;
  276. }
  277. }).catch(e => {
  278. console.log(e);
  279. });
  280. }
  281. },
  282. logout() {
  283. let self = this;
  284. this.$request({
  285. params: {
  286. r: 'store/client/auth/logout'
  287. },
  288. method: 'get',
  289. data: {}
  290. }).then(e => {
  291. // 在当前页面打开
  292. localStorage.setItem('user_key', '');
  293. localStorage.setItem('admin_menus', '');
  294. localStorage.setItem('mall_header_data', '');
  295. localStorage.setItem('mall_menus', '');
  296. localStorage.setItem('mall_info', '');
  297. localStorage.setItem('store_info', '');
  298. window.location.href=e.data.data.url;
  299. }).catch(e => {
  300. console.log(e);
  301. });
  302. },
  303. goBackToSystem() {
  304. if (_isWe7 == true) {
  305. this.$navigate({
  306. r: 'admin/account/info'
  307. });
  308. } else { //返回商城列表
  309. this.$navigate({
  310. r: 'admin/mall/index'
  311. });
  312. }
  313. },
  314. updatePassword() {
  315. this.dialogFormVisible = true;
  316. },
  317. updatePasswordSubmit(formName) {
  318. this.$refs[formName].validate((valid) => {
  319. if (valid) {
  320. this.btnLoading = true;
  321. this.$request({
  322. params: {
  323. r: 'store/client/store/update-password'
  324. },
  325. method: 'post',
  326. data: {
  327. old_pass: this.ruleForm.old_pass,
  328. new_pass: this.ruleForm.new_pass,
  329. check_pass: this.ruleForm.check_pass,
  330. }
  331. }).then(e => {
  332. this.btnLoading = false;
  333. if (e.data.code == 0) {
  334. this.dialogFormVisible = false;
  335. this.$message.success(e.data.msg);
  336. window.location.reload();
  337. } else {
  338. this.$message.error(e.data.msg);
  339. }
  340. }).catch(e => {
  341. console.log(e);
  342. });
  343. } else {
  344. console.log('error submit!!');
  345. return false;
  346. }
  347. });
  348. },
  349. navigateClick(params) {
  350. this.clearMenuStorage();
  351. this.$navigate(params);
  352. },
  353. clearMenuStorage() {
  354. localStorage.removeItem('open_menu_1_id');
  355. localStorage.removeItem('open_menu_2_id');
  356. localStorage.removeItem('open_menu_3_id');
  357. localStorage.removeItem('unfold_id_1');
  358. localStorage.removeItem('unfold_id_2');
  359. },
  360. handleSelect(index){
  361. console.info(index);
  362. let that = this;
  363. setTimeout(() => {
  364. that.activeIndex = -1;
  365. }, 1000);
  366. }
  367. },
  368. });
  369. </script>