ngx-bit
Version:
A flexible NG-ZORRO helper library
1,110 lines (1,093 loc) • 46.6 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('ng-zorro-antd/i18n'), require('@angular/common'), require('rxjs'), require('@angular/common/http'), require('@ngx-pwa/local-storage'), require('rxjs/operators'), require('@ngx-pwa/local-storage/public-api'), require('ng-zorro-antd/icon')) :
typeof define === 'function' && define.amd ? define('ngx-bit', ['exports', '@angular/core', '@angular/router', 'ng-zorro-antd/i18n', '@angular/common', 'rxjs', '@angular/common/http', '@ngx-pwa/local-storage', 'rxjs/operators', '@ngx-pwa/local-storage/public-api', 'ng-zorro-antd/icon'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-bit'] = {}, global.ng.core, global.ng.router, global.i6, global.ng.common, global.rxjs, global.ng.common.http, global.localStorage$1, global.rxjs.operators, global.i3, global.icon));
}(this, (function (exports, i0, i4, i6, i5, rxjs, i2, localStorage$1, operators, i3, icon) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var i4__namespace = /*#__PURE__*/_interopNamespace(i4);
var i6__namespace = /*#__PURE__*/_interopNamespace(i6);
var i5__namespace = /*#__PURE__*/_interopNamespace(i5);
var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
var BitConfig = /** @class */ (function () {
function BitConfig() {
}
return BitConfig;
}());
BitConfig.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function BitConfig_Factory() { return new BitConfig(); }, token: BitConfig, providedIn: "root" });
BitConfig.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(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());
});
}
function __generator(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 __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
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;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || from);
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
var ListByPage = /** @class */ (function () {
function ListByPage(curd, storage, option) {
var _this = this;
this.curd = curd;
this.storage = storage;
this.option = option;
/**
* 完成初始化
* Complete initialization
*/
this.ready = new rxjs.AsyncSubject();
/**
* 搜索字段定义
* Search field definition
*/
this.search = {};
/**
* 分页数据
* Paging data
*/
this.data = [];
/**
* 加载状态
* Loading status
*/
this.loading = true;
/**
* 分页限制
* Paging limit
*/
this.limit = 0;
/**
* 分页总数
* Total number of pages
*/
this.totals = 0;
/**
* 分页页码
* Pagination page number
*/
this.index = 1;
/**
* 是否全被选中
* Are all selected
*/
this.checked = false;
/**
* 是否不完全被选中
* Is it not completely selected
*/
this.indeterminate = false;
/**
* 是否可进行批量处理
* Whether it can be batch processed
*/
this.batch = false;
/**
* 被选中的数量
* Number selected
*/
this.checkedNumber = 0;
this.limit = option.limit;
this.order = option.order;
this.storage.get('search:' + option.id).subscribe(function (data) {
var e_1, _a;
if (!data) {
try {
for (var _b = __values(option.query), _c = _b.next(); !_c.done; _c = _b.next()) {
var value = _c.value;
_this.search[value.field] = value;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}
else {
_this.search = data;
}
_this.ready.next(data);
_this.ready.complete();
});
}
/**
* 设置数据
* Set data
*/
ListByPage.prototype.setData = function (data) {
this.data = data;
};
/**
* 判断是否包含该字段的搜索条件
* Determine whether to include the search criteria of the field
*/
ListByPage.prototype.hasSearch = function (field) {
return this.search.hasOwnProperty(field);
};
/**
* 主动触发搜索变动之后
* After actively triggering the search change
*/
ListByPage.prototype.afterSearch = function () {
return this.storage.set('search:' + this.option.id, this.search);
};
/**
* 主动触发搜索清空之后
* After actively triggering search and clearing
*/
ListByPage.prototype.clearSearch = function (reset) {
if (reset === void 0) { reset = {}; }
for (var key in this.search) {
if (this.search.hasOwnProperty(key)) {
var search = this.search[key];
if (reset.hasOwnProperty(search.field)) {
search.value = reset[search.field];
}
else {
search.value = '';
}
}
}
return this.storage.delete('search:' + this.option.id);
};
/**
* 更新分页列表状态
* Update the status of the paging list
*/
ListByPage.prototype.refreshStatus = function () {
var allChecked = this.data.every(function (value) { return value.checked === true; });
var allUnchecked = this.data.every(function (value) { return !value.checked; });
this.checked = this.data.length !== 0 && allChecked;
this.indeterminate = !allChecked && !allUnchecked;
this.batch = this.checked || this.indeterminate;
this.checkedNumber = this.data.filter(function (value) { return value.checked; }).length;
};
/**
* 更改所有分页列表选中状态
* Change the selected state of all tabbed lists
*/
ListByPage.prototype.checkedAll = function (event) {
this.data.forEach(function (data) { return (data.checked = event); });
this.refreshStatus();
};
/**
* 返回所有被选中的列表
* Return all selected lists
*/
ListByPage.prototype.getChecked = function () {
return this.data.filter(function (value) { return value.checked; });
};
/**
* 获取当前的页码
* Get the current page number
*/
ListByPage.prototype.getPage = function () {
return this.storage.get('page:' + this.option.id);
};
/**
* 主动执行分页页码的持久化记录
* Actively execute persistent records of paging page numbers
*/
ListByPage.prototype.persistence = function () {
this.storage.set('page:' + this.option.id, this.index).subscribe(function (_) { return _; });
};
/**
* 返回查询定义数组
* Return query definition array
*/
ListByPage.prototype.toQuery = function () {
return Object.values(this.search);
};
/**
* 返回查询语句
* Return query statement
*/
ListByPage.prototype.toQuerySchema = function () {
return this.curd.getQuerySchema(this.toQuery());
};
return ListByPage;
}());
var BitHttpService = /** @class */ (function () {
function BitHttpService(bitConfig, http) {
this.http = http;
this.baseUri = bitConfig.url.api + bitConfig.api.namespace + '/';
this.withCredentials = bitConfig.api.withCredentials;
}
/**
* 设置请求拦截器
* Http interceptor
*/
BitHttpService.prototype.setupInterceptor = function (operate) {
this.interceptor = operate;
};
/**
* 发起请求客户端
* Http client
*/
BitHttpService.prototype.req = function (url, body, method) {
if (body === void 0) { body = {}; }
if (method === void 0) { method = 'post'; }
var httpClient = this.http.request(method, this.baseUri + url, {
body: body,
withCredentials: this.withCredentials
});
if (this.interceptor) {
httpClient = httpClient.pipe(this.interceptor);
}
return httpClient;
};
return BitHttpService;
}());
BitHttpService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function BitHttpService_Factory() { return new BitHttpService(i0__namespace.ɵɵinject(BitConfig), i0__namespace.ɵɵinject(i2__namespace.HttpClient)); }, token: BitHttpService, providedIn: "root" });
BitHttpService.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
BitHttpService.ctorParameters = function () { return [
{ type: BitConfig },
{ type: i2.HttpClient }
]; };
var BitCurdService = /** @class */ (function () {
function BitCurdService(bitConfig, http) {
this.http = http;
this.mode = bitConfig.query;
this.curd = bitConfig.curd;
}
/**
* 获取查询语句
* Get query statement
*/
BitCurdService.prototype.getQuerySchema = function (options) {
switch (this.mode) {
case 'sql-orm':
return this.common(options);
}
};
/**
* mode: sql-orm
* php: Laravel ORM(Laravel,Lumen,Hyperf), ThinkPHP ORM
* - https://github.com/kainonly/think-bit
* - https://github.com/kainonly/hyperf-curd
* golang: https://github.com/kainonly/gin-curd
*/
BitCurdService.prototype.common = function (options) {
var e_1, _a;
var schema = [];
try {
for (var options_1 = __values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) {
var search = options_1_1.value;
if (search.value !== null &&
typeof search.value === 'object' &&
Object.keys(search.value).length === 0) {
continue;
}
if (typeof search.value === 'string') {
search.value = search.value.trim();
}
var exclude = search.exclude ? search.exclude : ['', 0, null];
if (!exclude.includes(search.value)) {
var value = search.value;
if (search.op === 'like') {
value = "%" + value + "%";
}
if (search.format !== undefined && search.format === 'unixtime') {
value = Array.isArray(value) ?
value.map(function (v) { return Math.trunc(v.getTime() / 1000); }) : Math.trunc(value.getTime() / 1000);
}
schema.push([search.field, search.op, value]);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (options_1_1 && !options_1_1.done && (_a = options_1.return)) _a.call(options_1);
}
finally { if (e_1) throw e_1.error; }
}
return schema;
};
return BitCurdService;
}());
BitCurdService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function BitCurdService_Factory() { return new BitCurdService(i0__namespace.ɵɵinject(BitConfig), i0__namespace.ɵɵinject(BitHttpService)); }, token: BitCurdService, providedIn: "root" });
BitCurdService.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
BitCurdService.ctorParameters = function () { return [
{ type: BitConfig },
{ type: BitHttpService }
]; };
var BitService = /** @class */ (function () {
function BitService(bitConfig, curd, storage, router, location, nzI18nService) {
this.curd = curd;
this.storage = storage;
this.router = router;
this.location = location;
this.nzI18nService = nzI18nService;
/**
* 公共语言包
* Common language pack
*/
this.language = new Map();
/**
* 语言包 ID 状态
* Language ID changed
*/
this.localeChanged = new rxjs.Subject();
/**
* 语言包引用
* Language pack reference
*/
this.l = {};
/**
* 国际化 ID 状态
* I18n ID changed
*/
this.i18nChanged = new rxjs.Subject();
/**
* 国际化包含语言 ID
* I18n includes languages ID
*/
this.i18nContain = [];
/**
* 国际化输入提示状态
* I18n tooltip status
*/
this.i18nTooltip = {};
this.static = bitConfig.url.static;
this.uploads = bitConfig.url.api + bitConfig.api.upload;
this.localeDefault = bitConfig.locale.default;
this.localeMapping = bitConfig.locale.mapping;
this.localeBind = bitConfig.locale.bind;
this.i18nDefault = bitConfig.i18n.default;
this.i18n = bitConfig.i18n.default;
this.i18nContain = bitConfig.i18n.contain;
this.i18nSwitch = bitConfig.i18n.switch;
this.pageDefault = bitConfig.page;
}
/**
* 路由导航
* Route navigation
*/
BitService.prototype.open = function (path, extras) {
if (path.length === 0) {
return;
}
var url = this.router.url;
if (url !== '/') {
var primary = this.router.parseUrl(url).root.children[i4.PRIMARY_OUTLET];
var segments = primary.segments;
if (segments.length > 1) {
var key = segments[0].path;
this.storage.set('history:' + key, segments.splice(1)).subscribe(function (_) { return _; });
}
}
var commands = [];
path.forEach(function (value) {
if (typeof value === 'string') {
commands.push.apply(commands, __spreadArray([], __read(value.split('/'))));
}
else {
commands.push(value);
}
});
this.router.navigate(commands, extras);
};
/**
* 导航历史
* Navigation history
*/
BitService.prototype.history = function (key) {
var _this = this;
this.storage.get('history:' + key).subscribe(function (segments) {
var commands = [key];
if (segments && segments.length !== 0) {
commands.push.apply(commands, __spreadArray([], __read(segments.map(function (v) { return v.path; }))));
_this.storage.delete('history:' + key).subscribe(function (_) { return _; });
}
_this.router.navigate(commands);
});
};
/**
* 导航返回
* Navigate back
*/
BitService.prototype.back = function () {
this.location.back();
this.resetI18n();
};
/**
* 初始化语言包
* Setup language pack
*/
BitService.prototype.setupLocale = function () {
this.l = {};
this.setLocale(localStorage.getItem('locale') || this.localeDefault);
};
/**
* 载入语言包
* Registered language pack
*/
BitService.prototype.registerLocales = function (packer) {
var _this = this;
Promise.resolve(packer).then(function (result) {
var e_1, _a;
if (!result.default) {
return;
}
_this.language = new Map(__spreadArray(__spreadArray([], __read(_this.language)), __read(Object.entries(result.default))));
var index = _this.localeDefault.indexOf(_this.locale);
try {
for (var _b = __values(_this.language.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), key = _d[0], data = _d[1];
_this.l[key] = data[index];
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
});
};
/**
* 设置语言包 ID
* Set language ID
*/
BitService.prototype.setLocale = function (locale) {
var e_2, _a;
this.locale = locale;
localStorage.setItem('locale', locale);
var index = this.localeMapping.indexOf(this.locale);
try {
for (var _b = __values(this.language.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
var _d = __read(_c.value, 2), key = _d[0], data = _d[1];
this.l[key] = data[index];
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
this.nzI18nService.setLocale(this.localeBind[index]);
this.localeChanged.next(locale);
};
/**
* 国际化 ID 是否相等
* Are the I18n IDs equal
*/
BitService.prototype.equalI18n = function (i18n) {
return this.i18n === i18n;
};
/**
* 重置国际化 ID
* Reset I18n ID
*/
BitService.prototype.resetI18n = function () {
this.i18n = this.i18nDefault;
};
/**
* 生成 I18n FormGroup
* Generate I18n FormGroup
*/
BitService.prototype.i18nGroup = function (options) {
var e_3, _a;
var controls = {};
if (options) {
try {
for (var _b = __values(this.i18nContain), _c = _b.next(); !_c.done; _c = _b.next()) {
var ID = _c.value;
controls[ID] = [null, [], []];
if (options.value !== undefined && options.value.hasOwnProperty(ID)) {
controls[ID][0] = options.value[ID];
}
if (options.validate !== undefined && options.validate.hasOwnProperty(ID)) {
controls[ID][1] = options.validate[ID];
}
if (options.asyncValidate !== undefined && options.asyncValidate.hasOwnProperty(ID)) {
controls[ID][2] = options.asyncValidate[ID];
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_3) throw e_3.error; }
}
}
return controls;
};
/**
* 解析国际化数据
* Parse i18n string json
*/
BitService.prototype.i18nParse = function (text) {
var e_4, _a;
var json = JSON.parse(text);
var data = {};
try {
for (var _b = __values(this.i18nContain), _c = _b.next(); !_c.done; _c = _b.next()) {
var ID = _c.value;
if (json.hasOwnProperty(ID)) {
data[ID] = json[ID];
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_4) throw e_4.error; }
}
return data;
};
/**
* 生产分页数据对象
* Factory list by page
*/
BitService.prototype.listByPage = function (option) {
option.limit = option.limit || this.pageDefault;
return new ListByPage(this.curd, this.storage, option);
};
/**
* 清除应用本地存储
* Clear app local storage
*/
BitService.prototype.clear = function () {
var _this = this;
this.storage.keys().pipe(operators.filter(function (v) { return ['resource', 'router'].includes(v) ||
v.search(/^search:\S+$/) !== -1 ||
v.search(/^page:\S+$/) !== -1 ||
v.search(/^cross:\S+$/) !== -1; }), operators.switchMap(function (key) { return _this.storage.delete(key); })).subscribe(function (_) { return _; });
};
return BitService;
}());
BitService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function BitService_Factory() { return new BitService(i0__namespace.ɵɵinject(BitConfig), i0__namespace.ɵɵinject(BitCurdService, 8), i0__namespace.ɵɵinject(i3__namespace.StorageMap, 8), i0__namespace.ɵɵinject(i4__namespace.Router, 8), i0__namespace.ɵɵinject(i5__namespace.Location, 8), i0__namespace.ɵɵinject(i6__namespace.NzI18nService, 8)); }, token: BitService, providedIn: "root" });
BitService.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
BitService.ctorParameters = function () { return [
{ type: BitConfig },
{ type: BitCurdService, decorators: [{ type: i0.Optional }] },
{ type: localStorage$1.StorageMap, decorators: [{ type: i0.Optional }] },
{ type: i4.Router, decorators: [{ type: i0.Optional }] },
{ type: i5.Location, decorators: [{ type: i0.Optional }] },
{ type: i6.NzI18nService, decorators: [{ type: i0.Optional }] }
]; };
var BitCurdCommonService = /** @class */ (function (_super) {
__extends(BitCurdCommonService, _super);
function BitCurdCommonService() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* 获取单条数据请求
* Get a single data request
*/
BitCurdCommonService.prototype.get = function (model, condition, order, path) {
var http;
var url = path || this.curd.get;
if (Array.isArray(condition)) {
http = this.http.req(model + url, {
where: this.getQuerySchema(condition),
order: order
});
}
else {
http = this.http.req(model + url, {
id: condition
});
}
return http.pipe(operators.map(function (res) { return !res.error ? res.data : null; }));
};
/**
* 获取分页数据请求
* Get pagination data request
*/
BitCurdCommonService.prototype.lists = function (model, factory, option, path) {
var _this = this;
var url = path || this.curd.lists;
if (option.refresh || option.persistence) {
if (option.refresh) {
factory.index = 1;
}
factory.persistence();
}
return factory.getPage().pipe(operators.switchMap(function (index) {
factory.index = index ? index : 1;
return _this.http.req(model + url, {
page: {
limit: factory.limit,
index: factory.index
},
where: factory.toQuerySchema(),
order: factory.order
});
}), operators.map(function (res) {
factory.totals = !res.error ? res.data.total : 0;
factory.loading = false;
factory.checked = false;
factory.indeterminate = false;
factory.batch = false;
factory.checkedNumber = 0;
return !res.error ? res.data.lists : null;
}));
};
/**
* 获取原始列表数据请求
* Get original list data request
*/
BitCurdCommonService.prototype.originLists = function (model, condition, order, path) {
if (condition === void 0) { condition = []; }
var url = path || this.curd.originLists;
return this.http.req(model + url, {
where: this.getQuerySchema(condition),
order: order
}).pipe(operators.map(function (res) { return !res.error ? res.data : null; }));
};
/**
* 新增数据请求
* New data request
*/
BitCurdCommonService.prototype.add = function (model, data, path) {
var url = path || this.curd.add;
return this.http.req(model + url, data);
};
/**
* 修改数据请求
* Modify data request
*/
BitCurdCommonService.prototype.edit = function (model, data, condition, path) {
var url = path || this.curd.edit;
data.switch = false;
return !condition ?
this.http.req(model + url, data) :
this.http.req(model + url, Object.assign(data, {
where: this.getQuerySchema(condition)
}));
};
/**
* 状态切换请求
* State switch request
*/
BitCurdCommonService.prototype.status = function (model, data, field, extra, path) {
var _a;
if (field === void 0) { field = 'status'; }
var url = path || this.curd.status;
var body = (_a = {
id: data.id,
switch: true
},
_a[field] = !data[field],
_a);
if (extra !== undefined) {
Object.assign(body, extra);
}
return this.http.req(model + url, body).pipe(operators.map(function (res) {
if (!res.error) {
data[field] = !data[field];
}
return res;
}));
};
/**
* 删除数据请求
* Delete data request
*/
BitCurdCommonService.prototype.delete = function (model, id, condition, path) {
var url = path || this.curd.delete;
if (id !== undefined) {
return this.http.req(model + url, {
id: id
});
}
if (condition !== undefined) {
return this.http.req(model + url, {
where: this.getQuerySchema(condition)
});
}
return rxjs.of(false);
};
return BitCurdCommonService;
}(BitCurdService));
BitCurdCommonService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function BitCurdCommonService_Factory() { return new BitCurdCommonService(i0__namespace.ɵɵinject(BitConfig), i0__namespace.ɵɵinject(BitHttpService)); }, token: BitCurdCommonService, providedIn: "root" });
BitCurdCommonService.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
var BitModule = /** @class */ (function () {
function BitModule(config, nzIcon) {
var _a;
nzIcon.changeAssetsSource((_a = config === null || config === void 0 ? void 0 : config.url) === null || _a === void 0 ? void 0 : _a.icon);
}
BitModule.forRoot = function (config) {
return {
ngModule: BitModule,
providers: [
{
provide: BitConfig,
useValue: config
},
BitService,
BitHttpService,
icon.NzIconService,
localStorage$1.StorageMap
]
};
};
return BitModule;
}());
BitModule.decorators = [
{ type: i0.NgModule }
];
BitModule.ctorParameters = function () { return [
{ type: BitConfig },
{ type: icon.NzIconService }
]; };
/**
* Generated bundle index. Do not edit.
*/
exports.BitConfig = BitConfig;
exports.BitCurdCommonService = BitCurdCommonService;
exports.BitCurdService = BitCurdService;
exports.BitHttpService = BitHttpService;
exports.BitModule = BitModule;
exports.BitService = BitService;
exports.ListByPage = ListByPage;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-bit.umd.js.map