App.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "uview-ui/index.scss";
  4. </style>
  5. <script>
  6. import Vue from 'vue'
  7. // import app from './utils/api.js'
  8. export default {
  9. onLaunch() {
  10. // 获取未读信息
  11. // this.getAllMessage()
  12. // 微信登录
  13. wx.login({
  14. success({
  15. code
  16. }) {
  17. console.log('code', code);
  18. uni.request({
  19. url:'https://teacherapi.cocorobo.cn/api/pbl/weChatCode',
  20. // url: 'http://localhost:7333/api/pbl/weChatCode', //接口地址:前缀+方法中传入的地址
  21. method: 'GET',
  22. data: {
  23. codes: code
  24. }
  25. }).then(res => {
  26. // console.log('微信登录',res);
  27. uni.setStorageSync('oId', res.data)
  28. // uni.getStorageSync('oId')
  29. })
  30. }
  31. })
  32. // 获取设备信息
  33. uni.getSystemInfo({
  34. success: function(res) {
  35. Vue.prototype.screenHeight = res.screenHeight
  36. Vue.prototype.screenWidth = res.screenWidth
  37. // console.log(res);
  38. const tabBarHeight = res.screenHeight - res.windowHeight;
  39. Vue.prototype.tabBarHeight = tabBarHeight
  40. if (uni.getMenuButtonBoundingClientRect()) {
  41. console.log('小程序');
  42. // 小程序状态栏是指显示电量的那一小部分
  43. thisWechat(res.statusBarHeight)
  44. } else {
  45. console.log('app');
  46. thisApp(res.statusBarHeight)
  47. }
  48. }
  49. });
  50. // 微信
  51. function thisWechat(statusBarHeight) {
  52. // 获取胶囊位置
  53. let meunButtonInfo = uni.getMenuButtonBoundingClientRect()
  54. // console.log(meunButtonInfo);
  55. Vue.prototype.meunButtonInfo = meunButtonInfo.height
  56. // 计算出导航栏高度+动态栏
  57. let allHeight = meunButtonInfo.bottom + (meunButtonInfo.top - statusBarHeight) * 2;
  58. // console.log(allHeight);
  59. let navheight;
  60. Vue.prototype.navheight = allHeight
  61. // 按钮离顶
  62. let alltop = meunButtonInfo.top
  63. Vue.prototype.navTop = alltop
  64. // 动态栏高度
  65. let statusHeight
  66. Vue.prototype.statusHeight = statusBarHeight
  67. };
  68. // 这个app的
  69. function thisApp(statusBarHeight) {
  70. // console.log(uni.getSystemInfoSync());
  71. // 导航栏高度
  72. let customBarHeight;
  73. if (uni.getSystemInfoSync().platform === 'android') {
  74. customBarHeight = statusBarHeight + 50;
  75. } else if (uni.getSystemInfoSync().platform === 'ios') {
  76. // iOS 平台
  77. // 在这里根据 iOS 平台的特性计算自定义状态栏高度
  78. // ...
  79. customBarHeight = statusBarHeight + 45;
  80. } else {
  81. // 其他平台
  82. // ...
  83. customBarHeight = statusBarHeight;
  84. }
  85. // console.log(customBarHeight);
  86. Vue.prototype.customBar = customBarHeight;
  87. }
  88. },
  89. onShow() {
  90. },
  91. methods: {
  92. // 获取未读信息
  93. getAllMessage() {
  94. this.$request('/selectAllMessage', "POST", {
  95. oid: this.$store.state.user.openid
  96. }).then(res => {
  97. console.log('获取未读信息',res[0][0].msg);
  98. let num = res[0][0].msg
  99. if (num == 0) {
  100. uni.hideTabBarRedDot({
  101. index: 3
  102. })
  103. } else {
  104. Vue.prototype.msgnum = num
  105. uni.setTabBarBadge({
  106. index: 3,
  107. text: num.toString()
  108. })
  109. }
  110. })
  111. }
  112. },
  113. onLoad() {
  114. }
  115. }
  116. </script>
  117. <style>
  118. /*每个页面公共css */
  119. body,
  120. html {
  121. background-color: #f0f2f5;
  122. /* font-family: PingFang SC; */
  123. height: 100vh;
  124. width: 750rpx;
  125. }
  126. view {
  127. box-sizing: border-box;
  128. padding: 0;
  129. }
  130. /* 公共字体大小类 */
  131. .one-font {
  132. font-size: 48rpx;
  133. line-height: 72rpx;
  134. font-weight: 600;
  135. }
  136. .two-font {
  137. font-size: 40rpx;
  138. line-height: 56rpx;
  139. }
  140. .twoZ-font {
  141. font-size: 40rpx;
  142. line-height: 56rpx;
  143. font-weight: 500;
  144. }
  145. .three-font {
  146. font-size: 34rpx;
  147. line-height: 48rpx;
  148. font-weight: 500;
  149. }
  150. .num-font {
  151. font-size: 36rpx;
  152. line-height: 56rpx;
  153. font-weight: 700;
  154. }
  155. .bmTit-font {
  156. font-size: 36rpx;
  157. line-height: 44rpx;
  158. font-weight: 500;
  159. }
  160. .fNum-font {
  161. font-size: 44rpx;
  162. line-height: 56rpx;
  163. font-weight: 700;
  164. }
  165. .zw-font {
  166. font-size: 34rpx;
  167. line-height: 48rpx;
  168. }
  169. .btn-font {
  170. font-size: 28rpx;
  171. line-height: 40rpx;
  172. font-weight: 600;
  173. }
  174. .fwb-font {
  175. font-size: 28rpx;
  176. line-height: 40rpx;
  177. font-size: 400;
  178. }
  179. .sZw-font {
  180. font-size: 26rpx;
  181. line-height: 42rpx;
  182. font-size: 400;
  183. }
  184. .sBtn-font {
  185. font-size: 24rpx;
  186. line-height: 32rpx;
  187. font-weight: 600;
  188. }
  189. .fz-font {
  190. font-size: 24rpx;
  191. line-height: 32rpx;
  192. font-weight: 400;
  193. }
  194. .bq-font {
  195. font-size: 20rpx;
  196. line-height: 24rpx;
  197. }
  198. .bqZ-font {
  199. font-size: 20rpx;
  200. line-height: 24rpx;
  201. font-weight: 600;
  202. }
  203. </style>