@tnwx/commons
Version:
TTNWX 微信系开发脚手架之公共模块
110 lines • 2.5 kB
JavaScript
"use strict";
/**
* @author Javen
* @copyright javendev@126.com
* @description 模板消息数据
*/
Object.defineProperty(exports, "__esModule", { value: true });
class TemplateData {
New() {
this.data = new Map();
this.miniprogram = new MiniProgram();
return this;
}
get getToUser() {
return this.touser;
}
setToUser(touser) {
this.touser = touser;
return this;
}
get getTemplateId() {
return this.template_id;
}
setTemplateId(templateId) {
this.template_id = templateId;
return this;
}
get getTemplateUrl() {
return this.url;
}
setTemplateUrl(url) {
this.url = url;
return this;
}
get getMiniProgram() {
return this.miniprogram;
}
setMiniProgram(miniprogram) {
this.miniprogram = miniprogram;
return this;
}
add(key, value, color) {
this.data.set(key, new TemplateItem(value, color));
return this;
}
build() {
let temp = {
touser: this.touser,
template_id: this.template_id,
url: this.url,
miniprogram: this.miniprogram,
data: this._mapToObj(this.data)
};
return JSON.stringify(temp);
}
_mapToObj(map) {
let obj = Object.create(null);
for (let [k, v] of map) {
obj[k] = v;
}
return obj;
}
_objToMap(obj) {
let strMap = new Map();
for (let k of Object.keys(obj)) {
strMap.set(k, obj[k]);
}
return strMap;
}
}
exports.TemplateData = TemplateData;
class MiniProgram {
constructor(appId, pagePath) {
this.appid = appId || '';
this.pagepath = pagePath || '';
}
get getAppId() {
return this.appid;
}
set setAppId(appid) {
this.appid = appid;
}
get getPagePath() {
return this.pagepath;
}
set getPagePath(pagepath) {
this.pagepath = pagepath;
}
}
exports.MiniProgram = MiniProgram;
class TemplateItem {
constructor(value, color) {
this.value = value;
this.color = color;
}
get getValue() {
return this.value;
}
set setValue(value) {
this.value = value;
}
get getColor() {
return this.color;
}
set setColor(color) {
this.color = color;
}
}
exports.TemplateItem = TemplateItem;
//# sourceMappingURL=TemplateData.js.map