收藏
回答

手动在模拟器添加token,但是并没有在页面上log出token,这是为什么?

回答关注问题邀请回答
收藏

1 个回答

  • 陈宇明
    陈宇明
    06-06

    需要看下具体代码

    06-06
    有用 1
    回复 2
    • 关朝元
      关朝元
      06-06
      <script setup>
      import { onLoad } from '@dcloudio/uni-app';
      import { ref } from 'vue';
      import api from '../../api';
      // 确认删除这里的 markers 引用
      // console.log('markers', markers);
      const longitude = ref(0);
      const latitude = ref(0);
      const currentMarker = ref(null);
      const isScan = ref(true);
      const markers = ref([]); // 保留这一行
      const app = getApp();
      onLoad(() => {
        uni.getLocation({
          success(res) {
            console.log('res', res);
            longitude.value = res.longitude;
            latitude.value = res.latitude;
          },
          fail(err) {
            console.log('err', err);
          }
        });
        api.getStadiumList().then(res => {
          if (res.code === 0) {
            console.log('res', res);
            app.globalData.markers = markers.value = res.data.map(i => {
              return {
                ...i,
                width: 40,
                iconPath: '/static/profile.png',
                latitude: +i.latitude,
                longitude: +i.longitude,
                title: i.name
              };
            });
          } else {
            uni.showToast({
              title: res.message,
              icon: 'none'
            });
          }
        });
      });
      const handleMarkerTap = (e) => {
        console.log(e.detail.markerId);
        const current = markers.value.find((i) => i.id === e.detail.markerId);
        console.log('current', current);
        currentMarker.value = current;
        isScan.value = false;
      };
      const handleScan = () => {
        uni.scanCode({
          success(res) {
            console.log('res', res.result.split('=')[1]);
          }
        });
      };
      const handleMapTap = () => {
        // isScan.value = true;
      };
      const handleNavTap = () => {
        console.log('跳转到详情');
        uni.navigateTo({
          url: `/pages/ground/ground?id=${currentMarker.value.id}`
        });
      };
      const actionList = [
        { id: 1, src: '/static/search.png', name: '地图搜索' },
        { id: 2, src: '/static/support.png', name: '客服中心' },
        { id: 3, src: '/static/origin.png', name: '回到原点' },
        { id: 4, src: '/static/profile.png', name: '个人中心' }
      ];
      const handlemageTap = (item) => {
        switch (item.id) {
          case 1:
            uni.chooseLocation({
              success(res) {
                console.log('res', res);
                longitude.value = res.longitude;
                latitude.value = res.latitude;
              }
            });
            break;
          case 2:
            console.log('客服中心');
            uni.navigateTo({
              url: '/pages/contact/contact'
            });
            break;
          case 3:
            const mapContext = uni.createMapContext('map');
            mapContext.moveToLocation();
            break;
          case 4:
            console.log('个人中心');
         console.log('token',token)
         if(!app.globalData.token){
          uni.showModal({
           title:'尚未登陆',
         content:'点击确认进行登陆',
         success(res) {
          if(res.confirm){
           uni.navigateTo({
            url:'/pages/login/login'
           })
          }
         }
          })
          return
         }
            uni.navigateTo({
              url: '/pages/profire/profire'
            });
            break;
          default:
            break;
        }
      };
      </script>
      <template>
        <view class="map-box">
          <map
            class="map"
            id="map"
            :longitude="longitude"
            :latitude="latitude"
            show-location
            :markers="markers"
            :scale="10"
            @markertap="handleMarkerTap"
            @tap="handleMapTap"
          ></map>
          <view v-show="isScan" class="scan-box scan-title" @tap="handleScan">扫码借还</view>
          <view v-show="!isScan" class="scan-box marker-sunmmary">
            <!-- left -->
            <view class="scan-box-left">
              <image src="/static/logo.png" mode="widthFix"></image>
            </view>
            <view class="scan-box-center">
              <view class="top scan-box-center-item">
                {{ currentMarker?.title || '-' }}
              </view>
              <view class="bottom scan-box-center-item">
                {{ currentMarker?.address || '-' }}
              </view>
            </view>
            <view class="scan-box-right" @tap="handleNavTap">
              <img src="../../static/nav.png" mode="widthFix" />
            </view>
          </view>
          <view class="action-box">
            <image
              v-for="item in actionList"
              :key="item.id"
              :src="item.src"
              mode="widthFix"
              @tap="handlemageTap(item)"
            ></image>
          </view>
        </view>
      </template>
      <style>
      .map-box {
        position: relative;
      }
      .map {
        width: 100vw;
        height: 100vh;
      }
      .scan-box {
        position: absolute;
        width: 80%;
        height: 120rpx;
        left: 10%;
        bottom: 100rpx;
        background-color: #1296db;
        box-shadow: 0 0 20rpx #1296db;
        border-radius: 20rpx;
        padding: 20rpx 0;
        display: flex;
      }
      .scan-title {
        font-size: 50rpx;
        font-weight: bold;
        justify-content: center;
        align-items: center;
        color: white;
        letter-spacing: 4rpx;
      }
      .marker-sunmmary {
        background-color: white;
      }
      .scan-box-left,
      .scan-box-right {
        width: 120rpx;
        /* background-color: #1296db; */
        margin: 0 20rpx;
      }
      .scan-box-left image,
      .scan-box-right image {
        width: 100%;
        border-radius: 50%;
      }
      .scan-box-right image {
        width: 80%;
        margin: 10% 0 0 10%;
      }
      .scan-box-center {
        flex: 1;
      }
      .scan-box-center-item {
        height: 60rpx;
        line-height: 60rpx;
        width: 280rpx;
        overflow: hidden;
        text-overflow: ellipsis;
        word-spacing: normal;
      }
      .top {
        font-weight: bold;
      }
      .bottom {
        font-size: 28rpx;
      }
      .action-box {
        position: absolute;
        right: 10%;
        bottom: 300rpx;
        width: 90rpx;
        /* background-color: white; */
      }
      .action-box image {
        width: 50rpx;
        padding: 20rpx;
        border-radius: 50%;
        box-shadow: 0 0 20rpx #1296db;
        background-color: white;
        margin-bottom: 40rpx;
      }
      <style>
      06-06
      回复
    • 关朝元
      关朝元
      06-06
      搞定了,不好意思,是我在app.vue里把globalData拼成了globaData,并且没有提供app.vue的代码,感谢您的回复
      06-06
      回复
登录 后发表内容