"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __spreadArrays = (this && this.__spreadArrays) || function () { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cookRichContent = exports.loginGrid = exports.getNodeRect = exports.checkVersionUpdate = exports.nextTick = exports.curry = exports.curryN = exports.getComponent = exports.doAfterLogin = exports.appLogin = exports.inputSync = exports.to = void 0; var rerquest_1 = require("../config/rerquest"); function to(promise) { return promise .then(function (data) { return [null, data]; }) .catch(function (err) { return [err]; }); } exports.to = to; function inputSync(event) { var value = event.detail.value, _a = event.currentTarget.dataset, name = _a.name, fm = _a.fm, subindex = _a.subindex, subindexname = _a.subindexname, maxlength = _a.maxlength, dataValue = _a.value; if (!name) { name = event.detail.name; fm = event.detail.fm; maxlength = event.detail.maxlength; } if (value == undefined && dataValue != undefined) { value = dataValue; } if (name) { if (maxlength) { value = value.substr(0, parseInt(maxlength)); } var fmKey = fm ? fm : "fmData"; var data = {}; data[fmKey] = this.data[fmKey]; if (subindex !== undefined && subindexname) { data[fmKey][name][subindex][subindexname] = value; } else { data[fmKey][name] = value; } if (typeof this.$beforeUpdateData === "function") { if (this.$beforeUpdateData(fmKey, name, value)) { this.setData(data); } else { return; } } else { this.setData(data); } if (typeof this.$afterUpdateData === "function") { this.$afterUpdateData(fmKey, name, value); } } } exports.inputSync = inputSync; function appLogin() { return __awaiter(this, void 0, void 0, function () { var app, _a, err, data; return __generator(this, function (_b) { switch (_b.label) { case 0: app = getApp(); return [4, to(app.login())]; case 1: _a = _b.sent(), err = _a[0], data = _a[1]; if (err) { console.error("登陆 app.login()函数报错", err); return [2, false]; } else { console.log("初始化登陆返回码", data); if (data === 1) { return [2, true]; } else { return [2, false]; } } return [2]; } }); }); } exports.appLogin = appLogin; function doAfterLogin() { return __awaiter(this, void 0, void 0, function () { var app; var _this = this; return __generator(this, function (_a) { app = getApp(); return [2, new Promise(function (reslove, reject) { return __awaiter(_this, void 0, void 0, function () { var i; return __generator(this, function (_a) { switch (_a.label) { case 0: i = 1; _a.label = 1; case 1: if (!(app.globalData.token == "" || app.globalData.gridId == "" || app.globalData.currentGridName == "")) return [3, 5]; i += 1; if (!(i == 10 || i == 100 || i == 250 || i == 600 || i % 3000 == 0)) return [3, 3]; return [4, appLogin()]; case 2: if (_a.sent()) { return [2, reslove()]; } _a.label = 3; case 3: return [4, exports.nextTick(100)]; case 4: _a.sent(); return [3, 1]; case 5: return [2, reslove()]; } }); }); })]; }); }); } exports.doAfterLogin = doAfterLogin; exports.getComponent = function (selector) { var ctx = getCurrentPages()[getCurrentPages().length - 1]; var componentCtx = ctx.selectComponent(selector); if (!componentCtx) { throw new Error("无法找到对应的组件,请按文档说明使用组件"); } return componentCtx; }; function curryN(fn, n) { if (n === void 0) { n = null; } var needLen = typeof n === "number" ? n : fn.length; function warp() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { arg[_i] = arguments[_i]; } var argLen = arg.length; if (needLen - argLen <= n) { return fn.apply(void 0, arg); } else { return function () { var newArg = []; for (var _i = 0; _i < arguments.length; _i++) { newArg[_i] = arguments[_i]; } return warp.apply(void 0, __spreadArrays(arg, newArg)); }; } } return warp; } exports.curryN = curryN; function curry(fn) { return curryN(fn); } exports.curry = curry; exports.nextTick = function (cd) { if (cd === void 0) { cd = 0; } return new Promise(function (reslove) { return setTimeout(reslove, cd); }); }; function checkVersionUpdate() { var updateManager = wx.getUpdateManager(); updateManager.onCheckForUpdate(function (res) { console.log(res.hasUpdate); }); updateManager.onUpdateReady(function () { wx.showModal({ title: "更新提示", content: "新版本已经准备好,是否重启应用?", success: function (res) { if (res.confirm) { updateManager.applyUpdate(); } }, }); }); updateManager.onUpdateFailed(function () { }); } exports.checkVersionUpdate = checkVersionUpdate; function getNodeRect(id, that) { if (that === void 0) { that = wx; } return new Promise(function (resolve) { that .createSelectorQuery() .select("#" + id) .boundingClientRect(function (rect) { resolve(rect); }) .exec(); }); } exports.getNodeRect = getNodeRect; function loginGrid() { return __awaiter(this, void 0, void 0, function () { var app, gid, cid; var _this = this; return __generator(this, function (_a) { app = getApp(); gid = app.globalData.gridId; cid = app.globalData.customerId; return [2, new Promise(function (reslove, reject) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, rerquest_1.default({ method: "POST", url: "resi/guide/user/entergrid", options: { customerId: cid, gridId: gid, }, ifToken: true, }).then(function (res) { console.log("重新进网格,更新数据"); wx.setStorageSync("userRoleList", res.data.userRoleList); wx.setStorageSync("gridName", res.data.currentGridName); app.globalData.userRoleList = res.data.userRoleList; app.globalData.currentGridName = res.data.currentGridName; app.globalData.userInfo.nickname = res.data.nickname; app.globalData.userInfo.userHeadPhoto = res.data.userHeadPhoto; app.globalData.gridId = gid; return reslove(); })]; }); }); })]; }); }); } exports.loginGrid = loginGrid; function cookRichContent(content) { if (content.startsWith("\n\n
\n\n\n") && content.endsWith("\n\n")) { content = content.slice(45, -16); } content = content .replace(/ /g, "\xa0") .replace(/