收藏
回答

TypeError: wxPano.config 报错找不到?

<template>

<pano :panolist="panolist" :entryid="entrypanoid" :entryname="entrypanoname" width="320" height="240" :key="key" :utoinit="false">

<cover-view style="position: fixed;top:80%;width:100%;text-align:center;">

  <cover-view style="width:50%;text-align:center;float:left;" bindtap="covertap">跳转全景图</cover-view>

  

  <cover-view style="width:50%;text-align:center;float:left;" bindtap="setCameraLookAt">切换视角</cover-view>

  <cover-view style="width:50%;text-align:center;float:left;" bindtap="enableTouch">打开触摸</cover-view>

  <cover-view style="width:50%;text-align:center;float:left;" bindtap="disableTouch">关闭触摸</cover-view>

  <cover-view style="width:50%;text-align:center;float:left;" bindtap="getPanoInfo">获取当前全景信息</cover-view>

</cover-view>

</pano>

</template>


<script>



export default {

  // data() {

  //   return {

  //     // 插件状态

  //     pluginReady: false,

  //     showLoading: true,

  //     loadingText: '初始化中...',

  //     loadingRetryCount: 0,

  //     maxRetryCount: 5,

  //     showRetryBtn: false,

      

  //     // 调试信息

  //     debugMode: true, // 开发时开启,生产时关闭

  //     debugInfo: '',

  //     wxPanoExists: false,

  //     configExists: false

  //   };

  // },

  

  onLoad(options) {

  

  // 注意:这里不使用 const,因为插件可能异步加载

  var wxPano = requirePlugin("wxPano")

    console.log('插件管理器:', wxPano);

   // 检查插件是否已授权

    const pluginManager = wx.getPluginManager && wx.getPluginManager();

    // 检查已安装的插件

    const plugins = wx.getStorageSync('plugins') || {};

    console.log('已安装的插件:', plugins);

//console.log('页面加载,开始初始化插件');

    setTimeout(() => {

    wxPano.config({

    panolist:[{

      name:"xindamen",

      src: "https://qcloud.dpfile.com/pc/UVlO2SAIXfHl1S291oBVrhRHEMii-N3Tm7LQBo_RAdcPu-sWyOM5Vp-C07zrDsmD.jpg",

      infospots:[ //信息标记

          {

              type: "modal",

              modal: {

                  title: "wxPano",

                  content: "欢迎使用wxPano"

              },

              position: { x: 0.092, y: 0.434 },

              size: 1,

              icon: "info",

              bindcamera:true,

              bindsize: 0.5,

              bindicon: "info",

              bindopacity:0.75,

              bindposition: { x: 0.5, y: 0.75 }

          },

          {

              type: "page",

              page: function(){

                  wx.navigateTo({url: "ar",

                      success(evt) {

                          console.log(evt);

                      }

                  })

              },

              position: { x: 0.437, y: 0.447 },

              size: 1,

              icon: "info"

          }

      ]

    }],

    request:wx.request,

    loader:"GLLoader",

    entryname:"xindamen"});

    console.log('插件管理器:');

   }, 30000);


 //  setTimeout(() => {

 //     this.initPanoPlugin();

 //  }, 2000);

  },

  

  // onReady() {

  //   console.log('页面就绪,再次检查插件状态');

  //   // 延迟检查,确保页面完全渲染

  //   // setTimeout(() => {

  //     this.checkPluginStatus();

  //   // }, 2000);

  // },

  

  // methods: {

  //   // 检查插件状态

  //   checkPluginStatus() {

  //     try {

  //       // 尝试获取插件

  //       wxPano = requirePlugin("wxPano");

  //       console.log('wxPano对象:', wxPano);

  //       console.log('wxPano类型:', typeof wxPano);

  //       console.log('wxPano属性:', Object.keys(wxPano || {}));

  //       console.log('wxPano对象获取成功,属性检查:', {

  //         config: typeof wxPano.config,

  //         on: typeof wxPano.on,

  //         setCameraLookAt: typeof wxPano.setCameraLookAt

  //       });

  //       this.wxPanoExists = !!wxPano;

  //       this.configExists = wxPano && typeof wxPano.config === 'function';

        

  //       this.debugInfo = `wxPano: ${this.wxPanoExists}, config: ${this.configExists}`;

        

  //       if (wxPano ) {

  //         console.log('插件已就绪,可以调用config');

  //         if (!this.pluginReady) {

  //           this.pluginReady = true;

  //           this.doPanoConfig();

  //         }

  //       } else {

  //         console.warn('插件尚未就绪,继续等待...');

  //       }

  //     } catch (error) {

  //       console.error('检查插件状态时出错:', error);

  //       this.debugInfo = `错误: ${error.message}`;

  //     }

  //   },

    

  //   // 初始化插件

  //   initPanoPlugin() {

  //     console.log('开始初始化全景插件...');

  //     this.showLoading = true;

  //     this.loadingText = '正在加载插件...';

      

  //     // 方案1:直接尝试获取插件

  //     this.loadingRetryCount++;

      

  //     try {

  //       wxPano = requirePlugin("wxPano");

  //       console.log('直接获取wxPano结果:', wxPano);

        

  //       if (wxPano) {

  //         console.log('wxPano对象获取成功,属性检查:', {

  //           config: typeof wxPano.config,

  //           on: typeof wxPano.on,

  //           setCameraLookAt: typeof wxPano.setCameraLookAt

  //         });

          

  //         // 检查插件是否完全就绪

  //         if (typeof wxPano.config === 'function') {

  //           console.log('插件已完全就绪');

  //           this.pluginReady = true;

  //           this.showLoading = false;

  //           this.doPanoConfig();

  //           return;

  //         }

          

  //         // 如果config不存在,尝试监听ready事件

  //         if (typeof wxPano.on === 'function') {

  //           console.log('监听插件ready事件...');

  //           wxPano.on('ready', () => {

  //             console.log('收到插件ready事件');

  //             this.pluginReady = true;

  //             this.showLoading = false;

  //             this.doPanoConfig();

  //           });

            

  //           // 设置超时

  //           setTimeout(() => {

  //             if (!this.pluginReady) {

  //               console.warn('ready事件超时,尝试直接调用');

  //               this.checkPluginStatus();

  //             }

  //           }, 3000);

  //         } else {

  //           // 如果没有on方法,开始轮询

  //           this.startPolling();

  //         }

  //       } else {

  //         console.warn('requirePlugin返回null或undefined');

  //         this.startPolling();

  //       }

  //     } catch (error) {

  //       console.error('获取插件时出错:', error);

  //       this.startPolling();

  //     }

  //   },

    

  //   // 开始轮询检查

  //   startPolling() {

  //     console.log('开始轮询检查插件状态...');

      

  //     if (this.loadingRetryCount >= this.maxRetryCount) {

  //       this.showLoading = false;

  //       this.showRetryBtn = true;

  //       this.loadingText = '插件加载失败';

  //       console.error('达到最大重试次数,插件加载失败');

  //       return;

  //     }

      

  //     this.loadingRetryCount++;

  //     this.loadingText = `尝试加载插件 (${this.loadingRetryCount}/${this.maxRetryCount})...`;

      

  //     setTimeout(() => {

  //       this.checkPluginStatus();

  //       if (!this.pluginReady) {

  //         this.startPolling();

  //       }

  //     }, 1500);

  //   },

    

  //   // 执行插件配置

  //   doPanoConfig() {

  //     if (!this.pluginReady || !wxPano) {

  //       console.error('插件未就绪,无法配置');

  //       return;

  //     }

      

  //     try {

  //       console.log('开始执行wxPano.config...');

  //       // 执行配置

  //       wxPano.config({

  //         panolist: [{

  //           name: "office_scene",

  //           src: "../../assets/11045.jpg",

  //         }],

  //         loader: "GLLoader",

  //         entryname: "office_scene"

  //       });

  //       // 检查配置函数是否存在

  //       if (typeof wxPano.config !== 'function') {

  //         console.error('wxPano.config不是函数:', wxPano.config);

  //         this.showRetryBtn = true;

  //         this.loadingText = '插件API异常';

  //         return;

  //       }

        


        

  //       console.log('wxPano.config执行成功');

  //       this.showLoading = false;

        

  //       // 监听事件

  //       this.setupEventListeners();

        

  //       // 显示成功提示

  //       uni.showToast({

  //         title: '全景加载成功',

  //         icon: 'success',

  //         duration: 2000

  //       });

        

  //     } catch (error) {

  //       console.error('执行wxPano.config时出错:', error);

  //       uni.showToast({

  //         title: `配置失败: ${error.message}`,

  //         icon: 'none',

  //         duration: 3000

  //       });

        

  //       this.showRetryBtn = true;

  //       this.loadingText = '配置失败,请重试';

  //     }

  //   },

    

  //   // 设置事件监听

  //   setupEventListeners() {

  //     if (!wxPano) return;

      

  //     // 监听导航事件

  //     if (typeof wxPano.onNavigate === 'function') {

  //       wxPano.onNavigate = (event) => {

  //         console.log('导航事件:', event);

  //       };

  //     }

      

  //     // 监听加载事件

  //     if (typeof wxPano.on === 'function') {

  //       wxPano.on('load', (event) => {

  //         console.log('场景加载完成:', event);

  //       });

        

  //       wxPano.on('error', (error) => {

  //         console.error('插件错误:', error);

  //       });

  //     }

  //   },

    

  //   // 测试插件API

  //   testPlugin() {

  //     console.log('=== 测试插件API ===');

  //     console.log('1. requirePlugin结果:', requirePlugin("wxPano"));

  //     console.log('2. wxPano对象:', wxPano);

  //     console.log('3. 插件配置:', uni.getStorageSync('plugins'));

      

  //     // 尝试其他方式获取插件

  //     if (typeof wx !== 'undefined') {

  //       console.log('4. 检查全局wx对象:', {

  //         getPlugin: typeof wx.getPlugin,

  //         requirePlugin: typeof wx.requirePlugin

  //       });

  //     }

      

  //     // 检查uni对象

  //     console.log('5. uni对象方法:', {

  //       requirePlugin: typeof uni.requirePlugin

  //     });

      

  //     // 尝试使用uni.requirePlugin

  //     try {

  //       const plugin = uni.requirePlugin("wxPano");

  //       console.log('6. uni.requirePlugin结果:', plugin);

  //     } catch (error) {

  //       console.error('uni.requirePlugin错误:', error);

  //     }

  //   },

    

  //   // 重试加载

  //   retryLoadPlugin() {

  //     console.log('重新加载插件...');

  //     this.loadingRetryCount = 0;

  //     this.pluginReady = false;

  //     this.showRetryBtn = false;

  //     this.showLoading = true;

  //     this.loadingText = '重新加载中...';

      

  //     // 清除可能的缓存

  //     wxPano = null;

      

  //     // 重新初始化

  //     setTimeout(() => {

  //       this.initPanoPlugin();

  //     }, 1000);

  //   },

    

  //   // 重置视角

  //   resetView() {

  //     if (!this.pluginReady || !wxPano || typeof wxPano.setCameraLookAt !== 'function') {

  //       uni.showToast({

  //         title: '插件未就绪',

  //         icon: 'none'

  //       });

  //       return;

  //     }

      

  //     try {

  //       wxPano.setCameraLookAt({ x: 0.5, y: 0.5 });

  //     } catch (error) {

  //       console.error('重置视角失败:', error);

  //     }

  //   }

  // },

  

  // onUnload() {

  //   // 清理资源

  //   if (wxPano && typeof wxPano.destroy === 'function') {

  //     wxPano.destroy();

  //   }

  //   wxPano = null;

  // }

};

