index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <app-layout :haveBackground="haveBackground">
  3. <app-my-share :shareInfo="shareInfo"></app-my-share>
  4. <app-my-app v-if="config.is_add_app == 1"></app-my-app>
  5. <template v-if="type === 'mall'">
  6. <app-index @buyProduct="buyProduct" v-if="destroy" :page-hide="pageHide" :home-pages="homePages" :is_storage="is_storage" :theme="themeObject" :page_id="page_id" :is_required="is_required" :coupon_req="coupon_req"></app-index>
  7. </template>
  8. <template v-else-if="type === 'diy'">
  9. <app-diy-page @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-diy-page>
  10. </template>
  11. <app-buy-prompt v-if="config.is_purchase_frame === `1`"></app-buy-prompt>
  12. <app-attr :goods="attrGoods.goods" :attrGroupList="attrGoods.goods.attr_groups" :theme="getTheme" :show="attrGoods.attrShow"></app-attr>
  13. </app-layout>
  14. </template>
  15. <script>
  16. import { mapGetters, mapState } from 'vuex';
  17. import appIndex from '../../components/page-component/index/app-index.vue';
  18. import appDiyPage from '../../components/page-component/index/app-diy-page.vue';
  19. import appBuyPrompt from '../../components/page-component/app-buy-prompt/app-buy-prompt.vue';
  20. import appMyApp from '../../components/page-component/app-my-app/app-my-app.vue';
  21. import appMyShare from '../../components/page-component/app-my-app/app-my-share.vue';
  22. import appAttr from '../../components/page-component/app-attr/app-attr.vue';
  23. export default {
  24. name: 'index',
  25. components: {
  26. appIndex,
  27. 'app-diy-page': appDiyPage,
  28. appBuyPrompt,
  29. appMyApp,
  30. appAttr,
  31. appMyShare,
  32. },
  33. data() {
  34. return {
  35. homePages: [],
  36. type: '',
  37. is_storage: false,
  38. haveBackground: true,
  39. destroy: true,
  40. pageHide: false,
  41. is_required: true,
  42. coupon_req: false,
  43. page_id: 0,
  44. //
  45. attrGoods: {
  46. goods: {},
  47. attrShow: 0
  48. },
  49. shareInfo:''
  50. }
  51. },
  52. onShow() {
  53. // #ifdef MP-TOUTIAO
  54. this.destroy = true;
  55. // #endif
  56. this.pageHide = false;
  57. },
  58. onHide() {
  59. // #ifdef MP-TOUTIAO
  60. this.destroy = false;
  61. // #endif
  62. this.pageHide = true;
  63. },
  64. onLoad(options) {
  65. this.getUserInfo();
  66. // 测试下分支
  67. if (typeof options.scene !== 'undefined') {
  68. if (options.scene === 'share') {
  69. this.share(options);
  70. } else {
  71. this.qrcode(options);
  72. }
  73. } else {
  74. // this.$showLoading();
  75. }
  76. // #ifdef MP-ALIPAY
  77. let query = this.$store.state.page.query;
  78. if (query && typeof query.scene !== 'undefined') this.qrcode(query);
  79. // #endif
  80. if (typeof options.user_id !== 'undefined') {
  81. this.$store.dispatch('user/setTempParentId', options.user_id);
  82. }
  83. this.page_id = typeof options.page_id !== 'undefined' ? Number(options.page_id) : 0;
  84. // mall
  85. if (this.page_id === 0) {
  86. let storage = this.$storage.getStorageSync('INDEX_MALL');
  87. if (storage) {
  88. let old = new Date(storage.time.replace(/-/g, '/'));
  89. old.setMinutes(old.getMinutes() + 10);
  90. let now = new Date();
  91. let time = now.getTime() - old.getTime();
  92. if (time >= 0) {
  93. this.type = storage.type;
  94. this.homePages = storage.home_pages;
  95. this.loadMall();
  96. } else {
  97. this.type = storage.type;
  98. if (this.type === 'diy') {
  99. this.coupon_req = true;
  100. this.homePages = {}
  101. }
  102. this.$nextTick(() => {
  103. this.homePages = storage.home_pages;
  104. let that = this;
  105. if(this.homePages.navs && this.homePages.navs.length > 0) {
  106. this.homePages.navs.forEach(function(row,inedx){
  107. row.template.data.forEach(function(v,idx){
  108. if(v.id === 'background') {
  109. that.haveBackground = false;
  110. return false;
  111. }
  112. })
  113. })
  114. }
  115. });
  116. this.is_required = false;
  117. }
  118. } else {
  119. this.loadMall();
  120. }
  121. // DIY
  122. } else {
  123. this.coupon_req = true;
  124. this.loadDiy();
  125. }
  126. // #ifdef MP-WEIXIN
  127. wx.showShareMenu({
  128. menus: ['shareAppMessage', 'shareTimeline']
  129. })
  130. const updateManager = wx.getUpdateManager()
  131. if (updateManager) {
  132. updateManager.onCheckForUpdate(function (res) {
  133. // 请求完新版本信息的回调
  134. })
  135. updateManager.onUpdateReady(function () {
  136. wx.showModal({
  137. title: '更新提示',
  138. content: '新版本已经准备好,是否重启应用?',
  139. success(res) {
  140. if (res.confirm) {
  141. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  142. updateManager.applyUpdate()
  143. }
  144. }
  145. })
  146. })
  147. }
  148. // #endif
  149. },
  150. /* #ifdef MP_WEIXIN || MP_BAIDU */
  151. onPageScroll(e) {
  152. this.$store.dispatch('page/actionSetScrollTop', e.scrollTop);
  153. },
  154. /* #endif */
  155. methods: {
  156. async loadMall() {
  157. const e = await this.$request({
  158. url: this.$api.index.tplIndex,
  159. data: {
  160. page_id: 0
  161. },
  162. method: 'get'
  163. });
  164. let { code, data } = e;
  165. this.$hideLoading();
  166. if (code === 0) {
  167. this.is_storage = false;
  168. this.$popupAd.show = null;
  169. this.type = data.type;
  170. let that = this;
  171. this.is_required = true;
  172. if (this.type === 'diy') {
  173. this.coupon_req = true;
  174. this.homePages = {};
  175. }
  176. this.$nextTick(() => {
  177. this.homePages = data.home_pages;
  178. if (this.homePages.navs && that.homePages.navs.length > 0) {
  179. this.homePages.navs.forEach(function(row, inedx) {
  180. row.template.data.forEach(function(v, idx) {
  181. if (v.id === 'background') {
  182. that.haveBackground = false;
  183. return false;
  184. }
  185. })
  186. })
  187. }
  188. });
  189. this.$storage.setStorageSync('INDEX_MALL', data);
  190. }
  191. },
  192. async loadDiy() {
  193. const e = await this.$request({
  194. url: this.$api.index.tplIndex,
  195. data: {
  196. page_id: this.page_id
  197. },
  198. method: 'get'
  199. });
  200. let { code, data } = e;
  201. this.$hideLoading();
  202. if (code === 0) {
  203. this.is_storage = false;
  204. this.$popupAd.show = null;
  205. this.homePages = data.home_pages;
  206. this.type = data.type;
  207. let that = this;
  208. if (this.homePages.navs && that.homePages.navs.length > 0) {
  209. this.homePages.navs.forEach(function(row, inedx) {
  210. row.template.data.forEach(function(v, idx) {
  211. if (v.id === 'background') {
  212. that.haveBackground = false;
  213. return false;
  214. }
  215. })
  216. })
  217. }
  218. }
  219. },
  220. share(options) {
  221. if (typeof options.params !== 'undefined') {
  222. let params = JSON.parse(options.params);
  223. this.$jump({
  224. url: params.path + '?' + this.$utils.objectToUrlParams(params),
  225. open_type: 'navigate'
  226. });
  227. }
  228. },
  229. qrcode(options) {
  230. this.$request({
  231. url: this.$api.default.qrcode_parameter,
  232. data: {
  233. token: options.scene
  234. }
  235. }).then(response => {
  236. if (response.code === 0) {
  237. this.$store.dispatch('page/actionSetQeury', null);
  238. let { data, path } = response.data.detail;
  239. let url = path == 'plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin' ? `${path}` : `/${path}`;
  240. if (data) {
  241. url += '?' + this.$utils.objectToUrlParams(data);
  242. if (typeof data.user_id !== 'undefined') {
  243. this.$store.dispatch('user/setTempParentId', data.user_id)
  244. }
  245. }
  246. if (`/${path}` != '/pages/index/index' || (typeof data.page_id !== 'undefined' && data.page_id !== this.homePages.id !== 0)) {
  247. this.$jump({
  248. url: url,
  249. open_type: 'navigate'
  250. });
  251. }
  252. }
  253. }).catch(() => {});
  254. },
  255. buyProduct(data) {
  256. this.attrGoods.goods = data.goods;
  257. this.attrGoods.attrShow = data.attrShow;
  258. },
  259. getUserInfo(){
  260. let _this = this;
  261. this.$request({
  262. url: this.$api.user.user_info,
  263. }).then(response => {
  264. this.$hideLoading();
  265. console.log('-->',response.data)
  266. if (response.code === 0) {
  267. _this.shareInfo = response.data.identity
  268. }
  269. })
  270. }
  271. },
  272. onShareAppMessage() {
  273. let args = {
  274. path: '/pages/index/index',
  275. params: {}
  276. };
  277. if (this.page_id == 0) {
  278. args.title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  279. args.imageUrl = this.mall.setting.share_pic
  280. } else {
  281. args.title = this.homePages.title;
  282. args.params.page_id = this.page_id;
  283. }
  284. return this.$shareAppMessage(args);
  285. },
  286. computed: {
  287. ...mapGetters('mallConfig', {
  288. tabBarNavs: 'getNavBar',
  289. getTheme: 'getTheme',
  290. }),
  291. ...mapState('mallConfig', {
  292. config: state => state.mall.setting,
  293. mall: state => state.mall,
  294. }),
  295. themeObject:function() {
  296. return {
  297. back: this.getTheme + '-m-back ' + this.getTheme,
  298. backP: this.getTheme + '-m-back-p ' + this.getTheme,
  299. backO: this.getTheme + '-m-back-o ' + this.getTheme,
  300. theme: this.getTheme,
  301. color: this.getTheme + '-m-text ' + this.getTheme,
  302. sBack: this.getTheme + '-s-back ' + this.getTheme,
  303. border: this.getTheme + '-m-border ' + this.getTheme,
  304. }
  305. },
  306. },
  307. // #ifdef MP-WEIXIN
  308. onShareTimeline() {
  309. // 分享朋友圈beta
  310. let query = {};
  311. let title = '';
  312. if (this.page_id == 0) {
  313. title = this.mall.setting.share_title ? this.mall.setting.share_title : this.mall.name;
  314. } else {
  315. title = this.homePages.title;
  316. query.page_id = this.page_id;
  317. }
  318. return this.$shareTimeline({
  319. title: title,
  320. query: query
  321. });
  322. },
  323. // #endif
  324. };
  325. </script>