# Example(async、建议)

// === Step 1 - 异步引入 ===

// SlugQA 实例
Vue.mixin({
  beforeCreate() {
    const options = this.$options
    if (options.qa) {
      this.$qa = options.qa
    } else if (options.parent && options.parent.$qa) {
      this.$qa = options.parent.$qa
    }
  },
})
// SlugQA 异步组件
let slugQaCompsCache = undefined
let slugQaComps = (name) => {
  if (!slugQaCompsCache) {
    slugQaCompsCache = import(
      /* webpackChunkName: 'slug-qa' */ '@tencent/slug-qa/dist/component.esm'
    )
  }
  return () => slugQaCompsCache.then((comps) => comps[name])
}
Vue.component('slug-qa-center-pane', slugQaComps('QaCenterPane'))
Vue.component('slug-qa-detail', slugQaComps('QaDetail'))
Vue.component('slug-qa-find', slugQaComps('QaFind'))
Vue.component('slug-qa-ask', slugQaComps('QaAsk'))
Vue.component('slug-qa-search', slugQaComps('QaSearch'))

// === Step 2 - 配置 ===
const slugQACfg = {
  options: {
    game: store.state.global.game,
    bhost: [
      'sy.qq.com',
      sessionStorage.igEnv == 'development' ? '' : 'test.ingame.qq.com',
    ],
  },
  theme: {
    colors: Object.assign({}, window.config.theme.color, {
      6: undefined, // 通用微社区已设置背景色,通用问答不用设置背景色
    }),
    searchbg: qaCfg ? qaCfg.searchbg : undefined,
    download: downloadNav.active
      ? {
          url: downloadNav.download_url,
          img: downloadNav.img_url,
        }
      : undefined,
  },
  nav: {
    back: true,
    find: {
      name: 'qa',
    },
    search: {
      name: 'qa',
      query: {
        qa_page: 'search',
      },
    },
    ask: {
      name: 'qa',
      query: {
        qa_page: 'ask',
      },
    },
    detail(id) {
      console.log('detail', id)
      return {
        name: 'qa-detail',
        params: { id },
      }
    },
  },
  inject: {
    // UI 组件
    SlugUI: { Toast },
    // 分享组件:需要sdk支持:msdk3->1 msdk5->2 其它->1
    SlugShare: `https://tiem-cdn.qq.com/slugteam/components/share/v${
      ingameEnvCheck.slugQAMSDKV5 ? 2 : 1
    }.0/slug-share.min.js`,
    shareURL: (qid) =>
      sessionStorage.igEnv === 'development'
        ? `https://test.ingame.qq.com/${store.state.global.game}/common/#/qa/share/${qid}`
        : `https://sy.qq.com/${store.state.global.game}/ingame/#/qa/share/${qid}`,
    shareImg: `https://tiem-cdn.qq.com/sy/${
      store.state.global.game
    }/ingame/images/${
      sessionStorage.igEnv === 'development' ? 'test_' : ''
    }qashare.png`,
    // 上报组件
    report({
      type,
      en,
      zh,
      targetid,
      action = 'pop',
      targettype = 'other',
      from = 'ingame',
    }) {
      console.log(type, en, zh)
      // mta.reportStat(en);
      targetid
        ? dmp.report({
            action,
            targetid,
            targettype,
            from,
          })
        : PTTSendClick(type, en, zh)
    },
  },
}
Vue.mixin({
  beforeCreate() {
    this.$qaCfg = slugQACfg
  },
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119