import { createApp } from 'vue'
import App from './App.vue'
import router from './router.js'
import './assets/styles/style.less'

const app = createApp(App);

app.config.globalProperties.$navigate = (e) => {
  if (window.__wxjs_environment === 'miniprogram') {
    const index = e.indexOf('?');
    let query = '';
    if (index > -1)
      query = e.slice(index);
    const data = router.resolve({ path: e });
    wx.miniProgram.navigateTo({
      url: `/pages/webview/webview?url=${encodeURIComponent(`${location.origin}/${data.href}${query}`)}`,
    });
  }
  else { router.push(e); }
};

app.use(router)
app.mount('#app')

// 禁用移动端双击缩放和多指缩放
document.addEventListener('touchstart', (event) => {
  if (event.touches.length > 1 && event.cancelable) {
    event.preventDefault();
  }
}, { passive: false });

let lastTouchEnd = 0;
document.addEventListener('touchend', (event) => {
  const now = new Date().getTime();
  if (now - lastTouchEnd <= 300) {
    if (event.cancelable) {
      event.preventDefault();
    }
  }
  lastTouchEnd = now;
}, false);