</script>


<style scoped>

.pano-container {

  width: 100vw;

  height: 100vh;

  position: relative;

  overflow: hidden;

}


.loading-overlay {

  position: absolute;

  top: 0;

  left: 0;

  width: 100%;

  height: 100%;

  background: #000;

  display: flex;

  justify-content: center;

  align-items: center;

  z-index: 1000;

}


.loading-content {

  display: flex;

  flex-direction: column;

  align-items: center;

  padding: 40rpx;

}


.loading-spinner {

  width: 80rpx;

  height: 80rpx;

  border: 8rpx solid rgba(255, 255, 255, 0.1);

  border-top: 8rpx solid #00b4ff;

  border-radius: 50%;

  animation: spin 1s linear infinite;

  margin-bottom: 40rpx;

}


@keyframes spin {

  0% { transform: rotate(0deg); }

  100% { transform: rotate(360deg); }

}


.loading-text {

  color: #fff;

  font-size: 32rpx;

  margin-bottom: 20rpx;

  text-align: center;

}


.debug-info {

  color: #ff9900;

  font-size: 24rpx;

  margin: 20rpx 0;

  background: rgba(0, 0, 0, 0.5);

  padding: 10rpx 20rpx;

  border-radius: 10rpx;

}


.retry-btn {

  background: #00b4ff;

  color: white;

  border: none;

  border-radius: 40rpx;

  padding: 20rpx 40rpx;

  font-size: 28rpx;

  margin-top: 40rpx;

}


.debug-panel {

  position: absolute;

  top: 100rpx;

  left: 20rpx;

  background: rgba(0, 0, 0, 0.7);

  color: white;

  padding: 20rpx;

  border-radius: 10rpx;

  font-size: 24rpx;

  z-index: 1001;

  display: flex;

  flex-direction: column;

  gap: 10rpx;

}


.debug-panel button {

  background: #ff9900;

  color: white;

  border: none;

  border-radius: 20rpx;

  padding: 10rpx 20rpx;

  font-size: 24rpx;

  margin-top: 10rpx;

}


.pano-wrapper {

  width: 100%;

  height: 100%;

  background: #000;

}

</style>

回答关注问题邀请回答
收藏
登录 后发表内容