App.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script>
  2. /**
  3. * vuex管理登陆状态,具体可以参考官方登陆模板示例
  4. */
  5. import { mapMutations } from 'vuex';
  6. import { getFileIndex,getFile,writerTxt,getFileText} from './utils/fileController.js';
  7. // #ifdef H5
  8. import { weixindata, setRouter } from './utils/wxAuthorized';
  9. // #endif
  10. // #ifdef APP-PLUS
  11. import { getUpApp } from './utils/upApp.js';
  12. // #endif
  13. export default {
  14. data() {
  15. return {
  16. /* 保存微信信息 */
  17. appData: {}
  18. };
  19. },
  20. methods: {
  21. ...mapMutations('user', ['setUserInfo', 'login', 'hasLogin'])
  22. },
  23. onLaunch: async function(urlObj) {
  24. let obj = this;
  25. // let mulv =
  26. getFileIndex().then(indexObj =>{
  27. getFileText(indexObj,'userInfo.txt').then((e) => {
  28. if(e.target.result){
  29. console.log(JSON.parse(e.target.result),'wenjianduixiang ');
  30. obj.setUserInfo(e.target.result);
  31. }
  32. })
  33. }).catch((e) => {
  34. console.log(e,'344156');
  35. });
  36. // 加载缓存中的用户信息
  37. let userInfo = uni.getStorageSync('userInfo') || '';
  38. // 判断是否拥有用户信息
  39. if (userInfo.uid) {
  40. //更新登陆状态
  41. uni.getStorage({
  42. key: 'userInfo',
  43. success: res => {
  44. obj.setUserInfo(res.data);
  45. obj.login(res.data);
  46. }
  47. });
  48. }
  49. // #ifdef H5
  50. // 保存路由对象
  51. setRouter(this.$router);
  52. //判断是否已经缓存浏览器
  53. let bool = uni.getStorageSync('weichatBrowser') || '';
  54. if (bool === '') {
  55. //判断是否为微信浏览
  56. bool = navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger';
  57. // 保存当前是否为微信内核浏览器
  58. uni.setStorageSync('weichatBrowser', bool);
  59. }
  60. if (bool) {
  61. // 加载微信信息
  62. weixindata();
  63. }
  64. // #endif
  65. // #ifdef APP-PLUS
  66. // 判断是否升级
  67. getUpApp();
  68. // 获取当前运行系统
  69. let system = uni.getStorageSync('platform') || '';
  70. if (!system) {
  71. uni.setStorage({
  72. key: 'platform',
  73. data: uni.getSystemInfoSync().platform
  74. });
  75. }
  76. // #endif
  77. },
  78. onShow: function() {
  79. // 加载拦截
  80. // console.log('App Show');
  81. },
  82. onHide: function() {
  83. // console.log('App Hide');
  84. }
  85. };
  86. </script>
  87. <style lang="scss">
  88. @import 'uview-ui/index.scss';
  89. /*全局公共样式和字体图标*/
  90. @import '/static/css/cmy.css';
  91. uni-page-body{
  92. min-height: 100%;
  93. height: auto;
  94. }
  95. view,
  96. scroll-view,
  97. swiper,
  98. swiper-item,
  99. cover-view,
  100. cover-image,
  101. icon,
  102. text,
  103. rich-text,
  104. progress,
  105. button,
  106. checkbox,
  107. form,
  108. input,
  109. label,
  110. radio,
  111. slider,
  112. switch,
  113. textarea,
  114. navigator,
  115. audio,
  116. camera,
  117. image,
  118. video {
  119. box-sizing: border-box;
  120. }
  121. // 边距样式
  122. @for $i from 1 to 4 {
  123. .margin-l-#{$i * 10} {
  124. margin-left: $i * 10rpx !important;
  125. }
  126. .margin-r-#{$i * 10} {
  127. margin-right: $i * 10rpx !important;
  128. }
  129. .margin-t-#{$i * 10} {
  130. margin-top: $i * 10rpx !important;
  131. }
  132. .margin-b-#{$i * 10} {
  133. margin-bottom: $i * 10rpx !important;
  134. }
  135. .margin-#{$i * 10} {
  136. margin: $i * 10rpx !important;
  137. }
  138. .margin-v-#{$i * 10} {
  139. margin-top: $i * 10rpx !important;
  140. margin-bottom: $i * 10rpx !important;
  141. }
  142. .margin-c-#{$i * 10} {
  143. margin-left: $i * 10rpx !important;
  144. margin-right: $i * 10rpx !important;
  145. }
  146. .padding-l-#{$i * 10} {
  147. padding-left: $i * 10rpx !important;
  148. }
  149. .padding-r-#{$i * 10} {
  150. padding-right: $i * 10rpx !important;
  151. }
  152. .padding-t-#{$i * 10} {
  153. padding-top: $i * 10rpx !important;
  154. }
  155. .padding-b-#{$i * 10} {
  156. padding-bottom: $i * 10rpx !important;
  157. }
  158. .padding-#{$i * 10} {
  159. padding: $i * 10rpx !important;
  160. }
  161. .padding-v-#{$i * 10} {
  162. padding-top: $i * 10rpx !important;
  163. padding-bottom: $i * 10rpx !important;
  164. }
  165. .padding-c-#{$i * 10} {
  166. padding-left: $i * 10rpx !important;
  167. padding-right: $i * 10rpx !important;
  168. }
  169. }
  170. // 字体大小
  171. .font-size-sm {
  172. font-size: $font-sm;
  173. }
  174. .font-size-base {
  175. font-size: $font-base;
  176. }
  177. .font-size-lg {
  178. font-size: $font-lg;
  179. }
  180. // 字体颜色
  181. .font-color-yellow {
  182. color: $color-yellow;
  183. }
  184. .font-color-gray {
  185. color: $color-gray;
  186. }
  187. .font-color-red {
  188. color: $color-red;
  189. }
  190. // 边框颜色
  191. .border-color-yellow {
  192. border: 1rpx solid $color-yellow;
  193. }
  194. // 修改默认背景颜色
  195. uni-page-wrapper {
  196. background-color: $page-color-base;
  197. }
  198. page {
  199. background-color: $page-color-base;
  200. // 设置默认字体
  201. font-family: PingFang SC, STHeitiSC-Light, Helvetica-Light, arial, sans-serif, Droid Sans Fallback;
  202. }
  203. </style>