Ver código fonte

加气优惠二期

chenlei 1 ano atrás
pai
commit
840959fef1

+ 1 - 1
src/components/container/index.vue

@@ -22,7 +22,7 @@
     </div>
     <div class="pt-spac" v-if="props.showSpac" />
     <!-- 小程序内只能用v-if移除组件,如果用v-show条件false时,整个页面不显示。。 -->
-    <ay-pull v-if="store.curPage.pageConfig?.isPager">
+    <ay-pull v-if="store.curPage.pageConfig?.isPager" :showSpac="props.showSpac">
       <slot />
     </ay-pull>
     <slot v-else />

+ 56 - 27
src/components/pull/index.vue

@@ -1,23 +1,31 @@
 <template>
-  <div>
-    <!-- #ifdef MP || APP-PLUS -->
+  <!-- 
+        采用非固定方式,将会影响内容插槽内的吸顶效果,最终还是使用固定方式
+        :fixed="false"
+      :use-page-scroll="true" 
+      -->
+  <z-paging
+    ref="paging"
+    refresher-only
+    :show-scrollbar="false"
+    @onRefresh="methods.onRefresh(false)"
+    @scrolltolower="methods.onRefresh(true)"
+    :paging-style="{ top: topHeightPX }"
+  >
+    <!-- 左侧间距 -->
+    <template #left>
+      <div class="pr-spac"></div>
+    </template>
+    <!-- 右侧间距 -->
+    <template #right>
+      <div class="pr-spac"></div>
+    </template>
+    <!-- 顶部间距,不放到slot="top"插槽内是因为,向上滑动时,页面只会被头部遮挡,体验更舒服 -->
+    <div class="pt-spac" v-if="props.showSpac" />
+    <!-- 内容插槽-定义 -->
     <slot />
-    <!-- #endif -->
-    <!-- #ifdef H5 -->
-    <van-list @load="methods.onLoad">
-      <slot />
-    </van-list>
-    <!-- #endif -->
-    <!-- <z-paging
-      ref="paging"
-      refresher-only
-      @onRefresh="methods.onRefresh"
-      :paging-style="{ top: '98px' }"
-    >
-      <slot />
-    </z-paging> -->
-    <!-- <uni-load-more :status="status" :content-text="contentText" /> -->
-    <div class="center s-fz">
+    <!-- 加载状态 失败重试 -->
+    <div class="center s-fz nmt-spac mb-spac">
       <uni-load-more :status="status" :content-text="contentText" />
       <ay-refresh
         v-if="store.curPage.pagerInfo.error"
@@ -26,21 +34,34 @@
         @refresh="store.curPage.pagerMethods.refresh({ isAdd: store.curPage.pagerInfo.isAdd })"
       ></ay-refresh>
     </div>
-  </div>
+  </z-paging>
+  <!-- <uni-load-more :status="status" :content-text="contentText" /> -->
 </template>
 <script lang="ts" setup>
 const paging = ref()
 defineOptions({
   name: 'pull',
 })
