App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <script>
  2. import initConfig from '@/initConfig.js';
  3. // #ifdef MP-WEIXIN
  4. import { SCAN_QR_CACHE } from '@/settings/enums.js';
  5. // #endif
  6. /** 从 scene 或 query 中解析:二维码 s=店铺id,t=桌号id */
  7. function parseSceneToStoreTable(sceneStr) {
  8. const trim = (v) => (v == null ? '' : String(v).trim());
  9. let storeId = '';
  10. let tableId = '';
  11. if (!sceneStr) return { storeId, tableId };
  12. const str = trim(sceneStr);
  13. try {
  14. const parts = str.split('&');
  15. parts.forEach((pair) => {
  16. const [k, v] = pair.split('=').map((s) => (s ? decodeURIComponent(String(s).trim()) : ''));
  17. if (k === 's' || k === 'storeId' || k === 'store_id') storeId = trim(v);
  18. if (k === 't' || k === 'tableId' || k === 'table_id' || k === 'tableid') tableId = trim(v);
  19. });
  20. } catch (err) {
  21. console.warn('parseSceneToStoreTable', err);
  22. }
  23. return { storeId, tableId };
  24. }
  25. export default {
  26. onLaunch: function (e) {
  27. // 只有小程序执行
  28. // #ifdef MP-WEIXIN
  29. initConfig();
  30. // 通过二维码编译/扫码进入:将二维码携带的信息缓存(query.scene 为小程序码参数,query.q 为普通链接二维码)
  31. try {
  32. const sceneEnc = e?.query?.scene;
  33. const qEnc = e?.query?.q;
  34. const scene = sceneEnc != null && sceneEnc !== '' ? decodeURIComponent(String(sceneEnc)) : '';
  35. const q = qEnc != null && qEnc !== '' ? decodeURIComponent(String(qEnc)) : '';
  36. const rawFromQR = scene || q || '';
  37. if (rawFromQR) {
  38. const { storeId, tableId } = parseSceneToStoreTable(rawFromQR);
  39. const payload = { raw: rawFromQR, storeId, tableId };
  40. uni.setStorageSync(SCAN_QR_CACHE, JSON.stringify(payload));
  41. if (storeId) uni.setStorageSync('currentStoreId', storeId);
  42. if (tableId) uni.setStorageSync('currentTableId', tableId);
  43. }
  44. } catch (err) {
  45. console.warn('缓存二维码启动参数失败', err);
  46. }
  47. // #endif
  48. },
  49. onShow: function (res) {
  50. console.log('App Show', res);
  51. // 是否是从被打开的小程序返回
  52. const { appId, extraData } = res.referrerInfo;
  53. if (appId && extraData) {
  54. uni.$emit('listener:ArBack', res.referrerInfo);
  55. }
  56. },
  57. onHide: function () {
  58. console.log('App Hide');
  59. }
  60. };
  61. </script>
  62. <style lang="scss">
  63. view,
  64. image,
  65. label {
  66. box-sizing: border-box;
  67. word-break: break-all;
  68. }
  69. image {
  70. height: auto;
  71. width: auto;
  72. }
  73. /* #ifndef APP-NVUE */
  74. // 设置整个项目的背景色
  75. page {
  76. background-color: #f7f9fa;
  77. }
  78. /* #endif */
  79. // 弹性盒子
  80. .flex {
  81. display: flex;
  82. &-none {
  83. flex: none;
  84. }
  85. &-1 {
  86. flex: 1;
  87. }
  88. &-y {
  89. flex-direction: column;
  90. }
  91. &-top {
  92. align-items: flex-start !important;
  93. }
  94. // 顶部对齐
  95. &-bottom {
  96. align-items: flex-end;
  97. }
  98. // 底部对齐
  99. &-content-end {
  100. justify-content: flex-end;
  101. }
  102. // 水平靠右 || 垂直靠下对齐
  103. &-center {
  104. align-items: center;
  105. }
  106. // 水平居中对齐
  107. &-center-center {
  108. align-items: center;
  109. justify-content: center;
  110. }
  111. // 水平垂直居中
  112. &-between {
  113. justify-content: space-between;
  114. }
  115. // 两端不留间隙对齐
  116. &-around {
  117. justify-content: space-around;
  118. }
  119. // 两端留间隙对齐
  120. &-wrap {
  121. flex-wrap: wrap;
  122. }
  123. // 允许换行
  124. }
  125. .w-0 {
  126. width: 0;
  127. }
  128. .h-0 {
  129. height: 0;
  130. }
  131. // 隐藏显示多少行
  132. .ellipsis {
  133. overflow: hidden;
  134. text-overflow: ellipsis;
  135. display: -webkit-box;
  136. -webkit-box-orient: vertical;
  137. -webkit-line-clamp: 1;
  138. word-break: break-all;
  139. @for $i from 2 through 10 {
  140. &.ellipsis-#{$i} {
  141. -webkit-line-clamp: $i;
  142. }
  143. }
  144. &-no {
  145. display: block;
  146. }
  147. }
  148. // 点击时的透明度
  149. .hover-active {
  150. opacity: 0.8 !important;
  151. }
  152. // 底部安全区
  153. .safe-area {
  154. padding-bottom: constant(safe-area-inset-bottom);
  155. /* 兼容 iOS < 11.2 */
  156. padding-bottom: env(safe-area-inset-bottom);
  157. /* 兼容 iOS >= 11.2 */
  158. }
  159. .ql-editor.ql-blank:before {
  160. color: #999999;
  161. font-size: 28rpx;
  162. font-style: normal;
  163. }
  164. </style>