App.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <script>
  2. import Vue from 'vue'
  3. // import TIM from 'tim-wx-sdk';
  4. // import COS from 'cos-wx-sdk-v5';
  5. export default {
  6. onLoad: function (){
  7. },
  8. onLaunch: function() {
  9. this.checkUpdate();
  10. // 看课题目字体跟随系统变化
  11. const systemInfo = uni.getSystemInfoSync();
  12. const baseFontSize = 14; // 标准字体大小(你可以自定义)
  13. const userFontSize = systemInfo.fontSizeSetting || baseFontSize;
  14. // 计算比例
  15. const scale = userFontSize / baseFontSize;
  16. // 存储到全局变量或 Vuex
  17. uni.setStorageSync('fontScale', scale);
  18. },
  19. onShow: function () {
  20. console.log('App Show')
  21. uni.getSystemInfo({
  22. success: (result) => {
  23. // 获取手机系统的状态栏高度(不同手机的状态栏高度不同)
  24. // console.log('当前手机的状态栏高度',result.statusBarHeight)
  25. let statusBarHeight = result.statusBarHeight + 'px'
  26. // 获取右侧胶囊的信息 单位px
  27. //#ifndef H5 || APP-PLUS
  28. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  29. //bottom: 胶囊底部距离屏幕顶部的距离
  30. //height: 胶囊高度
  31. //left: 胶囊左侧距离屏幕左侧的距离
  32. //right: 胶囊右侧距离屏幕左侧的距离
  33. //top: 胶囊顶部距离屏幕顶部的距离
  34. //width: 胶囊宽度
  35. // console.log(menuButtonInfo.width, menuButtonInfo.height, menuButtonInfo.top)
  36. // console.log('计算胶囊右侧距离屏幕右边距离', result.screenWidth - menuButtonInfo.right)
  37. let menuWidth = menuButtonInfo.width + 'px'
  38. let menuHeight = menuButtonInfo.height + 'px'
  39. let menuBorderRadius = menuButtonInfo.height / 2 + 'px'
  40. let menuRight = result.screenWidth - menuButtonInfo.right + 'px'
  41. let menuTop = menuButtonInfo.top + 'px'
  42. let contentTop = result.statusBarHeight + 44 + 'px'
  43. let menuInfo = {
  44. statusBarHeight: statusBarHeight,//状态栏高度----用来给自定义导航条页面的顶部导航条设计padding-top使用:目的留出系统的状态栏区域
  45. menuWidth: menuWidth,//右侧的胶囊宽度--用来给自定义导航条页面的左侧胶囊设置使用
  46. menuHeight: menuHeight,//右侧的胶囊高度--用来给自定义导航条页面的左侧胶囊设置使用
  47. menuBorderRadius: menuBorderRadius,//一半的圆角--用来给自定义导航条页面的左侧胶囊设置使用
  48. menuRight: menuRight,//右侧的胶囊距离右侧屏幕距离--用来给自定义导航条页面的左侧胶囊设置使用
  49. menuTop: menuTop,//右侧的胶囊顶部距离屏幕顶部的距离--用来给自定义导航条页面的左侧胶囊设置使用
  50. contentTop: contentTop,//内容区距离页面最上方的高度--用来给自定义导航条页面的内容区定位距离使用
  51. }
  52. uni.setStorageSync('menuInfo', menuInfo)
  53. //#endif
  54. },
  55. fail: (error) => {
  56. console.log(error)
  57. }
  58. })
  59. },
  60. onHide: function() {
  61. console.log('App Hide')
  62. },
  63. methods: {
  64. checkUpdate() {
  65. const updateManager = uni.getUpdateManager();
  66. updateManager.onCheckForUpdate(function(res) {
  67. // 请求完新版本信息的回调
  68. console.log('是否有新版本:', res.hasUpdate);
  69. });
  70. updateManager.onUpdateReady(function() {
  71. uni.showModal({
  72. title: '更新提示',
  73. content: '新版本已经准备好,是否重启小程序?',
  74. confirmText: '立即重启',
  75. confirmColor: '#2179f5',
  76. showCancel: false,
  77. success(res) {
  78. if (res.confirm) {
  79. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  80. updateManager.applyUpdate();
  81. }
  82. }
  83. });
  84. });
  85. updateManager.onUpdateFailed(function() {
  86. // 新的版本下载失败
  87. uni.showModal({
  88. title: '更新提示',
  89. content: '新版本下载失败,请检查网络后重试。',
  90. showCancel: false
  91. });
  92. });
  93. },
  94. // TODO:
  95. resetLoginData() {
  96. // this.globalData.expiresIn = '';
  97. // this.globalData.sessionID = '';
  98. // this.globalData.userInfo = {
  99. // userID: '',
  100. // userSig: '',
  101. // token: '',
  102. // phone: ''
  103. // };
  104. // this.globalData.userProfile = null;
  105. // logger.log(`| app | resetLoginData | globalData: ${this.globalData}`);
  106. },
  107. onTIMError() {},
  108. onSDKReady({name}) {
  109. console.log("im注册:"+name)
  110. const isSDKReady = name === uni.$TUIKitEvent.SDK_READY ? true : false
  111. console.log("im注册:"+isSDKReady)
  112. uni.$emit('isSDKReady', {
  113. isSDKReady: true
  114. });
  115. },
  116. onNetStateChange() {},
  117. onSDKReload() {},
  118. onSdkNotReady() {},
  119. onKickedOut() {
  120. uni.showToast({
  121. title: '您被踢下线',
  122. icon: 'error'
  123. });
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="less">
  129. @import './assets/css/common.less';
  130. </style>
  131. <style lang="scss">
  132. /*每个页面公共css */
  133. @import "uview-ui/index.scss";
  134. @import './assets/iconfont/iconfont.css';
  135. @import '@/assets/css/common.scss';
  136. @import './assets/css/theme.scss';
  137. page{
  138. background-color: #f6f6f6;
  139. }
  140. ::-webkit-scrollbar{
  141. width: 0 !important;
  142. height: 0 !important;
  143. }
  144. view{
  145. box-sizing: border-box;
  146. }
  147. .ellipsis{
  148. overflow: hidden;
  149. text-overflow: ellipsis;
  150. white-space: nowrap;
  151. }
  152. .single-line-ellipsis {
  153. width: 480rpx; /* 设置固定宽度 */
  154. white-space: nowrap; /* 文本不换行 */
  155. overflow: hidden; /* 隐藏超出部分 */
  156. text-overflow: ellipsis; /* 超出部分用省略号表示 */
  157. }
  158. .single-ellipsis {
  159. width: 260rpx; /* 设置固定宽度 */
  160. white-space: nowrap; /* 文本不换行 */
  161. overflow: hidden; /* 隐藏超出部分 */
  162. text-overflow: ellipsis; /* 超出部分用省略号表示 */
  163. }
  164. .ellipsis2{
  165. overflow:hidden;
  166. text-overflow:ellipsis;
  167. display:-webkit-box;
  168. -webkit-box-orient:vertical;
  169. -webkit-line-clamp:2;
  170. }
  171. .no-data-box{
  172. height:100%;
  173. width: 100%;
  174. display: flex;
  175. justify-content: center;
  176. align-items: center;
  177. flex-direction: column;
  178. image{
  179. width: 264upx;
  180. height: 212upx;
  181. }
  182. .empty-title{
  183. margin-top: 20rpx;
  184. font-size: 28rpx;
  185. color: gray;
  186. }
  187. }
  188. .w-calc-30 {
  189. padding: 0 30rpx;
  190. width: calc(100% - 60rpx);
  191. }
  192. .hb {
  193. height: 100%;
  194. box-sizing: border-box;
  195. }
  196. .hidden {
  197. overflow: hidden;
  198. }
  199. .base-color {
  200. color: $--base-color;
  201. }
  202. .base-color-2 {
  203. color: $--base-color2;
  204. }
  205. .base-color-3 {
  206. color: $--base-color3;
  207. }
  208. .base-color-9 {
  209. color: $--base-color-9;
  210. }
  211. .base-color-8 {
  212. color: $--base-color-f8;
  213. }
  214. .base-color-6 {
  215. color: $--base-color-6;
  216. }
  217. .base-color-gray {
  218. color: $--base-color-gray;
  219. }
  220. .base-color-red{
  221. color:#ee0a25;
  222. }
  223. .base-color-dark {
  224. color: $--base-color-dark;
  225. }
  226. .base-color-dark2 {
  227. color: $--base-color-dark2;
  228. }
  229. .base-price {
  230. color: $--base-color-price;
  231. }
  232. .base-success {
  233. color: $--base-color-success;
  234. }
  235. .base-bg {
  236. background: $--base-bg;
  237. }
  238. .base-bg-2 {
  239. background: $--base-bg2;
  240. }
  241. .base-bg-red{
  242. background: #ee0a25;
  243. }
  244. .base-bg-f{
  245. background-color:#fff;
  246. }
  247. .base-bg-f8{
  248. background-color: $--base-color-f8;
  249. }
  250. .base-bg-f5{
  251. background-color: $--base-color-f5;
  252. }
  253. .base-bg-9{
  254. background-color: $--base-color-9;
  255. }
  256. .base-bg-blue{
  257. background:$--base-bg-blue;
  258. }
  259. .base-bg-sure{
  260. background:$--base-sure-bg;
  261. }
  262. .base-bg-orange{
  263. background:$--base-bg-orange;
  264. }
  265. .base-bg-false{
  266. background:$--base-false-bg;
  267. }
  268. .bor-blue{
  269. border: 2rpx solid $--base-bor-blue;
  270. }
  271. .bor-red{
  272. border: 2rpx solid $--base-bor-red;
  273. }
  274. .colorf {
  275. color: #fff;
  276. }
  277. .bgf {
  278. background: #fff;
  279. }
  280. .fixed {
  281. position: fixed;
  282. }
  283. .absolute {
  284. position: absolute;
  285. }
  286. .relative {
  287. position: relative;
  288. }
  289. .w100 {
  290. width: 100%;
  291. }
  292. .h100 {
  293. height: 100%;
  294. }
  295. .card {
  296. background: #fff;
  297. border-radius: 15rpx;
  298. }
  299. .cover-height {
  300. height: 100%;
  301. display: flex;
  302. flex-direction: column;
  303. box-sizing: border-box;
  304. }
  305. .row {
  306. display: flex;
  307. flex-direction: row;
  308. }
  309. .column {
  310. display: flex;
  311. flex-direction: column;
  312. }
  313. .justify-start {
  314. display: flex;
  315. justify-content: flex-start;
  316. }
  317. .justify-center {
  318. display: flex;
  319. justify-content: center;
  320. }
  321. .justify-end {
  322. display: flex;
  323. justify-content: flex-end;
  324. }
  325. .justify-around {
  326. display: flex;
  327. justify-content: space-around;
  328. }
  329. .justify-evenly {
  330. display: flex;
  331. justify-content: space-evenly;
  332. }
  333. .justify-between {
  334. display: flex;
  335. justify-content: space-between;
  336. }
  337. .align-start {
  338. display: flex;
  339. align-items: flex-start;
  340. }
  341. .align-center {
  342. display: flex;
  343. align-items: center;
  344. }
  345. .align-end {
  346. display: flex;
  347. align-items: flex-end;
  348. }
  349. .center {
  350. display: flex;
  351. justify-content: center;
  352. align-items: center;
  353. }
  354. .centerV {
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. flex-direction: column;
  359. }
  360. .wrap {
  361. flex-wrap: wrap;
  362. }
  363. .flex-1 {
  364. flex: 1;
  365. }
  366. .ellipsis {
  367. overflow: hidden;
  368. text-overflow: ellipsis;
  369. display: -webkit-box;
  370. -webkit-box-orient: vertical;
  371. box-sizing: border-box;
  372. width: 100%;
  373. -webkit-line-clamp: 1;
  374. }
  375. .lines-2 {
  376. -webkit-line-clamp: 2 !important;
  377. }
  378. .lines-3 {
  379. -webkit-line-clamp: 3 !important;
  380. }
  381. .bold {
  382. font-weight: bold;
  383. }
  384. .line-through {
  385. text-decoration: line-through;
  386. }
  387. .nowrap {
  388. white-space: nowrap;
  389. }
  390. .scrollx {
  391. overflow-x: scroll;
  392. }
  393. .scrolly {
  394. overflow-y: scroll;
  395. }
  396. .cvauto {
  397. content-visibility: auto;
  398. }
  399. </style>
  400. <style>
  401. /*每个页面公共css */
  402. /* 解决小程序和app滚动条的问题 */
  403. /* #ifdef MP-WEIXIN || APP-PLUS */
  404. :deep(::-webkit-scrollbar ){
  405. display: none !important;
  406. width: 0 !important;
  407. height: 0 !important;
  408. -webkit-appearance: none;
  409. background: transparent;
  410. color: transparent;
  411. }
  412. /* #endif */
  413. /* 解决H5 的问题 */
  414. /* #ifdef H5 */
  415. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  416. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  417. display: none;
  418. width: 0 !important;
  419. height: 0 !important;
  420. -webkit-appearance: none;
  421. background: transparent;
  422. color: transparent;
  423. }
  424. /* #endif */
  425. </style>