App.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 msgPop from './components/msgPop/msgPop.vue'
  8. // import app from './utils/api.js'
  9. export default {
  10. onLaunch() {
  11. // 获取未读信息
  12. // this.getAllMessage()
  13. // 微信登录
  14. wx.login({
  15. success({
  16. code
  17. }) {
  18. // console.log('code', code);
  19. uni.request({
  20. url:'https://teacherapi.cocorobo.cn/api/pbl/weChatCode',
  21. // url: 'http://localhost:7333/api/pbl/weChatCode', //接口地址:前缀+方法中传入的地址
  22. method: 'GET',
  23. data: {
  24. codes: code
  25. }
  26. }).then(res => {
  27. // console.log('微信登录',res);
  28. uni.setStorageSync('oId', res.data)
  29. // uni.getStorageSync('oId')
  30. })
  31. }
  32. })
  33. // 获取设备信息
  34. uni.getSystemInfo({
  35. success: function(res) {
  36. Vue.prototype.screenHeight = res.screenHeight
  37. Vue.prototype.screenWidth = res.screenWidth
  38. // console.log(res);
  39. const tabBarHeight = res.screenHeight - res.windowHeight;
  40. Vue.prototype.tabBarHeight = tabBarHeight
  41. if (uni.getMenuButtonBoundingClientRect()) {
  42. console.log('小程序');
  43. // 小程序状态栏是指显示电量的那一小部分
  44. thisWechat(res.statusBarHeight)
  45. } else {
  46. console.log('app');
  47. thisApp(res.statusBarHeight)
  48. }
  49. }
  50. });
  51. // 微信
  52. function thisWechat(statusBarHeight) {
  53. // 获取胶囊位置
  54. let meunButtonInfo = uni.getMenuButtonBoundingClientRect()
  55. // console.log(meunButtonInfo);
  56. Vue.prototype.meunButtonInfo = meunButtonInfo.height
  57. // 计算出导航栏高度+动态栏
  58. let allHeight = meunButtonInfo.bottom + (meunButtonInfo.top - statusBarHeight) * 2;
  59. // console.log(allHeight);
  60. let navheight;
  61. Vue.prototype.navheight = allHeight
  62. // 按钮离顶
  63. let alltop = meunButtonInfo.top
  64. Vue.prototype.navTop = alltop
  65. // 动态栏高度
  66. let statusHeight
  67. Vue.prototype.statusHeight = statusBarHeight
  68. };
  69. // 这个app的
  70. function thisApp(statusBarHeight) {
  71. // console.log(uni.getSystemInfoSync());
  72. // 导航栏高度
  73. let customBarHeight;
  74. if (uni.getSystemInfoSync().platform === 'android') {
  75. customBarHeight = statusBarHeight + 50;
  76. } else if (uni.getSystemInfoSync().platform === 'ios') {
  77. // iOS 平台
  78. // 在这里根据 iOS 平台的特性计算自定义状态栏高度
  79. // ...
  80. customBarHeight = statusBarHeight + 45;
  81. } else {
  82. // 其他平台
  83. // ...
  84. customBarHeight = statusBarHeight;
  85. }
  86. // console.log(customBarHeight);
  87. Vue.prototype.customBar = customBarHeight;
  88. }
  89. },
  90. onShow() {
  91. },
  92. onLoad() {
  93. // this.animation = uni.createAnimation()
  94. },
  95. methods: {
  96. // 获取未读信息
  97. getAllMessage() {
  98. this.$request('/selectAllMessage', "POST", {
  99. oid: this.$store.state.user.openid
  100. }).then(res => {
  101. console.log('获取未读信息',res[0][0]);
  102. let num = res[0][0].msg
  103. if (num == 0) {
  104. uni.hideTabBarRedDot({
  105. index: 4
  106. })
  107. } else {
  108. Vue.prototype.msgnum = num
  109. uni.setTabBarBadge({
  110. index: 4,
  111. text: num.toString()
  112. })
  113. }
  114. })
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. /*每个页面公共css */
  121. body,
  122. html {
  123. background-color: #f0f2f5;
  124. /* font-family: PingFang SC; */
  125. height: 100vh;
  126. width: 750rpx;
  127. }
  128. view {
  129. box-sizing: border-box;
  130. padding: 0;
  131. }
  132. /* 确认弹窗 */
  133. .mask { //弹窗背景色
  134. position: fixed;
  135. top: 0;
  136. left: 0;
  137. width: 100%;
  138. height: 100%;
  139. background-color: rgba(0, 0, 0, 0.3);
  140. z-index: 999;
  141. overflow: hidden;
  142. // display: none;
  143. }
  144. .popup-container {
  145. position: fixed;
  146. top: 50%;
  147. left: 50%;
  148. transform: translate(-50%, -50%);
  149. width: 520rpx;
  150. height: 260rpx;
  151. z-index: 1000;
  152. border-radius: 16rpx;
  153. overflow: hidden;
  154. .popup {
  155. width: 100%;
  156. height: 100%;
  157. display: flex;
  158. flex-direction: column;
  159. background-color: #fff;
  160. border-radius: 16rpx;
  161. overflow: hidden;
  162. .header {
  163. flex: 1;
  164. display: flex;
  165. justify-content: center;
  166. align-items: center;
  167. flex-direction: column;
  168. margin-top: 24px;
  169. font-size: 34rpx;
  170. font-weight: 600;
  171. image {
  172. width: 150rpx;
  173. height: 150rpx;
  174. margin-top: 15px;
  175. margin-bottom: 15px;
  176. }
  177. }
  178. .footer {
  179. width: 100%;
  180. display: flex;
  181. overflow: hidden;
  182. .cancel-btn {
  183. width: 50%;
  184. height: 100rpx;
  185. background-color: #F7F7F7;
  186. color: #000;
  187. font-size: 34rpx;
  188. text-align: center;
  189. border-bottom-left-radius: 16rpx;
  190. line-height: 50px;
  191. }
  192. .confirm-btn {
  193. width: 50%;
  194. height: 100rpx;
  195. background-color: #0081FE;
  196. color: #fff;
  197. font-size: 34rpx;
  198. text-align: center;
  199. line-height: 50px;
  200. }
  201. }
  202. }
  203. }
  204. /* 触底加载更多 */
  205. .loading {
  206. height: 30rpx;
  207. text-align: center;
  208. padding-top: 20rpx;
  209. padding-bottom: 100rpx;
  210. font-size: 26rpx;
  211. color: #888;
  212. line-height: 2em;
  213. }
  214. /* 公共字体大小类 */
  215. .one-font {
  216. font-size: 48rpx;
  217. line-height: 72rpx;
  218. font-weight: 600;
  219. }
  220. .two-font {
  221. font-size: 40rpx;
  222. line-height: 56rpx;
  223. }
  224. .twoZ-font {
  225. font-size: 40rpx;
  226. line-height: 56rpx;
  227. font-weight: 500;
  228. }
  229. .three-font {
  230. font-size: 34rpx;
  231. line-height: 48rpx;
  232. font-weight: 500;
  233. }
  234. .num-font {
  235. font-size: 36rpx;
  236. line-height: 56rpx;
  237. font-weight: 700;
  238. }
  239. .bmTit-font {
  240. font-size: 36rpx;
  241. line-height: 44rpx;
  242. font-weight: 500;
  243. }
  244. .fNum-font {
  245. font-size: 44rpx;
  246. line-height: 56rpx;
  247. font-weight: 700;
  248. }
  249. .zw-font {
  250. font-size: 34rpx;
  251. line-height: 48rpx;
  252. }
  253. .btn-font {
  254. font-size: 28rpx;
  255. line-height: 40rpx;
  256. font-weight: 600;
  257. }
  258. .fwb-font {
  259. font-size: 28rpx;
  260. line-height: 40rpx;
  261. font-size: 400;
  262. }
  263. .sZw-font {
  264. font-size: 26rpx;
  265. line-height: 42rpx;
  266. font-size: 400;
  267. }
  268. .sBtn-font {
  269. font-size: 24rpx;
  270. line-height: 32rpx;
  271. font-weight: 600;
  272. }
  273. .fz-font {
  274. font-size: 24rpx;
  275. line-height: 32rpx;
  276. font-weight: 400;
  277. }
  278. .bq-font {
  279. font-size: 20rpx;
  280. line-height: 24rpx;
  281. }
  282. .bqZ-font {
  283. font-size: 20rpx;
  284. line-height: 24rpx;
  285. font-weight: 600;
  286. }
  287. </style>