更新小程序仓库
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import logger from './logger'
|
||||
|
||||
// -----------------检测类型工具函数-----------------
|
||||
/**
|
||||
* 检测input类型是否为数组或者object
|
||||
* @param {*} input 任意类型的输入
|
||||
* @returns {Boolean} true->input is an array or an object
|
||||
*/
|
||||
export const isArrayOrObject = function (input) {
|
||||
return isArray(input) || isObject(input)
|
||||
}
|
||||
/**
|
||||
* 检测input是否为Error的实例
|
||||
* @param {*} input 任意类型的输入
|
||||
* @returns {Boolean} true->input is an instance of Error
|
||||
*/
|
||||
export const isInstanceOfError = function (input) {
|
||||
return (input instanceof Error)
|
||||
}
|
||||
|
||||
|
||||
// -----------------获取时间工具函数,计算耗时用-----------------
|
||||
|
||||
let baseTime = 0
|
||||
if (!Date.now) {
|
||||
Date.now = function now() {
|
||||
return new Date().getTime()
|
||||
}
|
||||
}
|
||||
|
||||
export const TimeUtil = {
|
||||
now() {
|
||||
if (baseTime === 0) {
|
||||
baseTime = Date.now() - 1
|
||||
}
|
||||
|
||||
const diff = Date.now() - baseTime
|
||||
if (diff > 0xffffffff) {
|
||||
baseTime += 0xffffffff
|
||||
return Date.now() - baseTime
|
||||
}
|
||||
return diff
|
||||
},
|
||||
|
||||
utc() {
|
||||
return Math.round(Date.now() / 1000)
|
||||
},
|
||||
}
|
||||
|
||||
// -----------------深度合并工具函数-----------------
|
||||
|
||||
|
||||
// -----------------其它-----------------
|
||||
/**
|
||||
* 序列化Error实例,只序列化Error实例的message和code属性(如果有的话)
|
||||
* @param {Error} error Error实例
|
||||
* @returns {String} 序列化后的内容
|
||||
*/
|
||||
export const stringifyError = function (error) {
|
||||
return JSON.stringify(error, ['message', 'code'])
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
export function caculateTimeago(dateTimeStamp) {
|
||||
const minute = 1000 * 60; // 把分,时,天,周,半个月,一个月用毫秒表示
|
||||
const hour = minute * 60;
|
||||
const day = hour * 24;
|
||||
const week = day * 7;
|
||||
const now = new Date().getTime(); // 获取当前时间毫秒
|
||||
const diffValue = now - dateTimeStamp;// 时间差
|
||||
let result = '';
|
||||
|
||||
if (diffValue < 0) {
|
||||
return;
|
||||
}
|
||||
const minC = diffValue / minute; // 计算时间差的分,时,天,周,月
|
||||
const hourC = diffValue / hour;
|
||||
const dayC = diffValue / day;
|
||||
const weekC = diffValue / week;
|
||||
if (weekC >= 1 && weekC <= 4) {
|
||||
result = ` ${parseInt(weekC, 10)}周前`;
|
||||
} else if (dayC >= 1 && dayC <= 6) {
|
||||
result = ` ${parseInt(dayC, 10)}天前`;
|
||||
} else if (hourC >= 1 && hourC <= 23) {
|
||||
result = ` ${parseInt(hourC, 10)}小时前`;
|
||||
} else if (minC >= 1 && minC <= 59) {
|
||||
result = ` ${parseInt(minC, 10)}分钟前`;
|
||||
} else if (diffValue >= 0 && diffValue <= minute) {
|
||||
result = '刚刚';
|
||||
} else {
|
||||
const datetime = new Date();
|
||||
datetime.setTime(dateTimeStamp);
|
||||
const Nyear = datetime.getFullYear();
|
||||
const Nmonth = datetime.getMonth() + 1 < 10 ? `0${datetime.getMonth() + 1}` : datetime.getMonth() + 1;
|
||||
const Ndate = datetime.getDate() < 10 ? `0${datetime.getDate()}` : datetime.getDate();
|
||||
result = `${Nyear}-${Nmonth}-${Ndate}`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
let _console; let method
|
||||
if (typeof console !== 'undefined') {
|
||||
_console = console
|
||||
} else if (typeof global !== 'undefined' && global.console) {
|
||||
_console = global.console
|
||||
} else if (typeof window !== 'undefined' && window.console) {
|
||||
_console = window.console
|
||||
} else {
|
||||
_console = {}
|
||||
}
|
||||
|
||||
const noop = function () {}
|
||||
const methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn']
|
||||
let { length } = methods
|
||||
|
||||
while (length--) {
|
||||
method = methods[length]
|
||||
|
||||
if (!console[method]) {
|
||||
_console[method] = noop
|
||||
}
|
||||
}
|
||||
|
||||
export default _console
|
||||
@@ -0,0 +1,47 @@
|
||||
const constant = {
|
||||
FEAT_NATIVE_CODE: {
|
||||
NATIVE_VERSION: 1,
|
||||
ISTYPING_STATUS: 1,
|
||||
NOTTYPING_STATUS: 1,
|
||||
ISTYPING_ACTION: 14,
|
||||
NOTTYPING_ACTION: 0,
|
||||
FEAT_TYPING: 1
|
||||
},
|
||||
TYPE_INPUT_STATUS_ING: 'EIMAMSG_InputStatus_Ing',
|
||||
TYPE_INPUT_STATUS_END: 'EIMAMSG_InputStatus_End',
|
||||
MESSAGE_TYPE_TEXT: {
|
||||
TIM_CUSTOM_ELEM: 'TIMCustomElem',
|
||||
},
|
||||
BUSINESS_ID_TEXT: {
|
||||
USER_TYPING: 'user_typing_status',
|
||||
EVALUATION: 'evaluation',
|
||||
ORDER: 'order',
|
||||
LINK: 'text_link',
|
||||
CREATE_GROUP: 'group_create',
|
||||
CONSULTION: 'consultion',
|
||||
},
|
||||
|
||||
STRING_TEXT: {
|
||||
TYPETYPING: '对方正在输入...',
|
||||
TYPETEXT: '对本次服务的评价',
|
||||
},
|
||||
MESSAGE_ERROR_CODE: {
|
||||
DIRTY_WORDS: 80001,
|
||||
UPLOAD_FAIL: 6008,
|
||||
REQUESTOR_TIME: 2081,
|
||||
DISCONNECT_NETWORK: 2800,
|
||||
DIRTY_MEDIA: 80004,
|
||||
},
|
||||
TOAST_TITLE_TEXT: {
|
||||
DIRTY_WORDS: '您发送的消息包含违禁词汇!',
|
||||
UPLOAD_FAIL: '文件上传失败!',
|
||||
CONNECT_ERROR: '网络已断开',
|
||||
DIRTY_MEDIA: '您发送的消息包含违禁内容!',
|
||||
RESEND_SUCCESS: '重发成功',
|
||||
},
|
||||
|
||||
OPERATING_ENVIRONMENT: 'imWxTuikit'
|
||||
};
|
||||
|
||||
|
||||
export default constant
|
||||
@@ -0,0 +1,120 @@
|
||||
!(function (t, e) {
|
||||
'object' === typeof exports && 'undefined' !== typeof module ? module.exports = e() : 'function' === typeof define && define.amd ? define(e) : (t = 'undefined' !== typeof globalThis ? globalThis : t || self).dayjs = e();
|
||||
}(this, (() => {
|
||||
'use strict';const t = 1e3; const e = 6e4; const n = 36e5; const r = 'millisecond'; const i = 'second'; const s = 'minute'; const u = 'hour'; const a = 'day'; const o = 'week'; const f = 'month'; const h = 'quarter'; const c = 'year'; const d = 'date'; const $ = 'Invalid Date'; const l = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/; const y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g; const M = { name: 'en', weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'), months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_') }; const m = function (t, e, n) {
|
||||
const r = String(t);return !r || r.length >= e ? t : `${Array(e + 1 - r.length).join(n)}${t}`;
|
||||
}; const g = { s: m, z(t) {
|
||||
const e = -t.utcOffset(); const n = Math.abs(e); const r = Math.floor(n / 60); const i = n % 60;return `${(e <= 0 ? '+' : '-') + m(r, 2, '0')}:${m(i, 2, '0')}`;
|
||||
}, m: function t(e, n) {
|
||||
if (e.date() < n.date()) return -t(n, e);const r = 12 * (n.year() - e.year()) + (n.month() - e.month()); const i = e.clone().add(r, f); const s = n - i < 0; const u = e.clone().add(r + (s ? -1 : 1), f);return +(-(r + (n - i) / (s ? i - u : u - i)) || 0);
|
||||
}, a(t) {
|
||||
return t < 0 ? Math.ceil(t) || 0 : Math.floor(t);
|
||||
}, p(t) {
|
||||
return { M: f, y: c, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: h }[t] || String(t || '').toLowerCase()
|
||||
.replace(/s$/, '');
|
||||
}, u(t) {
|
||||
return void 0 === t;
|
||||
} }; let D = 'en'; const v = {};v[D] = M;const p = function (t) {
|
||||
return t instanceof _;
|
||||
}; const S = function (t, e, n) {
|
||||
let r;if (!t) return D;if ('string' === typeof t)v[t] && (r = t), e && (v[t] = e, r = t);else {
|
||||
const i = t.name;v[i] = t, r = i;
|
||||
} return !n && r && (D = r), r || !n && D;
|
||||
}; const w = function (t, e) {
|
||||
if (p(t)) return t.clone();const n = 'object' === typeof e ? e : {};return n.date = t, n.args = arguments, new _(n);
|
||||
}; const O = g;O.l = S, O.i = p, O.w = function (t, e) {
|
||||
return w(t, { locale: e.$L, utc: e.$u, x: e.$x, $offset: e.$offset });
|
||||
};
|
||||
var _ = (function () {
|
||||
function M(t) {
|
||||
this.$L = S(t.locale, null, !0), this.parse(t);
|
||||
} const m = M.prototype;return m.parse = function (t) {
|
||||
this.$d = (function (t) {
|
||||
const e = t.date; const n = t.utc;if (null === e) return new Date(NaN);if (O.u(e)) return new Date;if (e instanceof Date) return new Date(e);if ('string' === typeof e && !/Z$/i.test(e)) {
|
||||
const r = e.match(l);if (r) {
|
||||
const i = r[2] - 1 || 0; const s = (r[7] || '0').substring(0, 3);return n ? new Date(Date.UTC(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s)) : new Date(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s);
|
||||
}
|
||||
} return new Date(e);
|
||||
}(t)), this.$x = t.x || {}, this.init();
|
||||
}, m.init = function () {
|
||||
const t = this.$d;this.$y = t.getFullYear(), this.$M = t.getMonth(), this.$D = t.getDate(), this.$W = t.getDay(), this.$H = t.getHours(), this.$m = t.getMinutes(), this.$s = t.getSeconds(), this.$ms = t.getMilliseconds();
|
||||
}, m.$utils = function () {
|
||||
return O;
|
||||
}, m.isValid = function () {
|
||||
return !(this.$d.toString() === $);
|
||||
}, m.isSame = function (t, e) {
|
||||
const n = w(t);return this.startOf(e) <= n && n <= this.endOf(e);
|
||||
}, m.isAfter = function (t, e) {
|
||||
return w(t) < this.startOf(e);
|
||||
}, m.isBefore = function (t, e) {
|
||||
return this.endOf(e) < w(t);
|
||||
}, m.$g = function (t, e, n) {
|
||||
return O.u(t) ? this[e] : this.set(n, t);
|
||||
}, m.unix = function () {
|
||||
return Math.floor(this.valueOf() / 1e3);
|
||||
}, m.valueOf = function () {
|
||||
return this.$d.getTime();
|
||||
}, m.startOf = function (t, e) {
|
||||
const n = this; const r = !!O.u(e) || e; const h = O.p(t); const $ = function (t, e) {
|
||||
const i = O.w(n.$u ? Date.UTC(n.$y, e, t) : new Date(n.$y, e, t), n);return r ? i : i.endOf(a);
|
||||
}; const l = function (t, e) {
|
||||
return O.w(n.toDate()[t].apply(n.toDate('s'), (r ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e)), n);
|
||||
}; const y = this.$W; const M = this.$M; const m = this.$D; const g = `set${this.$u ? 'UTC' : ''}`;switch (h) {
|
||||
// eslint-disable-next-line no-var
|
||||
case c:return r ? $(1, 0) : $(31, 11);case f:return r ? $(1, M) : $(0, M + 1);case o:var D = this.$locale().weekStart || 0; var v = (y < D ? y + 7 : y) - D;return $(r ? m - v : m + (6 - v), M);case a:case d:return l(`${g}Hours`, 0);case u:return l(`${g}Minutes`, 1);case s:return l(`${g}Seconds`, 2);case i:return l(`${g}Milliseconds`, 3);default:return this.clone();
|
||||
}
|
||||
}, m.endOf = function (t) {
|
||||
return this.startOf(t, !1);
|
||||
}, m.$set = function (t, e) {
|
||||
let n; const o = O.p(t); const h = `set${this.$u ? 'UTC' : ''}`; const $ = (n = {}, n[a] = `${h}Date`, n[d] = `${h}Date`, n[f] = `${h}Month`, n[c] = `${h}FullYear`, n[u] = `${h}Hours`, n[s] = `${h}Minutes`, n[i] = `${h}Seconds`, n[r] = `${h}Milliseconds`, n)[o]; const l = o === a ? this.$D + (e - this.$W) : e;if (o === f || o === c) {
|
||||
const y = this.clone().set(d, 1);y.$d[$](l), y.init(), this.$d = y.set(d, Math.min(this.$D, y.daysInMonth())).$d;
|
||||
} else $ && this.$d[$](l);return this.init(), this;
|
||||
}, m.set = function (t, e) {
|
||||
return this.clone().$set(t, e);
|
||||
}, m.get = function (t) {
|
||||
return this[O.p(t)]();
|
||||
}, m.add = function (r, h) {
|
||||
let d; const $ = this;r = Number(r);const l = O.p(h); const y = function (t) {
|
||||
const e = w($);return O.w(e.date(e.date() + Math.round(t * r)), $);
|
||||
};if (l === f) return this.set(f, this.$M + r);if (l === c) return this.set(c, this.$y + r);if (l === a) return y(1);if (l === o) return y(7);const M = (d = {}, d[s] = e, d[u] = n, d[i] = t, d)[l] || 1; const m = this.$d.getTime() + r * M;return O.w(m, this);
|
||||
}, m.subtract = function (t, e) {
|
||||
return this.add(-1 * t, e);
|
||||
}, m.format = function (t) {
|
||||
const e = this; const n = this.$locale();if (!this.isValid()) return n.invalidDate || $;const r = t || 'YYYY-MM-DDTHH:mm:ssZ'; const i = O.z(this); const s = this.$H; const u = this.$m; const a = this.$M; const o = n.weekdays; const f = n.months; const h = function (t, n, i, s) {
|
||||
return t && (t[n] || t(e, r)) || i[n].substr(0, s);
|
||||
}; const c = function (t) {
|
||||
return O.s(s % 12 || 12, t, '0');
|
||||
}; const d = n.meridiem || function (t, _e, n) {
|
||||
const r = t < 12 ? 'AM' : 'PM';return n ? r.toLowerCase() : r;
|
||||
}; const l = { YY: String(this.$y).slice(-2), YYYY: this.$y, M: a + 1, MM: O.s(a + 1, 2, '0'), MMM: h(n.monthsShort, a, f, 3), MMMM: h(f, a), D: this.$D, DD: O.s(this.$D, 2, '0'), d: String(this.$W), dd: h(n.weekdaysMin, this.$W, o, 2), ddd: h(n.weekdaysShort, this.$W, o, 3), dddd: o[this.$W], H: String(s), HH: O.s(s, 2, '0'), h: c(1), hh: c(2), a: d(s, u, !0), A: d(s, u, !1), m: String(u), mm: O.s(u, 2, '0'), s: String(this.$s), ss: O.s(this.$s, 2, '0'), SSS: O.s(this.$ms, 3, '0'), Z: i };return r.replace(y, ((t, e) => e || l[t] || i.replace(':', '')));
|
||||
}, m.utcOffset = function () {
|
||||
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
||||
}, m.diff = function (r, d, $) {
|
||||
let l; const y = O.p(d); const M = w(r); const m = (M.utcOffset() - this.utcOffset()) * e; const g = this - M; let D = O.m(this, M);return D = (l = {}, l[c] = D / 12, l[f] = D, l[h] = D / 3, l[o] = (g - m) / 6048e5, l[a] = (g - m) / 864e5, l[u] = g / n, l[s] = g / e, l[i] = g / t, l)[y] || g, $ ? D : O.a(D);
|
||||
}, m.daysInMonth = function () {
|
||||
return this.endOf(f).$D;
|
||||
}, m.$locale = function () {
|
||||
return v[this.$L];
|
||||
}, m.locale = function (t, e) {
|
||||
if (!t) return this.$L;const n = this.clone(); const r = S(t, e, !0);return r && (n.$L = r), n;
|
||||
}, m.clone = function () {
|
||||
return O.w(this.$d, this);
|
||||
}, m.toDate = function () {
|
||||
return new Date(this.valueOf());
|
||||
}, m.toJSON = function () {
|
||||
return this.isValid() ? this.toISOString() : null;
|
||||
}, m.toISOString = function () {
|
||||
return this.$d.toISOString();
|
||||
}, m.toString = function () {
|
||||
return this.$d.toUTCString();
|
||||
}, M;
|
||||
}()); const b = _.prototype;return w.prototype = b, [['$ms', r], ['$s', i], ['$m', s], ['$H', u], ['$W', a], ['$M', f], ['$y', c], ['$D', d]].forEach(((t) => {
|
||||
b[t[1]] = function (e) {
|
||||
return this.$g(e, t[0], t[1]);
|
||||
};
|
||||
})), w.extend = function (t, e) {
|
||||
return t.$i || (t(e, _, w), t.$i = !0), w;
|
||||
}, w.locale = S, w.isDayjs = p, w.unix = function (t) {
|
||||
return w(1e3 * t);
|
||||
}, w.en = v[D], w.Ls = v, w.p = {}, w;
|
||||
})));
|
||||
@@ -0,0 +1,286 @@
|
||||
export const emojiUrl = 'https://web.sdk.qcloud.com/im/assets/emoji/';
|
||||
export const emojiMap = {
|
||||
'[NO]': 'emoji_0@2x.png',
|
||||
'[OK]': 'emoji_1@2x.png',
|
||||
'[下雨]': 'emoji_2@2x.png',
|
||||
'[么么哒]': 'emoji_3@2x.png',
|
||||
'[乒乓]': 'emoji_4@2x.png',
|
||||
'[便便]': 'emoji_5@2x.png',
|
||||
'[信封]': 'emoji_6@2x.png',
|
||||
'[偷笑]': 'emoji_7@2x.png',
|
||||
'[傲慢]': 'emoji_8@2x.png',
|
||||
'[再见]': 'emoji_9@2x.png',
|
||||
'[冷汗]': 'emoji_10@2x.png',
|
||||
'[凋谢]': 'emoji_11@2x.png',
|
||||
'[刀]': 'emoji_12@2x.png',
|
||||
'[删除]': 'emoji_13@2x.png',
|
||||
'[勾引]': 'emoji_14@2x.png',
|
||||
'[发呆]': 'emoji_15@2x.png',
|
||||
'[发抖]': 'emoji_16@2x.png',
|
||||
'[可怜]': 'emoji_17@2x.png',
|
||||
'[可爱]': 'emoji_18@2x.png',
|
||||
'[右哼哼]': 'emoji_19@2x.png',
|
||||
'[右太极]': 'emoji_20@2x.png',
|
||||
'[右车头]': 'emoji_21@2x.png',
|
||||
'[吐]': 'emoji_22@2x.png',
|
||||
'[吓]': 'emoji_23@2x.png',
|
||||
'[咒骂]': 'emoji_24@2x.png',
|
||||
'[咖啡]': 'emoji_25@2x.png',
|
||||
'[啤酒]': 'emoji_26@2x.png',
|
||||
'[嘘]': 'emoji_27@2x.png',
|
||||
'[回头]': 'emoji_28@2x.png',
|
||||
'[困]': 'emoji_29@2x.png',
|
||||
'[坏笑]': 'emoji_30@2x.png',
|
||||
'[多云]': 'emoji_31@2x.png',
|
||||
'[大兵]': 'emoji_32@2x.png',
|
||||
'[大哭]': 'emoji_33@2x.png',
|
||||
'[太阳]': 'emoji_34@2x.png',
|
||||
'[奋斗]': 'emoji_35@2x.png',
|
||||
'[奶瓶]': 'emoji_36@2x.png',
|
||||
'[委屈]': 'emoji_37@2x.png',
|
||||
'[害羞]': 'emoji_38@2x.png',
|
||||
'[尴尬]': 'emoji_39@2x.png',
|
||||
'[左哼哼]': 'emoji_40@2x.png',
|
||||
'[左太极]': 'emoji_41@2x.png',
|
||||
'[左车头]': 'emoji_42@2x.png',
|
||||
'[差劲]': 'emoji_43@2x.png',
|
||||
'[弱]': 'emoji_44@2x.png',
|
||||
'[强]': 'emoji_45@2x.png',
|
||||
'[彩带]': 'emoji_46@2x.png',
|
||||
'[彩球]': 'emoji_47@2x.png',
|
||||
'[得意]': 'emoji_48@2x.png',
|
||||
'[微笑]': 'emoji_49@2x.png',
|
||||
'[心碎了]': 'emoji_50@2x.png',
|
||||
'[快哭了]': 'emoji_51@2x.png',
|
||||
'[怄火]': 'emoji_52@2x.png',
|
||||
'[怒]': 'emoji_53@2x.png',
|
||||
'[惊恐]': 'emoji_54@2x.png',
|
||||
'[惊讶]': 'emoji_55@2x.png',
|
||||
'[憨笑]': 'emoji_56@2x.png',
|
||||
'[手枪]': 'emoji_57@2x.png',
|
||||
'[打哈欠]': 'emoji_58@2x.png',
|
||||
'[抓狂]': 'emoji_59@2x.png',
|
||||
'[折磨]': 'emoji_60@2x.png',
|
||||
'[抠鼻]': 'emoji_61@2x.png',
|
||||
'[抱抱]': 'emoji_62@2x.png',
|
||||
'[抱拳]': 'emoji_63@2x.png',
|
||||
'[拳头]': 'emoji_64@2x.png',
|
||||
'[挥手]': 'emoji_65@2x.png',
|
||||
'[握手]': 'emoji_66@2x.png',
|
||||
'[撇嘴]': 'emoji_67@2x.png',
|
||||
'[擦汗]': 'emoji_68@2x.png',
|
||||
'[敲打]': 'emoji_69@2x.png',
|
||||
'[晕]': 'emoji_70@2x.png',
|
||||
'[月亮]': 'emoji_71@2x.png',
|
||||
'[棒棒糖]': 'emoji_72@2x.png',
|
||||
'[汽车]': 'emoji_73@2x.png',
|
||||
'[沙发]': 'emoji_74@2x.png',
|
||||
'[流汗]': 'emoji_75@2x.png',
|
||||
'[流泪]': 'emoji_76@2x.png',
|
||||
'[激动]': 'emoji_77@2x.png',
|
||||
'[灯泡]': 'emoji_78@2x.png',
|
||||
'[炸弹]': 'emoji_79@2x.png',
|
||||
'[熊猫]': 'emoji_80@2x.png',
|
||||
'[爆筋]': 'emoji_81@2x.png',
|
||||
'[爱你]': 'emoji_82@2x.png',
|
||||
'[爱心]': 'emoji_83@2x.png',
|
||||
'[爱情]': 'emoji_84@2x.png',
|
||||
'[猪头]': 'emoji_85@2x.png',
|
||||
'[猫咪]': 'emoji_86@2x.png',
|
||||
'[献吻]': 'emoji_87@2x.png',
|
||||
'[玫瑰]': 'emoji_88@2x.png',
|
||||
'[瓢虫]': 'emoji_89@2x.png',
|
||||
'[疑问]': 'emoji_90@2x.png',
|
||||
'[白眼]': 'emoji_91@2x.png',
|
||||
'[皮球]': 'emoji_92@2x.png',
|
||||
'[睡觉]': 'emoji_93@2x.png',
|
||||
'[磕头]': 'emoji_94@2x.png',
|
||||
'[示爱]': 'emoji_95@2x.png',
|
||||
'[礼品袋]': 'emoji_96@2x.png',
|
||||
'[礼物]': 'emoji_97@2x.png',
|
||||
'[篮球]': 'emoji_98@2x.png',
|
||||
'[米饭]': 'emoji_99@2x.png',
|
||||
'[糗大了]': 'emoji_100@2x.png',
|
||||
'[红双喜]': 'emoji_101@2x.png',
|
||||
'[红灯笼]': 'emoji_102@2x.png',
|
||||
'[纸巾]': 'emoji_103@2x.png',
|
||||
'[胜利]': 'emoji_104@2x.png',
|
||||
'[色]': 'emoji_105@2x.png',
|
||||
'[药]': 'emoji_106@2x.png',
|
||||
'[菜刀]': 'emoji_107@2x.png',
|
||||
'[蛋糕]': 'emoji_108@2x.png',
|
||||
'[蜡烛]': 'emoji_109@2x.png',
|
||||
'[街舞]': 'emoji_110@2x.png',
|
||||
'[衰]': 'emoji_111@2x.png',
|
||||
'[西瓜]': 'emoji_112@2x.png',
|
||||
'[调皮]': 'emoji_113@2x.png',
|
||||
'[象棋]': 'emoji_114@2x.png',
|
||||
'[跳绳]': 'emoji_115@2x.png',
|
||||
'[跳跳]': 'emoji_116@2x.png',
|
||||
'[车厢]': 'emoji_117@2x.png',
|
||||
'[转圈]': 'emoji_118@2x.png',
|
||||
'[鄙视]': 'emoji_119@2x.png',
|
||||
'[酷]': 'emoji_120@2x.png',
|
||||
'[钞票]': 'emoji_121@2x.png',
|
||||
'[钻戒]': 'emoji_122@2x.png',
|
||||
'[闪电]': 'emoji_123@2x.png',
|
||||
'[闭嘴]': 'emoji_124@2x.png',
|
||||
'[闹钟]': 'emoji_125@2x.png',
|
||||
'[阴险]': 'emoji_126@2x.png',
|
||||
'[难过]': 'emoji_127@2x.png',
|
||||
'[雨伞]': 'emoji_128@2x.png',
|
||||
'[青蛙]': 'emoji_129@2x.png',
|
||||
'[面条]': 'emoji_130@2x.png',
|
||||
'[鞭炮]': 'emoji_131@2x.png',
|
||||
'[风车]': 'emoji_132@2x.png',
|
||||
'[飞吻]': 'emoji_133@2x.png',
|
||||
'[飞机]': 'emoji_134@2x.png',
|
||||
'[饥饿]': 'emoji_135@2x.png',
|
||||
'[香蕉]': 'emoji_136@2x.png',
|
||||
'[骷髅]': 'emoji_137@2x.png',
|
||||
'[麦克风]': 'emoji_138@2x.png',
|
||||
'[麻将]': 'emoji_139@2x.png',
|
||||
'[鼓掌]': 'emoji_140@2x.png',
|
||||
'[龇牙]': 'emoji_141@2x.png',
|
||||
};
|
||||
export const emojiName = [
|
||||
'[龇牙]',
|
||||
'[调皮]',
|
||||
'[流汗]',
|
||||
'[偷笑]',
|
||||
'[再见]',
|
||||
'[敲打]',
|
||||
'[擦汗]',
|
||||
'[猪头]',
|
||||
'[玫瑰]',
|
||||
'[流泪]',
|
||||
'[大哭]',
|
||||
'[嘘]',
|
||||
'[酷]',
|
||||
'[抓狂]',
|
||||
'[委屈]',
|
||||
'[便便]',
|
||||
'[炸弹]',
|
||||
'[菜刀]',
|
||||
'[可爱]',
|
||||
'[色]',
|
||||
'[害羞]',
|
||||
'[得意]',
|
||||
'[吐]',
|
||||
'[微笑]',
|
||||
'[怒]',
|
||||
'[尴尬]',
|
||||
'[惊恐]',
|
||||
'[冷汗]',
|
||||
'[爱心]',
|
||||
'[示爱]',
|
||||
'[白眼]',
|
||||
'[傲慢]',
|
||||
'[难过]',
|
||||
'[惊讶]',
|
||||
'[疑问]',
|
||||
'[困]',
|
||||
'[么么哒]',
|
||||
'[憨笑]',
|
||||
'[爱情]',
|
||||
'[衰]',
|
||||
'[撇嘴]',
|
||||
'[阴险]',
|
||||
'[奋斗]',
|
||||
'[发呆]',
|
||||
'[右哼哼]',
|
||||
'[抱抱]',
|
||||
'[坏笑]',
|
||||
'[飞吻]',
|
||||
'[鄙视]',
|
||||
'[晕]',
|
||||
'[大兵]',
|
||||
'[可怜]',
|
||||
'[强]',
|
||||
'[弱]',
|
||||
'[握手]',
|
||||
'[胜利]',
|
||||
'[抱拳]',
|
||||
'[凋谢]',
|
||||
'[米饭]',
|
||||
'[蛋糕]',
|
||||
'[西瓜]',
|
||||
'[啤酒]',
|
||||
'[瓢虫]',
|
||||
'[勾引]',
|
||||
'[OK]',
|
||||
'[爱你]',
|
||||
'[咖啡]',
|
||||
'[月亮]',
|
||||
'[刀]',
|
||||
'[发抖]',
|
||||
'[差劲]',
|
||||
'[拳头]',
|
||||
'[心碎了]',
|
||||
'[太阳]',
|
||||
'[礼物]',
|
||||
'[皮球]',
|
||||
'[骷髅]',
|
||||
'[挥手]',
|
||||
'[闪电]',
|
||||
'[饥饿]',
|
||||
'[困]',
|
||||
'[咒骂]',
|
||||
'[折磨]',
|
||||
'[抠鼻]',
|
||||
'[鼓掌]',
|
||||
'[糗大了]',
|
||||
'[左哼哼]',
|
||||
'[打哈欠]',
|
||||
'[快哭了]',
|
||||
'[吓]',
|
||||
'[篮球]',
|
||||
'[乒乓]',
|
||||
'[NO]',
|
||||
'[跳跳]',
|
||||
'[怄火]',
|
||||
'[转圈]',
|
||||
'[磕头]',
|
||||
'[回头]',
|
||||
'[跳绳]',
|
||||
'[激动]',
|
||||
'[街舞]',
|
||||
'[献吻]',
|
||||
'[左太极]',
|
||||
'[右太极]',
|
||||
'[闭嘴]',
|
||||
'[猫咪]',
|
||||
'[红双喜]',
|
||||
'[鞭炮]',
|
||||
'[红灯笼]',
|
||||
'[麻将]',
|
||||
'[麦克风]',
|
||||
'[礼品袋]',
|
||||
'[信封]',
|
||||
'[象棋]',
|
||||
'[彩带]',
|
||||
'[蜡烛]',
|
||||
'[爆筋]',
|
||||
'[棒棒糖]',
|
||||
'[奶瓶]',
|
||||
'[面条]',
|
||||
'[香蕉]',
|
||||
'[飞机]',
|
||||
'[左车头]',
|
||||
'[车厢]',
|
||||
'[右车头]',
|
||||
'[多云]',
|
||||
'[下雨]',
|
||||
'[钞票]',
|
||||
'[熊猫]',
|
||||
'[灯泡]',
|
||||
'[风车]',
|
||||
'[闹钟]',
|
||||
'[雨伞]',
|
||||
'[彩球]',
|
||||
'[钻戒]',
|
||||
'[沙发]',
|
||||
'[纸巾]',
|
||||
'[手枪]',
|
||||
'[青蛙]',
|
||||
];
|
||||
@@ -0,0 +1,22 @@
|
||||
export default function formatTime(secondTime) {
|
||||
const time = secondTime
|
||||
let newTime; let hour; let minite; let seconds
|
||||
if (time >= 3600) {
|
||||
hour = parseInt(time / 3600) < 10 ? `0${parseInt(time / 3600)}` : parseInt(time / 3600)
|
||||
minite = parseInt(time % 60 / 60) < 10 ? `0${parseInt(time % 60 / 60)}` : parseInt(time % 60 / 60)
|
||||
seconds = time % 3600 < 10 ? `0${time % 3600}` : time % 3600
|
||||
if (seconds > 60) {
|
||||
minite = parseInt(seconds / 60) < 10 ? `0${parseInt(seconds / 60)}` : parseInt(seconds / 60)
|
||||
seconds = seconds % 60 < 10 ? `0${seconds % 60}` : seconds % 60
|
||||
}
|
||||
newTime = `${hour}:${minite}:${seconds}`
|
||||
} else if (time >= 60 && time < 3600) {
|
||||
minite = parseInt(time / 60) < 10 ? `0${parseInt(time / 60)}` : parseInt(time / 60)
|
||||
seconds = time % 60 < 10 ? `0${time % 60}` : time % 60
|
||||
newTime = `00:${minite}:${seconds}`
|
||||
} else if (time < 60) {
|
||||
seconds = time < 10 ? `0${time}` : time
|
||||
newTime = `00:00:${seconds}`
|
||||
}
|
||||
return newTime
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
import console from './console'
|
||||
import { isArrayOrObject, TimeUtil, isInstanceOfError, stringifyError } from './common-utils'
|
||||
|
||||
const LOGLEVEL_DEBUG = -1
|
||||
const LOGLEVEL_LOG = 0
|
||||
const LOGLEVEL_INFO = 1
|
||||
const LOGLEVEL_WARN = 2
|
||||
const LOGLEVEL_ERROR = 3
|
||||
const LOGLEVEL_NON_LOGGING = 4 // 无日志记录级别,sdk将不打印任何日志
|
||||
const MAX_LOG_LENGTH = 1000
|
||||
let globalLevel = LOGLEVEL_LOG
|
||||
// 暂停使用 wx.getLogManager,没发现它能起到什么作用
|
||||
const bCanIUseWxLog = false
|
||||
const timerMap = new Map()
|
||||
|
||||
/**
|
||||
* 对齐毫秒字符串
|
||||
* @param {*} ms 毫秒
|
||||
* @returns {String} 对齐后的毫秒时间字符串
|
||||
*/
|
||||
function padMs(ms) {
|
||||
const len = ms.toString().length
|
||||
let ret
|
||||
switch (len) {
|
||||
case 1:
|
||||
ret = `00${ms}`
|
||||
break
|
||||
case 2:
|
||||
ret = `0${ms}`
|
||||
break
|
||||
default:
|
||||
ret = ms
|
||||
break
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
* log前缀
|
||||
* @returns {String} 日志前缀
|
||||
*/
|
||||
function getPrefix() {
|
||||
const date = new Date()
|
||||
return `TUIKit ${date.toLocaleTimeString('en-US', { hour12: false })}.${padMs(date.getMilliseconds())}:`
|
||||
}
|
||||
|
||||
|
||||
|
||||
const logger = {
|
||||
_data: [],
|
||||
_length: 0,
|
||||
_visible: false,
|
||||
|
||||
// 将函数参数拼成字符串
|
||||
arguments2String(args) {
|
||||
let s
|
||||
if (args.length === 1) {
|
||||
s = getPrefix() + args[0]
|
||||
} else {
|
||||
s = getPrefix()
|
||||
for (let i = 0, { length } = args; i < length; i++) {
|
||||
if (isArrayOrObject(args[i])) {
|
||||
if (isInstanceOfError(args[i])) {
|
||||
s += stringifyError(args[i])
|
||||
} else {
|
||||
s += JSON.stringify(args[i])
|
||||
}
|
||||
} else {
|
||||
s += args[i]
|
||||
}
|
||||
s += ' '
|
||||
}
|
||||
}
|
||||
return s
|
||||
},
|
||||
|
||||
/**
|
||||
* 打印调试日志
|
||||
*/
|
||||
debug() {
|
||||
if (globalLevel <= LOGLEVEL_DEBUG) {
|
||||
// 对参数使用slice会阻止某些JavaScript引擎中的优化 (比如 V8 - 更多信息)
|
||||
// see:https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
|
||||
const s = this.arguments2String(arguments)
|
||||
logger.record(s, 'debug')
|
||||
console.debug(s)
|
||||
if (bCanIUseWxLog) {
|
||||
wx.getLogManager().debug(s)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 打印普通日志
|
||||
*/
|
||||
log() {
|
||||
if (globalLevel <= LOGLEVEL_LOG) {
|
||||
const s = this.arguments2String(arguments)
|
||||
logger.record(s, 'log')
|
||||
console.log(s)
|
||||
if (bCanIUseWxLog) {
|
||||
wx.getLogManager().log(s)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 打印release日志
|
||||
*/
|
||||
info() {
|
||||
if (globalLevel <= LOGLEVEL_INFO) {
|
||||
const s = this.arguments2String(arguments)
|
||||
logger.record(s, 'info')
|
||||
console.info(s)
|
||||
if (bCanIUseWxLog) {
|
||||
wx.getLogManager().info(s)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 打印告警日志
|
||||
*/
|
||||
warn() {
|
||||
if (globalLevel <= LOGLEVEL_WARN) {
|
||||
const s = this.arguments2String(arguments)
|
||||
logger.record(s, 'warn')
|
||||
console.warn(s)
|
||||
if (bCanIUseWxLog) {
|
||||
wx.getLogManager().warn(s)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 打印错误日志
|
||||
*/
|
||||
error() {
|
||||
if (globalLevel <= LOGLEVEL_ERROR) {
|
||||
const s = this.arguments2String(arguments)
|
||||
logger.record(s, 'error')
|
||||
console.error(s)
|
||||
// 微信写不了error日志,就用warn代替了
|
||||
if (bCanIUseWxLog) {
|
||||
wx.getLogManager().warn(s)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
time(label) {
|
||||
timerMap.set(label, TimeUtil.now())
|
||||
},
|
||||
|
||||
timeEnd(label) {
|
||||
if (timerMap.has(label)) {
|
||||
const cost = TimeUtil.now() - timerMap.get(label)
|
||||
timerMap.delete(label)
|
||||
return cost
|
||||
}
|
||||
console.warn(`未找到对应label: ${label}, 请在调用 logger.timeEnd 前,调用 logger.time`)
|
||||
return 0
|
||||
},
|
||||
|
||||
setLevel(newLevel) {
|
||||
if (newLevel < LOGLEVEL_NON_LOGGING) {
|
||||
console.log(`${getPrefix()} set level from ${globalLevel} to ${newLevel}`)
|
||||
}
|
||||
globalLevel = newLevel
|
||||
},
|
||||
|
||||
record(s, type) {
|
||||
if (bCanIUseWxLog) {
|
||||
// 小程序环境不在内存缓存日志
|
||||
return
|
||||
}
|
||||
|
||||
if (logger._length === MAX_LOG_LENGTH + 100) {
|
||||
logger._data.splice(0, 100)
|
||||
logger._length = MAX_LOG_LENGTH
|
||||
}
|
||||
logger._length++
|
||||
logger._data.push(`${s} [${type}] \n`)
|
||||
},
|
||||
|
||||
getLog() {
|
||||
return logger._data
|
||||
},
|
||||
}
|
||||
|
||||
export default logger
|
||||
@@ -0,0 +1,192 @@
|
||||
import { emojiMap, emojiUrl } from './emojiMap';
|
||||
/** 传入message.element(群系统消息SystemMessage,群提示消息GroupTip除外)
|
||||
* content = {
|
||||
* type: 'TIMTextElem',
|
||||
* content: {
|
||||
* text: 'AAA[龇牙]AAA[龇牙]AAA[龇牙AAA]'
|
||||
* }
|
||||
*}
|
||||
**/
|
||||
|
||||
// 群提示消息的含义 (opType)
|
||||
const GROUP_TIP_TYPE = {
|
||||
MEMBER_JOIN: 1,
|
||||
MEMBER_QUIT: 2,
|
||||
MEMBER_KICKED_OUT: 3,
|
||||
MEMBER_SET_ADMIN: 4, // 被设置为管理员
|
||||
MEMBER_CANCELED_ADMIN: 5, // 被取消管理员
|
||||
GROUP_INFO_MODIFIED: 6, // 修改群资料,转让群组为该类型,msgBody.msgGroupNewInfo.ownerAccount表示新群主的ID
|
||||
MEMBER_INFO_MODIFIED: 7, // 修改群成员信息
|
||||
};
|
||||
|
||||
// 解析小程序text, 表情信息也是[嘻嘻]文本
|
||||
export function parseText(message) {
|
||||
const renderDom = [];
|
||||
let temp = message.payload.text;
|
||||
let left = -1;
|
||||
let right = -1;
|
||||
while (temp !== '') {
|
||||
left = temp.indexOf('[');
|
||||
right = temp.indexOf(']');
|
||||
switch (left) {
|
||||
case 0:
|
||||
if (right === -1) {
|
||||
renderDom.push({
|
||||
name: 'span',
|
||||
text: temp,
|
||||
});
|
||||
temp = '';
|
||||
} else {
|
||||
const _emoji = temp.slice(0, right + 1);
|
||||
if (emojiMap[_emoji]) {
|
||||
renderDom.push({
|
||||
name: 'img',
|
||||
src: emojiUrl + emojiMap[_emoji],
|
||||
});
|
||||
temp = temp.substring(right + 1);
|
||||
} else {
|
||||
renderDom.push({
|
||||
name: 'span',
|
||||
text: '[',
|
||||
});
|
||||
temp = temp.slice(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
renderDom.push({
|
||||
name: 'span',
|
||||
text: temp,
|
||||
});
|
||||
temp = '';
|
||||
break;
|
||||
default:
|
||||
renderDom.push({
|
||||
name: 'span',
|
||||
text: temp.slice(0, left),
|
||||
});
|
||||
temp = temp.substring(left);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return renderDom;
|
||||
}
|
||||
// 解析群系统消息 operationType详情见 https://web.sdk.qcloud.com/im/doc/preview/Message.html#.GroupSystemNoticePayload
|
||||
export function parseGroupSystemNotice(message) {
|
||||
const { payload } = message;
|
||||
const groupName = payload.groupProfile.name || payload.groupProfile.groupID;
|
||||
const { groupID } = payload.groupProfile;
|
||||
let text;
|
||||
|
||||
switch (payload.operationType) {
|
||||
case 1:
|
||||
text = `${payload.operatorID} 申请加入群组:${groupName}(群ID:${groupID})`;
|
||||
break;
|
||||
case 2:
|
||||
text = `成功加入群组:${groupName} (群ID:${groupID})`;
|
||||
break;
|
||||
case 3:
|
||||
text = `申请加入群组:${groupName} (群ID:${groupID})被拒绝`;
|
||||
break;
|
||||
case 4:
|
||||
text = `被管理员${payload.operatorID}踢出群组:${groupName}(群ID:${groupID})`;
|
||||
break;
|
||||
case 5:
|
||||
text = `群:${groupName} (群ID:${groupID})已被${payload.operatorID}解散`;
|
||||
break;
|
||||
case 6:
|
||||
text = `我(用户ID:${payload.operatorID})成功创建群聊:${groupName}(群ID:${groupID})`;
|
||||
break;
|
||||
case 7:
|
||||
text = `用户ID:${payload.operatorID}邀请你加群:${groupName}(群ID:${groupID})`;
|
||||
break;
|
||||
case 8:
|
||||
text = `你退出群组:${groupName}(群ID:${groupID})`;
|
||||
break;
|
||||
case 9:
|
||||
text = `你被${payload.operatorID}设置为群:${groupName}(群ID:${groupID})的管理员`;
|
||||
break;
|
||||
case 10:
|
||||
text = `你被${payload.operatorID}撤销群:${groupName} (群ID:${groupID})的管理员身份`;
|
||||
break;
|
||||
case 255:
|
||||
text = `自定义群系统通知: ${payload.userDefinedField}`;
|
||||
break;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
// 解析群提示消息
|
||||
export function parseGroupTip(message) {
|
||||
const { payload } = message;
|
||||
const userName = message.nick || payload.userIDList.join(',');
|
||||
let tip;
|
||||
let user;
|
||||
switch (payload.operationType) {
|
||||
case GROUP_TIP_TYPE.MEMBER_JOIN:
|
||||
tip = `${userName} 加入群聊`;
|
||||
break;
|
||||
case GROUP_TIP_TYPE.MEMBER_QUIT:
|
||||
tip = `群成员退群:${userName}`;
|
||||
break;
|
||||
case GROUP_TIP_TYPE.MEMBER_KICKED_OUT:
|
||||
tip = `群成员被踢:${userName}`;
|
||||
break;
|
||||
case GROUP_TIP_TYPE.MEMBER_SET_ADMIN:
|
||||
tip = `${payload.operatorID}将 ${userName}设置为管理员`;
|
||||
break;
|
||||
case GROUP_TIP_TYPE.MEMBER_CANCELED_ADMIN:
|
||||
tip = `${payload.operatorID}将 ${userName}取消作为管理员`;
|
||||
break;
|
||||
case GROUP_TIP_TYPE.GROUP_INFO_MODIFIED:
|
||||
tip = '群资料修改';
|
||||
break;
|
||||
case GROUP_TIP_TYPE.MEMBER_INFO_MODIFIED:
|
||||
for (const member of payload.memberList) {
|
||||
if (member.muteTime > 0) {
|
||||
tip = `群成员:${member.userID}被禁言${member.muteTime}秒`;
|
||||
} else {
|
||||
tip = `群成员:${member.userID}被取消禁言`;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 256:
|
||||
user = message.nick || message.from;
|
||||
if (payload.text === '无应答') {
|
||||
user = payload.userIDList.join(',');
|
||||
}
|
||||
tip = payload.text === '结束群聊' ? '结束群聊' : `"${user}" ${payload.text}`;
|
||||
break;
|
||||
}
|
||||
return [{
|
||||
name: 'groupTip',
|
||||
text: tip,
|
||||
}];
|
||||
}
|
||||
|
||||
// 解析图片消息
|
||||
export function parseImage(message) {
|
||||
const renderDom = [{
|
||||
name: 'image',
|
||||
// 这里默认渲染的是 1080P 的图片
|
||||
src: message.payload.imageInfoArray[0].url,
|
||||
}];
|
||||
return renderDom;
|
||||
}
|
||||
// 解析视频消息
|
||||
export function parseVideo(message) {
|
||||
const renderDom = [{
|
||||
name: 'video',
|
||||
src: message.payload.videoUrl,
|
||||
}];
|
||||
return renderDom;
|
||||
}
|
||||
// 解析语音消息
|
||||
export function parseAudio(message) {
|
||||
const renderDom = [{
|
||||
name: 'audio',
|
||||
src: message.payload.url,
|
||||
second: message.payload.second === 0 ? 1 : message.payload.second,
|
||||
}];
|
||||
return renderDom;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
class TouchMoveItem {
|
||||
_staticHeight = 0
|
||||
_clientY = 0
|
||||
newHeight = 0
|
||||
_temp = 0
|
||||
_diff = 0
|
||||
_step = 80
|
||||
max = 630
|
||||
min = 480
|
||||
setBlockHeight(_staticHeight) {
|
||||
this._staticHeight = _staticHeight
|
||||
this.newHeight = _staticHeight
|
||||
}
|
||||
setMaxHeight(val) {
|
||||
this.max = val
|
||||
}
|
||||
setMinHeight(val) {
|
||||
this.min = val
|
||||
}
|
||||
// touch start
|
||||
initTouchY(clientY) {
|
||||
this._clientY = clientY
|
||||
}
|
||||
// touch move计算差值
|
||||
diff(clientY) {
|
||||
return clientY - this._clientY
|
||||
}
|
||||
// get new block hight
|
||||
updateHeight(clientY) {
|
||||
let diff = this.diff(clientY)
|
||||
this._diff = diff
|
||||
if (this.newHeight - diff >= this.min && this.newHeight - diff <= this.max) {
|
||||
this._temp = this.newHeight - diff
|
||||
} else {
|
||||
if (this.newHeight - diff < this.min) {
|
||||
this._temp = this.min
|
||||
}
|
||||
if (this.newHeight - diff > this.max) {
|
||||
this._temp = this.max
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return this._temp
|
||||
}
|
||||
// touch end
|
||||
touchEnd() {
|
||||
if (Math.abs(this._diff) > this._step) {
|
||||
if (this._diff > 0) {
|
||||
this.newHeight = this.min
|
||||
} else {
|
||||
this.newHeight = this.max
|
||||
}
|
||||
} else {
|
||||
this.newHeight = this.newHeight
|
||||
}
|
||||
}
|
||||
getStaticHeight() {
|
||||
return this._staticHeight
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default TouchMoveItem
|
||||
Reference in New Issue
Block a user