App.vue 10 KB

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