diff --git a/App.vue b/App.vue index 6daec424..1fdf0f8a 100644 --- a/App.vue +++ b/App.vue @@ -161,6 +161,12 @@ // 未登录页面缓存记录key cache_user_no_login_page_status_data_key: 'cache_user_no_login_page_status_data_key', + // 首页数据缓存key + cache_index_data_key: 'cache_index_data_key', + + // 商品数据缓存key + cache_goods_data_key: 'cache_goods_data_key', + // 默认用户头像 default_user_head_src: '/static/images/common/user.png', @@ -1212,8 +1218,14 @@ * default_value 默认值 */ get_config(key, default_value) { - var value = null; + // 获取全部缓存 var config = uni.getStorageSync(this.data.cache_config_info_key) || null; + if((key || null) == null) { + return config; + } + + // key缓存获取 + var value = null; if (config != null) { // 数据读取 var arr = key.split('.'); @@ -1253,55 +1265,71 @@ uni.getNetworkType({ success: function (res) { if (res.networkType != 'none') { - uni.request({ - url: self.get_request_url('common', 'base'), - method: 'POST', - data: { - is_key: 1, - }, - dataType: 'json', - success: (res) => { - if (res.data.code == 0) { - // 记录已初始化公共数据状态 - self.data.common_data_init_status = 1; + // 获取配置本地缓存 + var config = self.get_config(); + if(config != null) { + // 公共配置初始化返回处理 + self.init_config_result_handle(config, self); + } - // 配置存储 - var data = res.data.data; - uni.setStorageSync(self.data.cache_config_info_key, data); + // 没有公共缓存,或者还未初始化则走接口 + if(config == null || self.data.common_data_init_status == 0) { + uni.request({ + url: self.get_request_url('common', 'base'), + method: 'POST', + data: { + is_key: 1, + }, + dataType: 'json', + success: (res) => { + if (res.data.code == 0) { + // 配置存储 + var data = res.data.data; + uni.setStorageSync(self.data.cache_config_info_key, data); - // 主题设置 - self.set_theme_value(data.plugins_themestyle_data); - - // 设置底部菜单 - self.set_tabbar(data.plugins_themestyle_data); - - // 用户自动登录处理 - self.user_auto_login_handle(); - } else { - self.showToast(res.data.msg); - // 站点关闭状态则 记录已初始化公共数据状态 - if (res.data.code == -10000) { - self.data.common_data_init_status = 1; + // 公共配置初始化返回处理 + self.init_config_result_handle(data, self); + } else { + self.showToast(res.data.msg); + // 站点关闭状态则 记录已初始化公共数据状态 + if (res.data.code == -10000) { + self.data.common_data_init_status = 1; + } + + // 首次则再次初始化配置、站点关闭状态则不处理 + if (status == 0 && self.data.common_data_init_status == 0) { + self.init_config(1); + } } - - // 首次则再次初始化配置、站点关闭状态则不处理 - if (status == 0 && self.data.common_data_init_status == 0) { + }, + fail: () => { + // 首次则再次初始化配置 + if (status == 0) { self.init_config(1); } - } - }, - fail: () => { - // 首次则再次初始化配置 - if (status == 0) { - self.init_config(1); - } - }, - }); + }, + }); + } } }, }); }, + // 公共配置初始化返回处理 + init_config_result_handle(data, self) { + // 记录已初始化公共数据状态 + self.data.common_data_init_status = 1; + + // 主题设置 + self.set_theme_value(data.plugins_themestyle_data); + + // 设置底部菜单 + self.set_tabbar(data.plugins_themestyle_data); + + // 用户自动登录处理 + self.user_auto_login_handle(); + }, + /** * 配置是否有效(100毫秒检验一次、最多检验100次) * object 回调操作对象 @@ -1996,23 +2024,20 @@ }, // 清除用户缓存 - remove_user_cache_event() { + remove_user_cache_event(is_remove_user = true) { // 当前平台 var client_value = this.application_client(); - // 用户登录缓存 - uni.removeStorageSync(this.data.cache_user_login_key); - // 用户信息缓存 - uni.removeStorageSync(this.data.cache_user_info_key); + // 是否清除用户登录信息 + if(is_remove_user) { + // 用户登录缓存 + uni.removeStorageSync(this.data.cache_user_login_key); + // 用户信息缓存 + uni.removeStorageSync(this.data.cache_user_info_key); + } // 未登录提示缓存记录 uni.removeStorageSync(this.data.cache_user_no_login_page_status_data_key); // 非小程序则两秒后回到首页 - this.showToast(i18n.t('shopxo-uniapp.app.'+(client_value == 'mp' ? '0gwt7z' : '87yghj')), 'success'); - var url = this.data.tabbar_pages[0]; - setTimeout(function () { - uni.switchTab({ - url: url, - }); - }, 1500); + this.showToast(i18n.t('shopxo-uniapp.app.'+((client_value == 'mp' || !is_remove_user) ? '0gwt7z' : '87yghj')), 'success'); }, // 是否站点变灰 @@ -2564,6 +2589,17 @@ clearInterval(this.data.weixin_privacy_setting_timer); }, + // 商品访问数据存储缓存 + goods_data_cache_handle(goods_id, goods_data = null) { + var key = this.data.cache_goods_data_key; + if((goods_data || null) == null) { + var res = uni.getStorageSync(key) || null; + return (res != null && res.id == goods_id) ? res : null; + } else { + uni.setStorageSync(key, goods_data); + } + }, + // 页面导航标题处理 set_pages_navigation_bar_title() { // 当前平台 diff --git a/components/cart/cart.vue b/components/cart/cart.vue index 792be5b1..c29eabc6 100644 --- a/components/cart/cart.vue +++ b/components/cart/cart.vue @@ -61,7 +61,7 @@ - + @@ -74,7 +74,7 @@ - + {{ item.title }} @@ -1187,6 +1187,17 @@ goods_list: temp_goods_list, }); } + }, + + // 商品事件 + goods_event(e) { + // 商品数据缓存处理 + var goods = this.data_list[e.currentTarget.dataset.index]; + goods['id'] = goods.goods_id; + app.globalData.goods_data_cache_handle(goods.id, goods); + + // 调用公共打开url地址 + app.globalData.url_event(e); }, // url事件 @@ -1528,8 +1539,13 @@ } .scroll-box-popup .content .item .cart-goods-image { width: 100%; + } + .scroll-box-popup .cart-selected { + background-color: #fff; + height: 36rpx; + border-radius: 50%; } - .alias { + .scroll-box-popup .alias { margin-left: 20rpx; padding: 0 12rpx; line-height: 40rpx; diff --git a/components/goods-list/goods-list.vue b/components/goods-list/goods-list.vue index b6bf0c58..d4ed79c4 100644 --- a/components/goods-list/goods-list.vue +++ b/components/goods-list/goods-list.vue @@ -14,7 +14,7 @@ - + {{ item.title }} @@ -58,7 +58,7 @@ - + {{ item.title }} @@ -125,7 +125,7 @@ - + {{ item.title }} @@ -331,6 +331,7 @@ ); } }, + // 加入购物车成功回调 goods_cart_back_event(e) { // 增加数量 @@ -378,10 +379,22 @@ } this.$emit('CartSuccessEvent', { ...e, ...{ goods_list: new_data.goods_list, goods: goods } }); }, + + // 商品事件 + goods_event(e) { + // 商品数据缓存处理 + var goods = this.data.goods_list[e.currentTarget.dataset.index]; + app.globalData.goods_data_cache_handle(goods.id, goods); + + // 调用公共打开url地址 + app.globalData.url_event(e); + }, + // url事件 url_event(e) { app.globalData.url_event(e); }, + // 购物车角标变化回调 goods_badge_change() { this.$emit('goods_badge_change'); diff --git a/lang/en.json b/lang/en.json index efa9bff1..2e52950d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -238,6 +238,8 @@ "jw378f": "Authorized User Information", "np9177": "Bind phone", "tgsa4d": "Bind email", + "876tdf": "Bind account", + "87yui2": "Bind successful", "158yg2": "Login with mobile verification code", "r329eu": "Email verification code login", "39hn6v": "Account password registration", diff --git a/lang/zh.json b/lang/zh.json index 112cba3b..d3d5ca47 100644 --- a/lang/zh.json +++ b/lang/zh.json @@ -241,6 +241,8 @@ "jw378f": "授权用户信息", "np9177": "绑定手机", "tgsa4d": "绑定邮箱", + "876tdf": "绑定账户", + "87yui2": "绑定成功", "158yg2": "手机验证码登录", "r329eu": "邮箱验证码登录", "39hn6v": "账号密码注册", diff --git a/pages/goods-category/goods-category.vue b/pages/goods-category/goods-category.vue index 2cfbf006..7764d90f 100644 --- a/pages/goods-category/goods-category.vue +++ b/pages/goods-category/goods-category.vue @@ -119,7 +119,7 @@ - + @@ -287,7 +287,7 @@ - + @@ -563,7 +563,7 @@ init(params = {}) { // 网络检查 if ((params || null) == null || (params.loading || 0) == 0) { - app.globalData.network_type_handle(this, 'init'); + app.globalData.network_type_handle(this, 'init', params); return false; } @@ -873,6 +873,22 @@ url: '/pages/goods-search/goods-search' + ((e || null) == null ? '' : '?keywords=' + e), }); } + }, + + // 商品事件 + goods_event(e) { + // 商品数据缓存处理 + var index = e.currentTarget.dataset.index; + if(e.currentTarget.dataset.type == 'cart') { + var goods = this.cart.data[index]; + goods['id'] = goods['goods_id']; + } else { + var goods = this.data_list[index]; + } + app.globalData.goods_data_cache_handle(goods.id, goods); +console.log(goods) + // 调用公共打开url地址 + app.globalData.url_event(e); }, // url事件 diff --git a/pages/goods-detail/goods-detail.vue b/pages/goods-detail/goods-detail.vue index 08f208f5..a8c8d61a 100644 --- a/pages/goods-detail/goods-detail.vue +++ b/pages/goods-detail/goods-detail.vue @@ -50,7 +50,7 @@ - + @@ -301,9 +301,9 @@ {{$t('goods-detail.goods-detail.znz76d')}} - ({{ goods.comments_count }}) + ({{ goods.comments_count || 0 }}) - {{$t('goods-detail.goods-detail.1rqkjt')}}{{ goods.comments_score.rate }}% + {{$t('goods-detail.goods-detail.1rqkjt')}}{{ goods.comments_score.rate || 0 }}% @@ -460,7 +460,7 @@ - + @@ -469,7 +469,7 @@ - + @@ -661,6 +661,7 @@ data_bottom_line_status: false, data_list_loding_status: 1, data_list_loding_msg: '', + data_loading_status: 0, params: null, system_info: system_info, photo_height: win_width <= 0 ? '55vh' : app.globalData.window_width_handle(win_width) + 'px', @@ -900,6 +901,13 @@ // 获取数据 init() { + // 缓存数据 + var goods = app.globalData.goods_data_cache_handle(this.params.id); + if(goods != null) { + this.init_result_data_handle(goods); + } + + // 获取数据 uni.request({ url: app.globalData.get_request_url('detail', 'goods'), method: 'POST', @@ -910,26 +918,17 @@ if (res.data.code == 0) { var data = res.data.data; var goods = data.goods; - var price_text_arr = [this.$t('goods-detail.goods-detail.bogx42'), this.$t('goods-category.goods-category.g2u3lf'), this.$t('goods-detail.goods-detail.3kdgjl')]; + + // 商品数据 + this.init_result_data_handle(goods); + + // 基础数据 var upd_data = { - data_bottom_line_status: true, - data_list_loding_status: 3, - goods: goods, - indicator_dots: goods.photo.length > 1, - autoplay: goods.photo.length > 1, + data_loading_status: 1, guess_you_like: data.guess_you_like || [], - goods_photo: goods.photo, nav_more_list: data.nav_more_list || [], - goods_content_app: goods.content_app || [], - nav_favor_button_info: { - text: (goods.is_favor == 1 ? this.$t('goods-detail.goods-detail.by7052') : '') + this.$t('goods-detail.goods-detail.dco1sc'), - status: goods.is_favor, - }, buy_button: data.buy_button || null, top_nav_title_data: data.middle_tabs_nav || [], - goods_spec_base_price: goods.price, - goods_spec_base_original_price: goods.original_price || 0, - show_field_price_text: price_text_arr.indexOf(goods.show_field_price_text) != -1 ? null : goods.show_field_price_text.replace(/<[^>]+>/g, '') || null, plugins_seckill_data: data.plugins_seckill_data || null, plugins_coupon_data: data.plugins_coupon_data || null, quick_nav_cart_count: data.cart_total.buy_number || 0, @@ -1013,6 +1012,32 @@ }, }); }, + + init_result_data_handle(goods) { + // 价格字段 + var price_text_arr = [this.$t('goods-detail.goods-detail.bogx42'), this.$t('goods-category.goods-category.g2u3lf'), this.$t('goods-detail.goods-detail.3kdgjl')]; + // 相册处理 + var photo = goods.photo || []; + if(photo.length == 0 && (goods.images || null) != null) { + photo.push({images: goods.images}); + } + this.setData({ + data_bottom_line_status: true, + data_list_loding_status: 3, + goods: goods, + indicator_dots: photo.length > 1, + autoplay: photo.length > 1, + goods_photo: photo, + goods_content_app: goods.content_app || [], + nav_favor_button_info: { + text: (goods.is_favor == 1 ? this.$t('goods-detail.goods-detail.by7052') : '') + this.$t('goods-detail.goods-detail.dco1sc'), + status: goods.is_favor, + }, + goods_spec_base_price: goods.price, + goods_spec_base_original_price: goods.original_price || 0, + show_field_price_text: price_text_arr.indexOf(goods.show_field_price_text) != -1 ? null : goods.show_field_price_text.replace(/<[^>]+>/g, '') || null, + }); + }, // 底部业务导航数量处理 bottom_nav_bus_number_handle() { diff --git a/pages/index/index.vue b/pages/index/index.vue index 7fb340b3..664af5c7 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -487,37 +487,44 @@ // 获取数据 init(params = {}) { + // 本地缓存数据 + var key = app.globalData.data.cache_index_data_key; + var upd_data = uni.getStorageSync(key) || null; + if(upd_data != null) { + // 先使用缓存数据展示 + this.setData(upd_data); + + // 初始化返回公共处理 + this.init_result_common_handle(); + + // 已有本地缓存则直接取远程有效数据(默认首次取的是远程缓存数据) + params['is_cache'] = 0; + } + // 网络检查 if((params || null) == null || (params.loading || 0) == 0) { - app.globalData.network_type_handle(this, 'init'); + app.globalData.network_type_handle(this, 'init', params); return false; } - // 请求数据 - this.setData({ - data_list_loding_status: 1, - }); + // 没有缓存数据则开启加载层 + if(upd_data == null) { + this.setData({ + data_list_loding_status: 1, + }); + } + // 请求远程数据 uni.request({ url: app.globalData.get_request_url('index', 'index'), method: 'POST', - data: {}, + data: params, dataType: 'json', success: (res) => { uni.stopPullDownRefresh(); - // 获取最新缓存 - if (this.load_status == 0) { - this.init_config(true); - } - + // 数据处理 var data = res.data.data; - var theme_view = app.globalData.get_theme_value_view(); - var theme_color = app.globalData.get_theme_color(); - var common_static_url = app.globalData.get_static_url('common'); - var seckill_static_url = app.globalData.get_static_url('seckill', true) + 'app/'; - var static_url = app.globalData.get_static_url('home'); if (res.data.code == 0) { - this.setData({ - top_content_search_content_style: 'background-image: url("' + static_url + 'nav-top.png");', + var upd_data = { data_bottom_line_status: true, banner_list: data.banner_list || [], navigation: data.navigation || [], @@ -541,7 +548,11 @@ plugins_shop_data: data.plugins_shop_data || null, plugins_binding_data: data.plugins_binding_data || null, plugins_magic_data: data.plugins_magic_data || null, - }); + }; + this.setData(upd_data); + + // 存储缓存 + uni.setStorageSync(key, upd_data); // 弹屏广告插件处理 this.plugins_popupscreen_handle(); @@ -552,6 +563,11 @@ } else { app.globalData.set_tab_bar_badge(2, 1, this.cart_total); } + + // 是否需要重新加载数据 + if(parseInt(data.is_result_data_cache || 0) == 1) { + this.init({is_cache: 0}); + } } else { this.setData({ data_list_loding_status: 0, @@ -561,26 +577,8 @@ app.globalData.showToast(res.data.msg); } - // 轮播数据处理 - if (this.load_status == 0 || (this.top_content_search_bg_color || null) == null) { - var color = (this.banner_list && this.banner_list.length > 0 && (this.banner_list[0]['bg_color'] || null) != null) ? this.banner_list[0]['bg_color'] : theme_color; - this.change_banner(color); - } - - // 公共数据 - this.setData({ - theme_view: theme_view, - theme_color: theme_color, - common_static_url: common_static_url, - seckill_static_url: seckill_static_url, - static_url: static_url, - load_status: 1, - }); - - // 分享菜单处理、延时执行,确保基础数据已加载完成 - setTimeout(function () { - app.globalData.page_share_handle(); - }, 3000); + // 初始化返回公共处理 + this.init_result_common_handle(); }, fail: () => { // 轮播数据处理 @@ -600,6 +598,37 @@ }); }, + // 初始化返回公共处理 + init_result_common_handle() { + var theme_view = app.globalData.get_theme_value_view(); + var theme_color = app.globalData.get_theme_color(); + var common_static_url = app.globalData.get_static_url('common'); + var seckill_static_url = app.globalData.get_static_url('seckill', true) + 'app/'; + var static_url = app.globalData.get_static_url('home'); + + // 轮播数据处理 + if (this.load_status == 0 || (this.top_content_search_bg_color || null) == null) { + var color = (this.banner_list && this.banner_list.length > 0 && (this.banner_list[0]['bg_color'] || null) != null) ? this.banner_list[0]['bg_color'] : theme_color; + this.change_banner(color); + } + + // 公共数据 + this.setData({ + top_content_search_content_style: 'background-image: url("' + static_url + 'nav-top.png");', + theme_view: theme_view, + theme_color: theme_color, + common_static_url: common_static_url, + seckill_static_url: seckill_static_url, + static_url: static_url, + load_status: 1, + }); + + // 分享菜单处理、延时执行,确保基础数据已加载完成 + setTimeout(function () { + app.globalData.page_share_handle(); + }, 3000); + }, + // 选择用户地理位置 choose_user_location_event(e) { app.globalData.choose_user_location_event(); diff --git a/pages/login/login.vue b/pages/login/login.vue index d377f5ce..7016dbe7 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -4,8 +4,8 @@ - - + + @@ -22,7 +22,7 @@
- {{ user.nickname }} + {{ user.user_name_view }} @@ -41,7 +41,7 @@ - {{ user.nickname }} + {{ user.user_name_view }} @@ -63,7 +63,7 @@ - {{ user.nickname }} + {{ user.user_name_view }} @@ -89,8 +89,14 @@ - - + + + + {{ user.user_name_view }} + + + + @@ -319,7 +325,7 @@ {{ $t('login.login.9q27d8') }} - + @@ -375,7 +381,7 @@