-const props = defineProps<{ pagingStyle?: object }>()
-const methods: AyContainerPullMethods = {
-  // onRefresh() {
-  //   console.log(arguments)
-  //   paging.value.complete()
-  // },
+const topHeightPX = computed(() => config.common.safeAreaTopHeight + 'px')
+
+const props = defineProps<{ showSpac: boolean }>()
+const methods = {
+  onRefresh(isAdd) {
+    store.curPage.pagerMethods.refresh({ isAdd })
+  },
 }
-// 小程序环境内,多次创建本组件时data不会被清理,computed始终监听是第一页本组件的data,造成后续列表页面无uni-load-more状态的问题,改为将在store内computed
+watch(
+  () => store.curPage.pagerInfo.loading,
+  (nv) => {
+    if (nv === false) {
+      paging.value.complete()
+    }
+  },
+)
+// onMounted(() => {
+//   store.curPage.pagerMethods.setCurZPagingRef(paging)
+// })
+// 小程序环境内,多次创建本组件时data不会被清理,computed始终监听第一页本组件的data,造成后续列表页面无uni-load-more状态的问题,改为在store内computed
 const status = computed(() => store.curPage.loadMoreStatus)
 const contentText = computed(() => store.curPage.loadMoreContentText)
 // const data: PagerInfo = store.curPage.pageConfig.pagerInfo
@@ -79,4 +100,12 @@ const contentText = computed(() => store.curPage.loadMoreContentText)
 // })
 // methods = store.curPage.pagerMethods
 </script>
-<style lang="scss" scoped></style>
+<style lang="scss">
+// .z-paging-content {
+//   right: $p-spac;
+//   left: $p-spac;
+// }
+// .zp-paging-main ::-webkit-scrollbar {
+//   display: none; /* 对于Webkit浏览器 */
+// }
+</style>

+ 2 - 1
src/pages.json

@@ -53,7 +53,8 @@
       "path": "pages/order/index",
       "type": "page",
       "style": {
-        "enablePullDownRefresh": true
+        "enablePullDownRefresh": false,
+        "navigationStyle": "custom"
       }
     },
     {

+ 66 - 25
src/pages/index/index.vue

@@ -1,10 +1,10 @@
 <template>
-  <ay-container v-show="store.user.isLogined">
-    <div class="chunk">
+  <ay-container>
+    <div class="chunk p-b-0">
       <div class="center justify-between top">
         <div class="center" @click="methods.goPerson">
           <image class="personal" :src="store.user.userInfo.head_url" mode="scaleToFill" />
-          <div>
+          <div :class="{ 'p-color': !store.user.isLogined }">
             <div>{{ store.user.userInfo.user_name }}</div>
             <div class="mobile">{{ store.user.userInfo.mobileDes }}</div>
           </div>
@@ -39,21 +39,19 @@
           </div>
         </ay-flowLine>
       </div>
-      <div class="center qrcode-text">
-        <template v-if="!data.firstUnload">
-          <template v-if="data.hasnopayfordriver">存在未支付完成订单</template>
-          <template v-else-if="data.qrcode.expire">
-            二维码已失效
-            <ay-refresh
-              :iconSize="36"
-              :loading="store.webapi.strategy.get_user_qrcode.ing"
-              @refresh="methods.getQrcode"
-            ></ay-refresh>
-          </template>
-          <template v-else>
-            有效时间:
-            <ay-countdown :seconds="data.qrcode.seconds" @ender="data.qrcode.expire = true" />
-          </template>
+      <div class="center qrcode-text mb-spac" v-if="!data.firstUnload">
+        <template v-if="data.hasnopayfordriver">存在未支付完成订单</template>
+        <template v-else-if="data.qrcode.expire">
+          二维码已失效
+          <ay-refresh
+            :iconSize="36"
+            :loading="store.webapi.strategy.get_user_qrcode.ing"
+            @refresh="methods.getQrcode"
+          ></ay-refresh>
+        </template>
+        <template v-else>
+          有效时间:
+          <ay-countdown :seconds="data.qrcode.seconds" @ender="data.qrcode.expire = true" />
         </template>
       </div>
     </div>
@@ -73,6 +71,7 @@
         <div class="chunk m0 h-100% s-fz cars" @click="methods.truckManage">
           <div>
             <div class="mb-spacd4" v-show="showcm">车辆管理</div>
+            <div v-if="!store.user.isLogined">{{ config.common.nullView[0] }}</div>
             <div v-show="store.webapi.strategy.get_truck_info.firstSuccess">
               <div class="p-color mt-spac" v-if="data.truckInfo.length === 0">添加车辆</div>
               <div v-else>
@@ -96,7 +95,7 @@
       </div>
     </div>
     <div class="chuck list-app">
-      <ay-sticky :top="topHeightPX" relativeTo="#stations" targetSelector="#stationTop">
+      <ay-sticky :top="0" relativeTo="#stations" targetSelector="#stationTop">
         <div
           class="center justify-between sticky"
           id="stationTop"
@@ -131,7 +130,7 @@
       </div>
       <div
         class="center p-color"
-        v-show="!data.firstUnload && !data.userLocation"
+        v-show="!data.userLocation"
         @click="methods.getListApp({ activation: true })"
       >
         查看附近加气站
@@ -158,7 +157,7 @@
         </div>
       </uni-popup-dialog>
     </uni-popup>
-
+    <!-- 城市列表抽屉 -->
     <ay-drawer
       ref="drawer"
       mode="right"
@@ -204,6 +203,15 @@ const staticData = {
   indexedListWatcher: null,
   /** 页面滚动距离 */
   scrollTop: 0,
+  /** 需要登录的方法名 */
+  IdentityMethods: [
+    'goPerson',
+    'scanCode',
+    'getQrcode',
+    'goAccount',
+    'truckManage',
+    'goPage',
+  ] as (keyof typeof methods)[],
 }
 
 const data = ay.initData({
@@ -630,6 +638,34 @@ const methods = ay.initMethods(
   {
     scanCode: { showLoading: true },
   },
+  {
+    ba(methodName) {
+      // console.log(k)
+      // 需要登录的功能
+      if (staticData.IdentityMethods.includes(methodName)) {
+        // 未登录
+        if (!store.user.isLogined) {
+          if (methodName === 'goPerson') {
+            return true
+          } else {
+            func.native
+              .showModal({
+                title: '请先登录账号',
+                confirmText: '同意',
+                cancelText: '再看看',
+                showCancel: true,
+              })
+              .then((res) => {
+                if (res.confirm) {
+                  ay.goLogin()
+                }
+              })
+            return false
+          }
+        }
+      }
+    },
+  },
 )
 ay.entrance(
   async (args) => {
@@ -659,10 +695,15 @@ ay.entrance(
         .catch()
 
       // #endif
-      methods.initWS()
       methods.getCityList()
       data.station.curCity = uni.getStorageSync(staticData.cctkn) || staticData.defCity
       methods.getListApp({ cras: args.cras })
+      if (!store.user.isLogined) {
+        // data.hasnopayfordriver = false
+        // data.firstUnload = false
+        return
+      }
+      methods.initWS()
       await init()
       // 无未支付订单
       if (!data.hasnopayfordriver) {
@@ -681,9 +722,9 @@ ay.entrance(
       //   init()
       // }
     }
-    if (args.loadType === enums.LoadType.onShow) {
-      init()
-    }
+    // if (args.loadType === enums.LoadType.onShow) {
+    //   init()
+    // }
   },
   {
     addLoadTypes: [enums.LoadType.onShow],

+ 8 - 7
src/pages/order/index.vue

@@ -67,11 +67,12 @@
         </div>
       </div>
     </div>
-    <uni-drawer
+    <ay-drawer
       ref="drawer"
       mode="right"
       :maskClick="true"
       :width="config.common.SystemInfo.windowWidth"
+      :top="topHeightPX"
       @change="methods.drawerChange"
     >
       <div class="m-spac">
@@ -130,15 +131,15 @@
           <button type="primary" @click="methods.saveFilters">确定</button>
         </div>
       </div>
-    </uni-drawer>
+    </ay-drawer>
   </ay-container>
 </template>
 
 <script lang="ts" setup>
 const staticData = {
-  // 缓存筛选条件key名
+  /** 缓存筛选条件key名 */
   fcn: 'filterCheckeds',
-  // 全部选项的value值
+  /** 全部选项的value值 */
   nullValue: '-1',
   payTypeGroups: [
     { label: '支付方式', type: 0, hasStatus: ['-1', '10'] },
@@ -147,6 +148,9 @@ const staticData = {
   ],
 }
 const drawer = ref()
+const topHeight = computed(() => config.common.safeAreaTopHeight)
+const topHeightPX = computed(() => `${topHeight.value}px`)
+
 const data = ay.initData({
   /** 确定选中条件数量 */
   checkCount: 0,
@@ -232,9 +236,6 @@ const checkCount = computed(() =>
     .reduce((a, b) => a + b, 0),
 )
 const methods = {
-  stickChange(e) {
-    console.log(e)
-  },
   goDetail(od) {
     ay.goPage(config.pages.order_orderDetail, { params: od })
   },

+ 1 - 1
src/types/page.d.ts

@@ -12,7 +12,7 @@ interface ayPage {
   readonly identity?: boolean
   /** 是分页页面 */
   readonly isPager: boolean
-  /** 页面配置,对应 小程序.json */
+  /** 页面配置,对应 小程序.json 。特别注意:修改后需要重启项目才会生效!!! */
   readonly style?: CopyGlobalStyle // @uni-helper/vite-plugin-uni-pages.GlobalStyle
   /** 分页数据 */
   readonly pagerInfo?: PagerInfo

+ 7 - 0
src/utils/config/index.ts

@@ -9,6 +9,13 @@ const common = {
     /** 提交审核假数据 */
     examine: ' examine',
   },
+  /** 空值显示 */
+  get nullView() {
+    return {
+      0: '--',
+      1: '0',
+    }
+  },
   /** 骨架屏默认 */
   skeletons: [
     ...Array(20).fill({

+ 4 - 3
src/utils/config/pages.ts

@@ -20,7 +20,7 @@ export default {
     _url: '/pages/index/index',
     _type: 'page',
     title: '大象加气 · 驾驶员端',
-    identity: true,
+    identity: false,
     isPager: true,
     style: {
       enablePullDownRefresh: false,
@@ -62,7 +62,8 @@ export default {
     identity: true,
     isPager: true,
     style: {
-      enablePullDownRefresh: true
+      enablePullDownRefresh: false,
+      navigationStyle: 'custom'
     }
   } as ayPage,
   order_orderDetail: {
@@ -131,7 +132,7 @@ export default {
     _url: '/pages/station/detail',
     _type: 'page',
     title: '加气站详情',
-    identity: true,
+    identity: false,
     isPager: false
   } as ayPage,
   cards_index: {

+ 28 - 14
src/utils/container/index.ts

@@ -28,7 +28,16 @@ export default {
   },
   /** 初始化对象内的方法,自动为对象内所有方法增加防重提功能(同步方法、异步方法执行中再次触发不执行) */
 
-  initMethods<T>(methods: T, ext?: Record<string, { showLoading?: boolean }>): T {
+  initMethods<T>(
+    methods: T,
+    extEach?: Record<string, { showLoading?: boolean; ba?: () => void }>,
+    ext?: {
+      /**
+       * 前置通知,返回false时不执行目标方法
+       * @param methodName:方法名
+       */ ba?: (methodName: keyof T) => boolean | void
+    },
+  ): T {
     const rv = {}
     const executings = {}
     for (const [k, v] of Object.entries(methods)) {
@@ -37,15 +46,20 @@ export default {
           apply(target, arg, argArray) {
             if (executings[k] === true) return
             executings[k] = true
+            const bar = ext?.ba(k)
+            if (bar === false) {
+              executings[k] = false
+              return
+            }
             const rv = v(...argArray)
             // 异步方法
             if (rv?.finally) {
-              if (ext[k]?.showLoading) {
+              if (extEach[k]?.showLoading) {
                 uni.showLoading({ title: config.common.RequestExtDef.loadingText })
               }
               rv.finally(() => {
                 executings[k] = false
-                if (ext[k]?.showLoading) {
+                if (extEach[k]?.showLoading) {
                   // 在调用hideLoading与hideToast时配置参数noConflict: true取消混用特性,解决hideLoading隐藏showToast提示的问题。
                   uni.hideLoading({ noConflict: true })
                 }
@@ -185,17 +199,17 @@ export default {
           callBack(args)
         }
         // 在onload中 初始化原生方法时,之前的代码不能有await,否则小程序环境'重新进入小程序' 无法触发
-        onReachBottom(() => {
-          store.curPage.pagerMethods.refresh({ isAdd: true })
-        })
-        onPullDownRefresh(() => {
-          store.curPage.pagerMethods.refresh({ isAdd: false })
-        })
-      } else {
-        onPullDownRefresh(() => {
-          args.loadType = enums.LoadType.refresh
-          callBack(args)
-        })
+        // onReachBottom(() => {
+        //   store.curPage.pagerMethods.refresh({ isAdd: true })
+        // })
+        // onPullDownRefresh(() => {
+        //   store.curPage.pagerMethods.refresh({ isAdd: false })
+        // })
+        // } else {
+        //   onPullDownRefresh(() => {
+        //     args.loadType = enums.LoadType.refresh
+        //     callBack(args)
+        //   })
       }
       // if (options) {
       //   args.options = options

+ 1 - 7
src/utils/func/convert.ts

@@ -1,9 +1,3 @@
-const maps = {
-  nullView: {
-    0: '--',
-    1: '0',
-  },
-}
 const convert = {
   transformFromBaiduToGCJ(latitude, longitude) {
     const xPi = (3.14159265358979323846264338327950288 * 3000.0) / 180.0
@@ -21,7 +15,7 @@ const convert = {
     return mobile && mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
   },
   nullView(data, type = 0) {
-    const rv = !data && data !== 0 ? maps.nullView[type] : data
+    const rv = !data && data !== 0 ? config.common.nullView[type] : data
     return rv
   },
   getOrderStatusStr(settleStatus) {

+ 1 - 1
src/utils/store/common.ts

@@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
 
 export default defineStore('common', () => {
   const data = reactive({
-    debug: false,
+    debug: true,
     /** 加气量上限 */
     preferWeight: 800,
     /** 客服电话 */

+ 3 - 2
src/utils/store/curPage.ts

@@ -1,5 +1,5 @@
 import { defineStore } from 'pinia'
-const debug = () => import.meta.env.DEV && true
+const debug = () => import.meta.env.DEV && false
 /** 当前页面地址 */
 const curPage = ref<string>()
 /** 预制页面地址 */
@@ -50,7 +50,8 @@ const pagerMethods = {
     // #ifdef H5
     pagerInfo.value.loaded = true
     // #endif
-    uni.stopPullDownRefresh()
+    // uni.stopPullDownRefresh()
+    // pageConfig.value.zPagingRef.complete()
     pagerInfo.value.loading = false
     if (!args) return
     if (args.pages) {

+ 2 - 0
src/utils/store/user.ts

@@ -16,6 +16,8 @@ interface TUser extends Token认证用户实体 {
 const service = 'miniprogram'
 const initState = {
   Identifier: Base64.encode(service + ':org:user:role'),
+  head_url: defHead,
+  user_name: '登录/注册',
 }
 
 const useUserStore = defineStore(