import Taro from '@tarojs/taro'
import Vue from 'vue'
import BasicLayout from '@/components/Layout/Basic'
// import Markdown from '@/components/Markdown'
import { vueAuthPlugin } from '@/util/auth-plugin'
import store from './store/index'

import './app.scss'
import './iconfont.scss'

// Vue.config.productionTip = false

// 引入项目通用（顶层）方法对象
import ToolClass from './util/PublicMethod/index'
Vue.prototype.ToolClass = ToolClass

Vue.use(vueAuthPlugin)
Vue.component('BasicLayout', BasicLayout)
// Vue.component('Markdown', Markdown)

const App = new Vue({
  store,
  onLaunch (options) {
    this.login(options)
  },
  render(h) {
    // this.$slots.default 是将要会渲染的页面
    return h('block', this.$slots.default)
  },
  methods: {
    login(options) {
      Taro.login({
        success (res) {
          if (res.code) {
            store.dispatch(
              'user/MainSignIn',
              { queryData: { code: res.code } }
            ).then((res) => { // 获取用户信息
              store.commit(
                'user/EditUserInfo',
                { name: 'PersonId', value: res.data.data.person.personId }
              )

              store.commit(
                'user/EditUserInfo',
                { name: 'OpenId', value: res.data.data.person.openId }
              )
              
              store.commit(
                'user/EditUserInfo',
                { name: 'SessionKey', value: res.data.data.person.sessionKey }
              )
              
              store.commit(
                'user/EditUserInfo',
                { name: 'Phone', value: res.data.data.person.phone }
              )
            })
          } else {
            Taro.showToast({
              title: '初始化失败, 请退出重试',
              icon: 'none',
              duration: 3000
            })
          }
        }
      })
    }
  }
})

export default App
