Skip to content

Commit

Permalink
[refactor] 使用ts重构项目,优化整体逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
hry committed Aug 24, 2022
1 parent 8f51496 commit 30b5cea
Show file tree
Hide file tree
Showing 149 changed files with 3,941 additions and 5,253 deletions.
22 changes: 11 additions & 11 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"presets": [
[
"es2015",
{
"modules": false
}
]
],
"plugins": [
"external-helpers"
]
"presets": [
[
"es2015",
{
"modules": false
}
]
],
"plugins": [
"external-helpers"
]
}
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ANS=WX
LIB=WeChat
LibVERSION=5.0.0
1 change: 1 addition & 0 deletions .eslintcache

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { defineConfig } = require('eslint-define-config');

module.exports = defineConfig({
root: true,
env: {
browser: true,
node: true,
es6: true
},
globals: {
wx: true,
Page: true,
App: true,
Component: true,
getCurrentPages: true
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {
"@typescript-eslint/no-this-alias": ["error", {
allowedNames: ['_this', 'self']
}],
"@typescript-eslint/no-explicit-any": ["off"]
},
});
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules/
package-lock.json
package-lock.json
.DS_Store
yarn.lock
89 changes: 34 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,54 @@
# [易观方舟](https://www.analysys.cn/) ans-wechat-sdk [![NPM version][npm-image]][npm-url] [![License](https://img.shields.io/github/license/analysys/ans-wechat-sdk.svg)](https://github.com/analysys/ans-wechat-sdk/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/analysys/ans-wechat-sdk.svg)](https://github.com/analysys/ans-wechat-sdk/releases)
# [易观方舟](https://www.analysys.cn/) asd-wechat-sdk [![NPM version][npm-image]][npm-url] [![License](https://img.shields.io/github/license/analysys/ans-wechat-sdk.svg)](https://github.com/analysys/ans-wechat-sdk/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/analysys/ans-wechat-sdk.svg)](https://github.com/analysys/ans-wechat-sdk/releases)

## 安装

$ npm install ans-wechat-sdk --save
```sh
$ npm install asd-wechat-sdk --save
```

## 微信小程序 SDK 基础说明

## wechat SDK 基础说明
+ 快速集成
#### 快速集成
##### 引入sdk模块并初始化
```js

// 非es6
var AnalysysAgent = require("ans-wechat-sdk");
// 小程序提供了加密模块 根据自己需要引入
var AnalysysEncryption = require('ans-wechat-sdk/sdk/AnalysysAgent_encryption.min.js');
// sdk 与 加密模块关联
AnalysysAgent.encrypt = AnalysysEncryption;
import AnalysysAgent from "asd-wechat-sdk"

// es6
import AnalysysAgent from "ans-wechat-sdk"
import AnalysysEncryption from 'ans-wechat-sdk/sdk/AnalysysAgent_encryption.min.js';
AnalysysAgent.encrypt = AnalysysEncryption;
// 引入加密模块(非必须)
import AnalysysEncryption from 'asd-wechat-sdk/dist/AnalysysAgent_encryption.min.js';
AnalysysAgent.encrypt = AnalysysEncryption;

//初始化
AnalysysAgent.init({
appkey: '',
uploadURL: ''
})
```

// wechat SDK 初始化
AnalysysAgent.appkey = "/*设置为实际APPKEY*/"
AnalysysAgent.uploadURL = "/*设置为实际地址*/"
AnalysysAgent.debugMode = 1
AnalysysAgent.autoProfile = false
AnalysysAgent.encryptType = 1
AnalysysAgent.allowTimeCheck = true
AnalysysAgent.maxDiffTimeInterval = 20
AnalysysAgent.autoTrack = true
##### 初始化参数说明



+ appkey(必须) 在网站获取的 AppKey
+ debugMode 设置调试模式:0 - 关闭调试模式(默认);1 - 开启调试模式,数据不入库;2 - 开启调试模式,数据入库
+ uploadURL(必须) 自定义上传地址
+ autoProfile 设置是否追踪新用户的首次属性:false - 不追踪新用户的首次属性;true - 追踪新用户的首次属性(默认)
+ encryptType 设置是否对上传数据加密:0 - 对上传数据不加密(默认);1 - 对上传数据进行AES 128位ECB加密;2 对上传数据进行AES 128位CBC加密
+ allowTimeCheck 设置是否开启时间校准:false(默认) - 关闭时间校准;true - 开启时间校准
+ maxDiffTimeInterval 设置最大时间校准分为:30s(默认) ,当设置的时间差值小于他,将不开启校准。否则将会进行时间校准。假如设置成为负值,将默认为 30s。
+ autoTrack 设置是否开启全埋点,false - 不开启全埋点\(默认\);true - 开启全埋点;开启全埋点将会上报所有绑定(支持tab、longtab、longpress)事件,并上报$user_click 事件,设置data-content为采集的 $element_content、data-type为采集的 $element_type、data-name为采集的$element_name、id为采集的$element_id。不设置采集不到。不支持系统方法包括生命周期事件的上报,如果要采集tabbar切换,务必在注册Page的时候注册OnTabItemTap方法,否则采集不到。

>微信小程序要手动上报启动事件。
App({
onShow : function( options ){
//设置微信小程序启动事件,并传输UTM等参数
AnalysysAgent.appStart(options)
}
});

// 注,各个页面调用API 要加上这个定义,直接引用
let AnalysysAgent = wx.AnalysysAgent
参数 | 是否必须| 类型 | 默认值 | 说明
--- | :--- | :--- | :--- | :---
appkey | 是 | string | - | 在网站获取的AppKey
uploadURL | 是 | string | - | 自定义上传地址
debugMode | 否 | number | 0 | 0: 关闭调试模式;1 - 开启调试模式,数据不入库;2 - 开启调试模式,数据入库
autoProfile | 否 | boolean | true | 设置是否追踪新用户的首次属性
encryptType | 否 | number | 0 | 设置是否对上传数据加密:0 - 对上传数据不加密(默认);1 - 对上传数据进行AES 128位ECB加密;2 对上传数据进行AES 128位CBC加密
allowTimeCheck | 否 | boolean | false | 设置是否开启时间校准
maxDiffTimeInterval | 否 | number | 30 | 设置最大时间校准分为:30s(默认) ,当设置的时间差值小于他,将不开启校准。否则将会进行时间校准。假如设置成为负值,将默认为 30s。
autoTrack | 否 | boolean | false | 设置是否开启全埋点,开启全埋点将会上报所有绑定(支持tab、longtab、longpress)事件,并上报$user_click 事件,设置data-content为采集的 $element_content、data-type为采集的 $element_type、data-name为采集的$element_name、id为采集的$element_id。不设置采集不到。不支持系统方法包括生命周期事件的上报,如果要采集tabbar切换,务必在注册Page的时候注册OnTabItemTap方法,否则采集不到。
autoCompleteURL | 否 | boolean | true | 设置是否采集完整URL,true - 采集URL包括参数;false - 采集URL不包括参数
autoPageViewDuration | 否 | boolean | false | 是否采集页面离开事件

> 通过以上步骤您即可验证SDK是否已经集成成功,更多Api使用方法参考:[易观方舟 wechat SDK 文档](https://docs.analysys.cn/ark/integration/sdk/wx/wxsdkcustom)
> 注意 SDK 可能不完全向前兼容,请查看版本更新说明 [Release及版本升级记录](https://github.com/analysys/ans-wechat-sdk/releases)。如果有说明不兼容的话,需要升级易观方舟对应的版本。 请根据需要前往 [Release](https://github.com/analysys/ans-wechat-sdk/releases) 里下载对应的文件
> npm 安装适用于框架版小程序,基础版和插件版原生开发的小程序使用详见:[易观方舟 wechat SDK 文档](https://docs.analysys.cn/ark/integration/sdk/wx)

## 版本升级记录
请参见 [Release及版本升级记录](https://github.com/analysys/ans-wechat-sdk/releases)



## 讨论
+ 微信号:nlfxwz
+ 钉钉群:30099866
+ 邮箱:[email protected]


**禁止一切基于易观方舟 wechat 开源 SDK 的所有商业活动!**
Expand All @@ -82,7 +61,7 @@


[homepage]: https://github.com/analysys/ans-wechat-sdk
[npm-url]: https://www.npmjs.com/package/ans-wechat-sdk
[npm-image]: https://img.shields.io/npm/v/ans-wechat-sdk.svg?style=flat
[npm-downloads]: https://img.shields.io/npm/dm/ans-wechat-sdk.svg?style=flat
[npm-url]: https://www.npmjs.com/package/asd-wechat-sdk
[npm-image]: https://img.shields.io/npm/v/asd-wechat-sdk.svg?style=flat
[npm-downloads]: https://img.shields.io/npm/dm/asd-wechat-sdk.svg?style=flat

1 change: 0 additions & 1 deletion SDK/AnalysysAgent_WX_SDK.custom.es6.min.js

This file was deleted.

1 change: 0 additions & 1 deletion SDK/AnalysysAgent_WX_SDK.custom.min.js

This file was deleted.

1 change: 0 additions & 1 deletion SDK/AnalysysAgent_WX_SDK.es6.min.js

This file was deleted.

1 change: 0 additions & 1 deletion SDK/AnalysysAgent_WX_SDK.min.js

This file was deleted.

1 change: 0 additions & 1 deletion SDK/AnalysysAgent_WX_SDK.plugin.es6.min.js

This file was deleted.

1 change: 0 additions & 1 deletion SDK/AnalysysAgent_WX_SDK.plugin.min.js

This file was deleted.

148 changes: 87 additions & 61 deletions demo/demo/app.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,100 @@
//app.js
let AnalysysAgent = require("./sdk/AnalysysAgent_WX_SDK.min.js") //基础版本 sdk
let AnalysysEncryption = require("./sdk/AnalysysAgent_encryption.min.js") //加密板块,目前与sdk分开,为了缩小sdk的体积。需要的话单独引入。
AnalysysAgent.encrypt = AnalysysEncryption;
// let AnalysysAgent = require('./sdk/AnalysysAgent_WX_SDK.min.js') //基础版本 sdk
let AnalysysEncryption = require('./sdk/AnalysysAgent_encryption.min.js') //加密板块,目前与sdk分开,为了缩小sdk的体积。需要的话单独引入。
AnalysysAgent.encrypt = AnalysysEncryption

// es6 版本
// import AnalysysAgent from './sdk/AnalysysAgent_WX_SDK.es6.min.js';
// import * as AnalysysEncryption from './sdk/AnalysysAgent_encryption.es6.min.js';
// AnalysysAgent.encrypt = AnalysysEncryption; //加密模块的方法赋值给AnalysysAgent,方便调用。
import AnalysysAgent from './sdk/AnalysysAgent_WX_SDK.es6.min.js';

AnalysysAgent.debugMode = 2
AnalysysAgent.appkey = 'sdktest201'
AnalysysAgent.uploadURL = 'https://arkpaastest.analxysys.cn:4089'
AnalysysAgent.encryptType = 1; //使用加密文件的时候 放开赋值。(直接放开不会报错)
AnalysysAgent.autoShare = true;
// AnalysysAgent.autoProfile = false;
AnalysysAgent.auto = true;
AnalysysAgent.allowTimeCheck = true;
AnalysysAgent.maxDiffTimeInterval = 0;
AnalysysAgent.autoTrack = true;
AnalysysAgent.autoCompleteURL = false;

AnalysysAgent.alias('abc')

// AnalysysAgent.debugMode = 2
// AnalysysAgent.appkey = '2d01eb66efd95d2c'
// AnalysysAgent.uploadURL = 'https://uba-up.analysysdata.com'
// AnalysysAgent.encryptType = 1 //使用加密文件的时候 放开赋值。(直接放开不会报错)
// AnalysysAgent.autoShare = true
// AnalysysAgent.auto = true
// AnalysysAgent.allowTimeCheck = true
// AnalysysAgent.autoPageViewDuration = true
// AnalysysAgent.autoTrack = true
// AnalysysAgent.$appname = 'test_appname'
// AnalysysAgent.$appid = 'test_app_id'

// AnalysysAgent.registerSuperProperties({})
AnalysysAgent.init({
appkey: '2d01eb66efd95d2c',
uploadURL: 'https://uba-up.analysysdata.com',
debugMode: 2,
$appname: 'test_appname',
$appid: 'test_app_id',
autoShare: false
})

// console.log(AnalysysAgent.registerSuperProperties)
AnalysysAgent.registerSuperProperty('sfsf', 1)

AnalysysAgent.onReady = function(config) {
console.log('sdk已准备就绪')
}

AnalysysAgent.onBeforeStartUp = function (res) {
console.log('开始发送预制启动事件')
console.log(res)
}
AnalysysAgent.onAfterStartUp = function (res) {
console.log('预制启动事件发送成功')
console.log(res)
}

// AnalysysAgent.alias('abc')

// AnalysysAgent.registerSuperProperties({})

// console.log(AnalysysAgent.registerSuperProperties)

App({
onLaunch: function (options) {
AnalysysAgent.registerSuperProperty('cc', 9999)
AnalysysAgent.identify("identy1111111", false)
// AnalysysAgent.alias("1")
// AnalysysAgent.pageProperty({'page1':'property1'})
AnalysysAgent.pageView('hhhhhhhhhhh')
// console.log('APP---onLaunch--->', options)
if (options.shareTicket) {
wx.getShareInfo({
shareTicket: options.shareTicket,
success: function (res) {
//解密res.encryptedDat
// AnalysysAgent.appProperty({ 'openGId': 123256465 })
}
})
}
},
onShow: function (options) {
// console.log('APP---onShow--->', options)
// AnalysysAgent.appStart(options)
// if (options.shareTicket) {
// wx.getShareInfo({
// shareTicket: options.shareTicket,
// success: function (res) {
// //解密res.encryptedDat
// console.log('获取成功--->', res)
// // AnalysysAgent.appProperty({ 'openGId': 123256465 })
// }
// })
// }
AnalysysAgent.profileAppend("Movies", "霸王别姬")
let profies = {
"age": 20,
"integral": 200
}
AnalysysAgent.profileIncrement(profies)
},
globalData: {
userInfo: null
onLaunch: function(options) {

// AnalysysAgent.identify('identy1111111', false)
// AnalysysAgent.alias("1")
// AnalysysAgent.pageProperty({'page1':'property1'})

// AnalysysAgent.pageView('test', {username: 'hry'})

// console.log('APP---onLaunch--->', options)
if (options.shareTicket) {
wx.getShareInfo({
shareTicket: options.shareTicket,
success: function(res) {
//解密res.encryptedDat
// AnalysysAgent.appProperty({ 'openGId': 123256465 })
},
})
}
})
},
onShow: function(options) {
console.log('onshow+111')
// console.log('APP---onShow--->', options)
// AnalysysAgent.appStart(options)
// if (options.shareTicket) {
// wx.getShareInfo({
// shareTicket: options.shareTicket,
// success: function (res) {
// //解密res.encryptedDat
// console.log('获取成功--->', res)
// // AnalysysAgent.appProperty({ 'openGId': 123256465 })
// }
// })
// }

// AnalysysAgent.profileAppend('Movies', '霸王别姬')
// let profies = {
// age: 20,
// integral: 200,
// }
// AnalysysAgent.profileIncrement(profies)
},
onHide: function () {
console.log('onhide+2222')
},
globalData: {
userInfo: null,
},
})
12 changes: 11 additions & 1 deletion demo/demo/app.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs"
"pages/logs/logs",
"pages/my/index"
],
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页"
}, {
"pagePath": "pages/my/index",
"text": "我的"
}]
},
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
Expand Down
Loading

0 comments on commit 30b5cea

Please sign in to comment.