Selaa lähdekoodia

feat: 添加外部依赖支持,支持手动初始化、自定义配置项

zhangyuhan 2 vuotta sitten
vanhempi
commit
7d5d8a2cb3
2 muutettua tiedostoa jossa 15 lisäystä ja 3 poistoa
  1. 11 2
      src/easy-use-track.js
  2. 4 1
      src/index.js

+ 11 - 2
src/easy-use-track.js

@@ -10,8 +10,17 @@ import {getPlatform, loadJS} from './module/utils'
 
 
 class EasyUse {
 class EasyUse {
   constructor(options = {}) {
   constructor(options = {}) {
+
+    // 默认配置文件、版本号读取
+    const dataSoucre = `/common-module/track/json/${getPlatform() === 'PC' ? 'pc' : 'mobile'}.json`
+    let version = ''
+    if (window.goTemplateData && window.goTemplateData.version) {
+      version = window.goTemplateData.version
+    }
+
     this.config = Object.assign({
     this.config = Object.assign({
-      dataSource: '/common-module/track/json/pc.json'
+      dataSoucre,
+      version
     }, options)
     }, options)
     this.json = []
     this.json = []
     this.params = {}
     this.params = {}
@@ -179,7 +188,7 @@ class EasyUse {
    * 获取页面数据集
    * 获取页面数据集
    */
    */
   getDataJSON() {
   getDataJSON() {
-    this.getJSON(this.config.dataSource, (data) => {
+    this.getJSON(`${this.config.dataSource}${this.config.version ? ('?v=' + this.config.version) : ''}`, (data) => {
       if (Array.isArray(data)) {
       if (Array.isArray(data)) {
         this.json = [].concat(data)
         this.json = [].concat(data)
         this.upPageInfo()
         this.upPageInfo()

+ 4 - 1
src/index.js

@@ -1,9 +1,12 @@
 import EasyUse from './easy-use-track'
 import EasyUse from './easy-use-track'
 
 
 ;(function () {
 ;(function () {
+  // 支持手动初始化
   const skipInit = window._skip_easy_track_init || false
   const skipInit = window._skip_easy_track_init || false
   if (!skipInit) {
   if (!skipInit) {
-    new EasyUse()
+    // 支持自定义配置
+    const config = window._easy_track_config || {}
+    new EasyUse(Object.assign({}, config))
   }
   }
 })();
 })();