App.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <script>
  2. /**
  3. * vuex管理登陆状态,具体可以参考官方登陆模板示例
  4. */
  5. import { mapMutations,mapState } from 'vuex';
  6. import interceptor from './interceptor';
  7. // #ifdef H5
  8. import { weixindata } from './utils/wxAuthorized';
  9. // #endif
  10. import { version } from './api/user.js';
  11. export default {
  12. data() {
  13. return {
  14. /* 保存微信信息 */
  15. appData: {},
  16. weixinObj: '', //保存微信对象
  17. url: '',
  18. versionFu: ''
  19. };
  20. },
  21. computed: {
  22. ...mapState(['baseURL'])
  23. },
  24. methods: {
  25. ...mapMutations('user', ['setUserInfo', 'login', 'hasLogin']),
  26. banben() {
  27. const obj = this;
  28. version({}).then(e => {
  29. console.log(e);
  30. try {
  31. obj.url =obj.baseURL + e.data.apk;
  32. obj.versionFu = e.data.version_code;
  33. console.log(obj.versionFu);
  34. let ver = plus.runtime.versionCode;
  35. uni.showModal({
  36. title: ver
  37. });
  38. if (+ver > +this.versionFu) {
  39. uni.showModal({
  40. title: '友情提示',
  41. content: '当前版本较低请升级小程序',
  42. success: res => {
  43. if (res.confirm) {
  44. try{
  45. plus.runtime.openURL(obj.url,function (e) {
  46. console.log(e)
  47. });
  48. console.log('用户点击确定');
  49. }catch(e){
  50. console.log(e)
  51. }
  52. } else if (res.cancel) {
  53. console.log('用户点击取消');
  54. }
  55. }
  56. });
  57. } else {
  58. uni.showModal({
  59. title: '友情提示',
  60. content: '当前版本new'
  61. });
  62. }
  63. } catch (e) {
  64. console.log(e);
  65. }
  66. });
  67. }
  68. },
  69. onLaunch: function(urlObj) {
  70. let obj = this;
  71. //判断当前版本是否需要更新
  72. obj.banben();
  73. // 加载缓存中的用户信息
  74. let userInfo = uni.getStorageSync('userInfo') || '';
  75. // 判断是否拥有用户信息
  76. if (userInfo.uid) {
  77. //更新登陆状态
  78. uni.getStorage({
  79. key: 'userInfo',
  80. success: res => {
  81. obj.setUserInfo(res.data);
  82. obj.login(res.data);
  83. }
  84. });
  85. }
  86. },
  87. onShow: function() {},
  88. onHide: function() {}
  89. };
  90. </script>
  91. <style lang="scss">
  92. /*全局公共样式和字体图标*/
  93. @import '/static/css/public.css';
  94. view,
  95. scroll-view,
  96. swiper,
  97. swiper-item,
  98. cover-view,
  99. cover-image,
  100. icon,
  101. text,
  102. rich-text,
  103. progress,
  104. button,
  105. checkbox,
  106. form,
  107. input,
  108. label,
  109. radio,
  110. slider,
  111. switch,
  112. textarea,
  113. navigator,
  114. audio,
  115. camera,
  116. image,
  117. video {
  118. box-sizing: border-box;
  119. }
  120. /* 骨架屏替代方案 */
  121. .Skeleton {
  122. background: #f3f3f3;
  123. padding: 20rpx 0;
  124. border-radius: 8rpx;
  125. }
  126. /* 图片载入替代方案 */
  127. .image-wrapper {
  128. font-size: 0;
  129. background: #f3f3f3;
  130. border-radius: 4px;
  131. image {
  132. width: 100%;
  133. height: 100%;
  134. transition: 0.6s;
  135. opacity: 0;
  136. &.loaded {
  137. opacity: 1;
  138. }
  139. }
  140. }
  141. // 设置富文本中图片最大宽度
  142. uni-rich-text img {
  143. max-width: 100% !important;
  144. }
  145. /*边框*/
  146. .b-b:after,
  147. .b-t:after {
  148. position: absolute;
  149. z-index: 3;
  150. left: 0;
  151. right: 0;
  152. height: 0;
  153. content: '';
  154. transform: scaleY(0.5);
  155. border-bottom: 1px solid $border-color-base;
  156. }
  157. .b-b:after {
  158. bottom: 0;
  159. }
  160. .b-t:after {
  161. top: 0;
  162. }
  163. /* button样式改写 */
  164. uni-button,
  165. button {
  166. height: 80rpx;
  167. line-height: 80rpx;
  168. font-size: $font-lg + 2rpx;
  169. font-weight: normal;
  170. &.no-border:before,
  171. &.no-border:after {
  172. border: 0;
  173. }
  174. }
  175. uni-button[type='default'],
  176. button[type='default'] {
  177. color: $font-color-dark;
  178. }
  179. /* input 样式 */
  180. .input-placeholder {
  181. color: #999999;
  182. }
  183. .placeholder {
  184. color: #999999;
  185. }
  186. // 边距样式
  187. @for $i from 1 to 4 {
  188. .margin-l-#{$i * 10} {
  189. margin-left: $i * 10rpx !important;
  190. }
  191. .margin-r-#{$i * 10} {
  192. margin-right: $i * 10rpx !important;
  193. }
  194. .margin-t-#{$i * 10} {
  195. margin-top: $i * 10rpx !important;
  196. }
  197. .margin-b-#{$i * 10} {
  198. margin-bottom: $i * 10rpx !important;
  199. }
  200. .margin-#{$i * 10} {
  201. margin: $i * 10rpx !important;
  202. }
  203. .margin-v-#{$i * 10} {
  204. margin-top: $i * 10rpx !important;
  205. margin-bottom: $i * 10rpx !important;
  206. }
  207. .margin-c-#{$i * 10} {
  208. margin-left: $i * 10rpx !important;
  209. margin-right: $i * 10rpx !important;
  210. }
  211. .padding-l-#{$i * 10} {
  212. padding-left: $i * 10rpx !important;
  213. }
  214. .padding-r-#{$i * 10} {
  215. padding-right: $i * 10rpx !important;
  216. }
  217. .padding-t-#{$i * 10} {
  218. padding-top: $i * 10rpx !important;
  219. }
  220. .padding-b-#{$i * 10} {
  221. padding-bottom: $i * 10rpx !important;
  222. }
  223. .padding-#{$i * 10} {
  224. padding: $i * 10rpx !important;
  225. }
  226. .padding-v-#{$i * 10} {
  227. padding-top: $i * 10rpx !important;
  228. padding-bottom: $i * 10rpx !important;
  229. }
  230. .padding-c-#{$i * 10} {
  231. padding-left: $i * 10rpx !important;
  232. padding-right: $i * 10rpx !important;
  233. }
  234. }
  235. // 字体大小
  236. .font-size-sm {
  237. font-size: $font-sm;
  238. }
  239. .font-size-base {
  240. font-size: $font-base;
  241. }
  242. .font-size-lg {
  243. font-size: $font-lg;
  244. }
  245. // 字体颜色
  246. .font-color-yellow {
  247. color: $color-yellow;
  248. }
  249. .font-color-gray {
  250. color: $color-gray;
  251. }
  252. .font-color-red {
  253. color: $color-red;
  254. }
  255. // 边框颜色
  256. .border-color-yellow {
  257. border: 1rpx solid $color-yellow;
  258. }
  259. // 修改默认背景颜色
  260. uni-page-wrapper {
  261. background-color: #ffffff;
  262. }
  263. page {
  264. background-color: #ffffff;
  265. // 设置默认字体
  266. font-family: PingFang SC, STHeitiSC-Light, Helvetica-Light, arial, sans-serif, Droid Sans Fallback;
  267. }
  268. </style>