App.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <script>
  2. var user = require('./utils/user.js');
  3. const util = require('./utils/util.js');
  4. const api = require('./config/api.js');
  5. var app = getApp();
  6. export default {
  7. data() {
  8. return {};
  9. },
  10. onLaunch: function() {
  11. const updateManager = uni.getUpdateManager();
  12. uni.getUpdateManager().onUpdateReady(function() {
  13. updateManager.applyUpdate();
  14. // wx.showModal({
  15. // title: '更新提示',
  16. // content: '新版本已经准备好,是否重启应用?',
  17. // success: function (res) {
  18. // if (res.confirm) {
  19. // updateManager.applyUpdate();
  20. // }
  21. // }
  22. // });
  23. });
  24. /*网络状态
  25. wx.onNetworkStatusChange(function (res) {
  26. if (res.networkType === 'none') {
  27. wx.showToast({
  28. title: '网络已断开',
  29. icon: 'none'
  30. })
  31. } else if (res.networkType === "2g" || res.networkType === "3g")
  32. wx.showToast({
  33. title: '您的网络状态不佳,' + res.networkType + ',建议使用wifi',
  34. icon: 'none'
  35. });
  36. })*/
  37. // util.request(api.appTheme, {
  38. // }).then(res=> {
  39. // if (res.errno === 0) {
  40. // }
  41. // });
  42. //项目启动获取缓存中的皮肤
  43. const value = uni.getStorageSync('theme');
  44. console.log(value);
  45. if (value == 'jz') {
  46. this.$store.dispatch('handleActionAgree', 'jz');
  47. } else if (value == 'yj') {
  48. this.$store.dispatch('handleActionAgree', 'yj');
  49. } else {
  50. }
  51. const appInstance = getApp();
  52. console.log(appInstance);
  53. this.getUserOpenId();
  54. if (uni.getStorageSync('randomAandB') == null || uni.getStorageSync('randomAandB') == "") {
  55. //1是A,0是B
  56. let randomVar = Math.random() < 0.5 ? 0 : 1;
  57. // 假设这是你要存储的数据
  58. const timestamp = Date.now(); // 获取当前时间戳
  59. // 将数据和时间戳一起存储
  60. uni.setStorage({
  61. key: 'randomAandB',
  62. data: {
  63. randomAandB: randomVar,
  64. timestamp: timestamp
  65. },
  66. success: function() {
  67. console.log('数据和时间戳存储成功');
  68. }
  69. });
  70. } else {
  71. function isDataExpired(timestamp, expiryDuration) {
  72. const now = Date.now();
  73. return (now - timestamp) > expiryDuration;
  74. }
  75. let flag = false
  76. const expiryDuration = 3600000; // 一小时的毫秒数
  77. let s = uni.getStorageSync("randomAandB");
  78. flag = s && isDataExpired(s.timestamp, expiryDuration);
  79. if (flag) {
  80. let randomVar = Math.random() < 0.5 ? 0 : 1;
  81. // 假设这是你要存储的数据
  82. const timestamp = Date.now(); // 获取当前时间戳
  83. // 将数据和时间戳一起存储
  84. uni.setStorage({
  85. key: 'randomAandB',
  86. data: {
  87. randomAandB:randomVar ,
  88. timestamp: timestamp
  89. },
  90. success: function() {
  91. console.log('数据和时间戳再次存储成功');
  92. }
  93. });
  94. }
  95. }
  96. },
  97. onLoad() {
  98. var updateManager = uni.getUpdateManager();
  99. updateManager.onUpdateReady((res) => {
  100. uni.showModal({
  101. title: '更新提示',
  102. content: '新版本已经准备好,是否重启小程序?',
  103. success: (res) => {
  104. if (res.confirm) {
  105. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  106. updateManager.applyUpdate();
  107. }
  108. }
  109. });
  110. });
  111. updateManager.onUpdateFailed((err) => {
  112. // 新的版本下载失败
  113. console.log('版本下载失败原因', err);
  114. uni.showToast({
  115. title: '新版本下载失败,请稍后再试',
  116. icon: 'none'
  117. });
  118. });
  119. },
  120. methods: {
  121. async getUserOpenId() {
  122. let that = this;
  123. let res = await user.userOpenId();
  124. console.log(res);
  125. let openId = res.data;
  126. getApp().globalData.openId = res.data;
  127. let uuid = uni.getStorageSync('uuid');
  128. if (openId == '' || openId == null || openId == undefined) {
  129. // 生成uuid
  130. if (!uuid) {
  131. uuid = util.creadUuid();
  132. uni.setStorageSync('uuid', uuid);
  133. }
  134. }
  135. getApp().globalData.uuid = uuid;
  136. // uni.setStorageSync('openId', res.data);
  137. },
  138. },
  139. onShow: function(options) {
  140. /*是否授权登录*/
  141. user.checkLogin()
  142. .then((res) => {
  143. this.globalData.hasLogin = true;
  144. if (this.globalData.checkLoginReadyCallback) {
  145. this.globalData.checkLoginReadyCallback();
  146. }
  147. })
  148. .catch(() => {
  149. this.globalData.hasLogin = false;
  150. });
  151. //购物车数据显示
  152. //user.cartcount();
  153. },
  154. globalData: {
  155. uuid: '',
  156. openId: '',
  157. hasLogin: false,
  158. //是否授权登录
  159. isMember: false,
  160. //是否是会员
  161. userInfo: {},
  162. r_userid: 0,
  163. //推荐人id
  164. iscert: false,
  165. //是否注册过
  166. mapKey: 'AEZBZ-7JYL6-N4WSL-EFMOK-SAHSO-GLFA4',
  167. currentLocationName: '位置获取中',
  168. city: '',
  169. rId: '',
  170. //引荐人ID
  171. shareImage: '',
  172. recommend: {
  173. //引荐人信息
  174. userName: '',
  175. avatarUrl: '',
  176. bCode: '',
  177. phone: '',
  178. unionId: '',
  179. openId: '',
  180. sessionKey: ''
  181. },
  182. infoGoods: {
  183. picUrl: '',
  184. name: '',
  185. brief: '',
  186. type: '0',
  187. id: ''
  188. },
  189. //信息收集,
  190. infoAddress: {
  191. addressId: '',
  192. addressDetail: ''
  193. },
  194. memberUserInfo: {
  195. nickName: '',
  196. avatarUrl: '/static/images/new/icon-user.png'
  197. },
  198. checkLoginReadyCallback: function() {
  199. //是否登录
  200. this.hasLogin = true;
  201. }
  202. }
  203. };
  204. //购物车隐藏
  205. // {
  206. // "pagePath": "pages/tabBar/cart/cart",
  207. // "iconPath": "static/images/cart.png",
  208. // "selectedIconPath": "static/images/cart@selected.png",
  209. // "text": "购物车"
  210. // },
  211. </script>
  212. <style>
  213. /**app.ttss**/
  214. .container {
  215. box-sizing: border-box;
  216. background-color: #f5f5f5;
  217. font-family: AlibabaPuHuiTi_2_55_Regular;
  218. }
  219. view,
  220. image,
  221. text,
  222. navigator {
  223. box-sizing: border-box;
  224. padding: 0;
  225. margin: 0;
  226. }
  227. page {
  228. color: #2a2a2a;
  229. /*主要颜色*/
  230. font-size: 28rpx;
  231. background: #f5f5f5;
  232. }
  233. text,
  234. view {
  235. font-family: AlibabaPuHuiTi_2_55_Regular;
  236. font-weight: 400;
  237. }
  238. .sub-color {
  239. color: #85868a;
  240. }
  241. .jz-color {
  242. color: #09afff;
  243. /*鲸致色号00AFFF*/
  244. }
  245. .van-tab>view.van-ellipsis {
  246. color: #888;
  247. }
  248. .van-tab--active.van-tab>view.van-ellipsis {
  249. color: #09afff;
  250. }
  251. van-dialog .van-button {
  252. color: #09afff !important;
  253. }
  254. .van-dialog__message-text {
  255. color: #666;
  256. }
  257. .van-button--info {
  258. background: #09afff !important;
  259. border: none !important;
  260. }
  261. .bottom-fixed-btn-wrapper {
  262. position: fixed;
  263. bottom: 146rpx;
  264. left: 0;
  265. right: 28rpx;
  266. left: 28rpx;
  267. }
  268. .bottom-fixed-btn-wrapper .van-button {
  269. height: 74rpx;
  270. border: none;
  271. }
  272. .common-btn-wrapper {
  273. margin: 0 28rpx 0;
  274. }
  275. .common-btn-wrapper .van-button {
  276. height: 74rpx;
  277. margin: 0 0 48rpx 0;
  278. }
  279. /* 云嘉样式 */
  280. /* .yj.container .new-item-right{
  281. background: #f18342;
  282. }
  283. .yj.container .add-address{
  284. background: #f18342;
  285. } */
  286. </style>