index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <app-layout :haveBackground="haveBackground">
  3. <!-- #ifdef MP -->
  4. <app-my-app v-if="config.is_add_app == 1"></app-my-app>
  5. <!-- #endif -->
  6. <template v-if="type === 'mall'">
  7. <app-nav-bar v-if="navbarStatus" :fixed="true" :title="mall.name" :color="tabBarNavs.top_text_color"
  8. :background-color="tabBarNavs.top_background_color"></app-nav-bar>
  9. <app-index :isShowAttention="isShowAttention" @buyProduct="buyProduct" v-if="destroy" :page-hide="pageHide" :home-pages="homePages" :is_storage="is_storage" :theme="getTheme" :page_id="page_id" :is_required="is_required" :coupon_req="coupon_req"></app-index>
  10. </template>
  11. <template v-else-if="type === 'diy'">
  12. <app-nav-bar v-if="navbarStatus"
  13. :fixed="true"
  14. :background-color="diy__app_nav_bar.backgroundColor"
  15. :left-icon="diy__app_nav_bar.leftIcon"
  16. :link="diy__app_nav_bar.link"
  17. :title="homePages.title"
  18. :xStyle="diy__app_nav_bar.style"
  19. :hasMallSetting="diy__app_nav_bar.hasMallSetting"
  20. :color="diy__app_nav_bar.color"
  21. :position="diy__app_nav_bar.position"
  22. :placeholder="diy__app_nav_bar.placeholder"
  23. :placeholderColor="diy__app_nav_bar.placeholderColor"
  24. ></app-nav-bar>
  25. <app-diy-page @buyProduct="buyProduct" v-if="destroy" :page-hide="pageHide" :home-pages="homePages"
  26. :is_storage="is_storage" :theme="getTheme" :page_id="page_id" :is_required="is_required"
  27. :coupon_req="coupon_req"></app-diy-page>
  28. </template>
  29. <app-buy-prompt :isShowAttention="isShowAttention" v-if="config.is_purchase_frame === `1`"></app-buy-prompt>
  30. <app-attr :goods="attrGoods.goods" :attrGroupList="attrGoods.goods.attr_groups" :theme="getTheme" :show="attrGoods.attrShow"></app-attr>
  31. </app-layout>
  32. </template>
  33. <script>
  34. import { mapGetters, mapState } from 'vuex';
  35. import appIndex from '@/components/page-component/index/app-index.vue';
  36. import appDiyPage from '@/components/page-component/index/app-diy-page.vue';
  37. import appBuyPrompt from '@/components/page-component/app-buy-prompt/app-buy-prompt.vue';
  38. // #ifdef MP
  39. import appMyApp from '@/components/page-component/app-my-app/app-my-app.vue';
  40. // #endif
  41. import appAttr from '@/components/page-component/app-attr/app-attr.vue';
  42. import appNavBar from '@/components/page-component/index/app-nav-bar.vue';
  43. export default {
  44. name: 'index',
  45. components: {
  46. appIndex,
  47. 'app-diy-page': appDiyPage,
  48. appBuyPrompt,
  49. // #ifdef MP
  50. appMyApp,
  51. // #endif
  52. appAttr,
  53. appNavBar
  54. },
  55. data() {
  56. return {
  57. diy__app_nav_bar: {},
  58. homePages: {},
  59. type: '',
  60. is_storage: false,
  61. haveBackground: true,
  62. destroy: true,
  63. pageHide: false,
  64. is_required: true,
  65. coupon_req: false,
  66. page_id: 0,
  67. //
  68. attrGoods: {
  69. goods: {},
  70. attrShow: 0
  71. },
  72. // #ifdef H5
  73. pagePath: '',
  74. // #endif
  75. isShowAttention: false
  76. }
  77. },
  78. onShow() {
  79. // #ifdef MP-TOUTIAO || H5
  80. this.destroy = true;
  81. // #endif
  82. this.pageHide = false;
  83. },
  84. onHide() {
  85. // #ifdef MP-TOUTIAO || H5
  86. this.destroy = false;
  87. // #endif
  88. this.pageHide = true;
  89. },
  90. onLoad(options) {
  91. console.log(mapGetters)
  92. this.$commonLoad.onload(options);
  93. // #ifdef H5
  94. this.$jwx.config();
  95. // #endif
  96. this.load(options);
  97. // #ifdef MP-WEIXIN
  98. wx.showShareMenu({
  99. menus: ['shareAppMessage', 'shareTimeline']
  100. });
  101. const updateManager = wx.getUpdateManager();
  102. if (updateManager) {
  103. updateManager.onCheckForUpdate(function (res) {
  104. // 请求完新版本信息的回调
  105. })
  106. updateManager.onUpdateReady(function () {
  107. wx.showModal({
  108. title: '更新提示',
  109. content: '新版本已经准备好,是否重启应用?',
  110. success(res) {
  111. if (res.confirm) {
  112. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  113. updateManager.applyUpdate()
  114. }
  115. }
  116. })
  117. })
  118. }
  119. // #endif
  120. },
  121. /* #ifdef MP_WEIXIN || MP_BAIDU */
  122. onPageScroll(e) {
  123. this.$store.dispatch('page/actionSetScrollTop', e.scrollTop);
  124. },
  125. /* #endif */
  126. methods: {
  127. async loadMall() {
  128. const e = await this.$request({
  129. url: this.$api.index.tplIndex,
  130. data: {
  131. page_id: 0
  132. },
  133. method: 'get'
  134. });
  135. let { code, data } = e;
  136. this.$hideLoading();
  137. if (code === 0) {
  138. this.is_storage = false;
  139. this.$popupAd.show = null;
  140. this.type = data.type;
  141. let that = this;
  142. this.is_required = true;
  143. if (this.type === 'diy') {
  144. this.coupon_req = true;
  145. this.homePages = {};
  146. }
  147. this.$nextTick(() => {
  148. this.homePages = data.home_pages;
  149. if (this.homePages.navs && that.homePages.navs.length > 0) {
  150. this.homePages.navs.forEach(function(row, inedx) {
  151. row.template.data.forEach(function(v, idx) {
  152. if (v.id === 'background') {
  153. that.haveBackground = false;
  154. }
  155. if (v.id === 'app-nav-bar') {
  156. that.diy__app_nav_bar = v.data;
  157. }
  158. })
  159. })
  160. }
  161. });
  162. this.$storage.setStorageSync('INDEX_MALL', data);
  163. }
  164. },
  165. async loadDiy() {
  166. const e = await this.$request({
  167. url: this.$api.index.tplIndex,
  168. data: {
  169. page_id: this.page_id
  170. },
  171. method: 'get'
  172. });
  173. let { code, data } = e;
  174. this.$hideLoading();
  175. if (code === 0) {
  176. this.is_storage = false;
  177. this.$popupAd.show = null;
  178. this.homePages = data.home_pages;
  179. this.type = data.type;
  180. let that = this;
  181. if (this.homePages.navs && that.homePages.navs.length > 0) {
  182. this.homePages.navs.forEach(function(row, inedx) {
  183. row.template.data.forEach(function(v, idx) {
  184. if (v.id === 'background') {
  185. that.haveBackground = false;
  186. }
  187. if (v.id === 'app-nav-bar') {
  188. that.diy__app_nav_bar = v.data;
  189. }
  190. })
  191. })
  192. }
  193. }
  194. },
  195. delHistory(){
  196. // #ifdef H5
  197. console.error('delete history');
  198. let originUrl = window.location.href;
  199. let parseUrl = new URL(window.location.href);
  200. originUrl = originUrl.replace(parseUrl.origin, "")
  201. let lastIndex = originUrl.lastIndexOf('?')
  202. if (lastIndex !== -1) {
  203. let end = originUrl.slice(lastIndex + 1);
  204. let params = end.split('&');
  205. params = params.filter(function (item) {
  206. if (/^scene=\S/.test(item)) {
  207. return false;
  208. }
  209. if (/^params=\S/.test(item)) {
  210. return false;
  211. }
  212. return true;
  213. });
  214. params = params.join('&');
  215. originUrl = originUrl.slice(0, lastIndex + 1) + params;
  216. if (originUrl.charAt(originUrl.length - 1) === '?') {
  217. originUrl = originUrl.substr(0, originUrl.length - 1)
  218. }
  219. }
  220. window.history.replaceState(null, '', originUrl);
  221. window.history.pushState(null, '', originUrl);
  222. // #endif
  223. },
  224. share(options) {
  225. if (typeof options.params !== 'undefined') {
  226. let params;
  227. // #ifdef MP
  228. params = JSON.parse(options.params);
  229. // #endif
  230. // #ifdef H5
  231. this.delHistory();
  232. params = JSON.parse(atob(options.params));
  233. // #endif
  234. this.$jump({
  235. url: params.path + '?' + this.$utils.objectToUrlParams(params),
  236. open_type: 'navigate'
  237. });
  238. }
  239. },
  240. qrcode(options) {
  241. this.$request({
  242. url: this.$api.default.qrcode_parameter,
  243. data: {
  244. token: options.scene
  245. }
  246. }).then(response => {
  247. if (response.code === 0) {
  248. this.$store.dispatch('page/actionSetQeury', null);
  249. let { data, path } = response.data.detail;
  250. let url = path == 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin' ? `${path}` : `/${path}`;
  251. if (data) {
  252. url += '?' + this.$utils.objectToUrlParams(data);
  253. if (typeof data.user_id !== 'undefined') {
  254. this.$store.dispatch('user/setTempParentId', data.user_id)
  255. }
  256. }
  257. if (`/${path}` != '/pages/index/index' || (typeof data.page_id !== 'undefined' && data.page_id !== this.homePages.id !== 0)) {
  258. this.delHistory();
  259. this.$jump({
  260. url: url,
  261. open_type: 'navigate'
  262. });
  263. }
  264. }
  265. }).catch(() => {});
  266. },
  267. buyProduct(data) {
  268. this.attrGoods.goods = data.goods;
  269. this.attrGoods.attrShow = data.attrShow;
  270. },
  271. load(options) {
  272. // 测试下分支
  273. if (typeof options.scene !== 'undefined') {
  274. if (options.scene === 'share') {
  275. this.share(options);
  276. } else {
  277. this.qrcode(options);
  278. }
  279. } else {
  280. // this.$showLoading();
  281. }
  282. // #ifdef MP-ALIPAY
  283. let query = this.$store.state.page.query;
  284. if (query && typeof query.scene !== 'undefined') this.qrcode(query);
  285. // #endif
  286. if (typeof options.user_id !== 'undefined') {
  287. this.$store.dispatch('user/setTempParentId', options.user_id);
  288. }
  289. this.page_id = typeof options.page_id !== 'undefined' ? Number(options.page_id) : 0;
  290. // mall
  291. if (this.page_id === 0) {
  292. // #ifdef H5
  293. this.$request({
  294. url: this.$api.index.indexWechat
  295. });
  296. // #endif
  297. let storage = this.$storage.getStorageSync('INDEX_MALL');
  298. if (storage && storage.time) {
  299. let old = new Date(storage.time.replace(/-/g, '/'));
  300. old.setMinutes(old.getMinutes() + 10);
  301. let now = new Date();
  302. let time = now.getTime() - old.getTime();
  303. if (time >= 0) {
  304. this.type = storage.type;
  305. this.homePages = storage.home_pages;
  306. this.loadMall();
  307. } else {
  308. this.type = storage.type;
  309. if (this.type === 'diy') {
  310. this.coupon_req = true;
  311. this.homePages = {}
  312. }
  313. this.$nextTick(() => {
  314. this.homePages = storage.home_pages;
  315. let that = this;
  316. if(this.homePages.navs && this.homePages.navs.length > 0) {
  317. this.homePages.navs.forEach(function(row,inedx){
  318. row.template.data.forEach(function(v,idx) {
  319. if (v.id === 'background') {
  320. that.haveBackground = false;
  321. }
  322. if (v.id === 'app-nav-bar') {
  323. that.diy__app_nav_bar = v.data;
  324. }
  325. })
  326. })
  327. }
  328. });
  329. this.is_required = false;
  330. }
  331. } else {
  332. this.loadMall();
  333. }
  334. // DIY
  335. } else {
  336. this.coupon_req = true;
  337. this.loadDiy();
  338. }
  339. // #ifdef H5
  340. if (this.userInfo && this.userInfo.other_config && this.$jwx.isWechat()) {
  341. this.isShowAttention = this.userInfo.subscribe == 0;
  342. }
  343. let args = {
  344. path: '/pages/index/index',
  345. params: {}
  346. };
  347. if (this.page_id == 0) {
  348. args.title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  349. args.imageUrl = this.mall.setting.share_pic ? this.mall.setting.share_pic : '';
  350. args.desc = this.mall.name;
  351. } else {
  352. args.title = this.homePages.title;
  353. args.params.page_id = this.page_id;
  354. args.imageUrl = this.mall.setting.share_pic ? this.mall.setting.share_pic : '';
  355. args.desc = this.mall.name;
  356. }
  357. this.$shareAppMessage(args);
  358. // #endif
  359. },
  360. },
  361. // #ifdef MP
  362. onShareAppMessage() {
  363. let args = {
  364. path: '/pages/index/index',
  365. params: {}
  366. };
  367. if (this.page_id == 0) {
  368. args.title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  369. args.imageUrl = this.mall.setting.share_pic
  370. } else {
  371. args.title = this.homePages.title;
  372. args.params.page_id = this.page_id;
  373. }
  374. return this.$shareAppMessage(args);
  375. },
  376. // #endif
  377. computed: {
  378. navbarStatus: function () {
  379. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO
  380. return ['windows', 'mac'].indexOf(this.systemInfo.platform) === -1;
  381. // #endif
  382. // #ifdef H5
  383. return !this.$jwx.isWechat();
  384. // #endif
  385. // #ifdef MP-ALIPAY
  386. return false;
  387. // #endif
  388. },
  389. ...mapGetters('mallConfig', {
  390. tabBarNavs: 'getNavBar',
  391. getTheme: 'getTheme',
  392. }),
  393. ...mapGetters({
  394. userInfo: 'user/info',
  395. }),
  396. ...mapState({
  397. systemInfo: state => state.gConfig.systemInfo
  398. }),
  399. ...mapState('mallConfig', {
  400. config: state => state.mall.setting,
  401. mall: state => state.mall,
  402. }),
  403. isSign: function () {
  404. return this.$storage.getStorageSync('isSign');
  405. },
  406. },
  407. // #ifdef MP-WEIXIN
  408. onShareTimeline() {
  409. // 分享朋友圈beta
  410. let query = {};
  411. let title = '';
  412. if (this.page_id == 0) {
  413. title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  414. } else {
  415. title = this.homePages.title;
  416. query.page_id = this.page_id;
  417. }
  418. return this.$shareTimeline({
  419. title: title,
  420. query: query
  421. });
  422. },
  423. // #endif
  424. // #ifdef H5
  425. watch: {
  426. $route: {
  427. handler: function(to) {
  428. this.pagePath = to.meta.pagePath;
  429. if (to.meta.pagePath === 'pages/index/index') {
  430. this.homePages = {};
  431. this.load(to.query);
  432. }
  433. }
  434. },
  435. userInfo: {
  436. handler: function(newVal) {
  437. if (newVal && newVal.other_config && this.pagePath === 'pages/index/index' && this.$jwx.isWechat()) {
  438. this.isShowAttention = this.userInfo.other_config.includes('index') && this.userInfo.subscribe == 0;
  439. }
  440. }
  441. }
  442. }
  443. // #endif
  444. };
  445. </script>
  446. <style lang="scss">
  447. </style>