完善了i18n wxs中发现键值缺失时向component层的回调
This commit is contained in:
parent
14d700224f
commit
064b5ea733
|
|
@ -42,9 +42,7 @@ exports.default = OakComponent({
|
|||
ready: function () {
|
||||
var _a = this.props, attributes = _a.attributes, entity = _a.entity;
|
||||
var schema = this.features.cache.getSchema();
|
||||
var transformer = (0, usefulFn_1.makeDataTransformer)(schema, entity, attributes
|
||||
// (k, params) => this.t(k, params)
|
||||
);
|
||||
var transformer = (0, usefulFn_1.makeDataTransformer)(schema, entity, attributes, this.t);
|
||||
this.setState({
|
||||
transformer: transformer,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,17 +23,17 @@ function Render(props) {
|
|||
var methods = props.methods, oakData = props.data;
|
||||
var t = methods.t;
|
||||
var entity = oakData.entity, title = oakData.title, colorDict = oakData.colorDict, bordered = oakData.bordered, column = oakData.column, renderData = oakData.renderData, _a = oakData.layout, layout = _a === void 0 ? "horizontal" : _a;
|
||||
return ((0, jsx_runtime_1.jsx)(antd_1.Card, { children: (0, jsx_runtime_1.jsx)(antd_1.Descriptions, tslib_1.__assign({ title: title, column: column, bordered: bordered, layout: layout }, { children: renderData === null || renderData === void 0 ? void 0 : renderData.map(function (ele) {
|
||||
var _a, _b;
|
||||
var renderValue = ele.value || t('not_filled_in');
|
||||
var color = colorDict && ((_b = (_a = colorDict[entity]) === null || _a === void 0 ? void 0 : _a[ele.attr]) === null || _b === void 0 ? void 0 : _b[ele.value]) || 'default';
|
||||
if (ele.type === 'enum') {
|
||||
renderValue = ele.value && t("".concat(entity, ":v.").concat(ele.attr, ".").concat(ele.value));
|
||||
}
|
||||
if (ele.type === 'datetime') {
|
||||
renderValue = ele.value && (0, dayjs_1.default)(ele.value).format('YYYY-MM-DD');
|
||||
}
|
||||
return ((0, jsx_runtime_1.jsx)(antd_1.Descriptions.Item, tslib_1.__assign({ label: t(ele.label), span: ele.span || 1 }, { children: (0, jsx_runtime_1.jsx)(RenderRow, { type: ele.type, value: renderValue, color: color }) })));
|
||||
}) })) }));
|
||||
return ((0, jsx_runtime_1.jsx)(antd_1.Descriptions, tslib_1.__assign({ title: title, column: column, bordered: bordered, layout: layout }, { children: renderData === null || renderData === void 0 ? void 0 : renderData.map(function (ele) {
|
||||
var _a, _b;
|
||||
var renderValue = ele.value || t('not_filled_in');
|
||||
var color = colorDict && ((_b = (_a = colorDict[entity]) === null || _a === void 0 ? void 0 : _a[ele.attr]) === null || _b === void 0 ? void 0 : _b[ele.value]) || 'default';
|
||||
if (ele.type === 'enum') {
|
||||
renderValue = ele.value && t("".concat(entity, ":v.").concat(ele.attr, ".").concat(ele.value));
|
||||
}
|
||||
if (ele.type === 'datetime') {
|
||||
renderValue = ele.value && (0, dayjs_1.default)(ele.value).format('YYYY-MM-DD');
|
||||
}
|
||||
return ((0, jsx_runtime_1.jsx)(antd_1.Descriptions.Item, tslib_1.__assign({ label: ele.label, span: ele.span || 1 }, { children: (0, jsx_runtime_1.jsx)(RenderRow, { type: ele.type, value: renderValue, color: color }) })));
|
||||
}) })));
|
||||
}
|
||||
exports.default = Render;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ export declare class Locales<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
* @param ns
|
||||
*/
|
||||
private loadData;
|
||||
/**
|
||||
* 暴露给小程序的Wxs调用
|
||||
* @param key
|
||||
*/
|
||||
loadMissedLocale(key: string): void;
|
||||
/**
|
||||
* translate函数,这里编译器会在params里注入两个参数 #oakNamespace 和 #oakModule,用以标识文件路径
|
||||
* @param key
|
||||
|
|
|
|||
|
|
@ -161,6 +161,13 @@ var Locales = /** @class */ (function (_super) {
|
|||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 暴露给小程序的Wxs调用
|
||||
* @param key
|
||||
*/
|
||||
Locales.prototype.loadMissedLocale = function (key) {
|
||||
this.loadData(key);
|
||||
};
|
||||
/**
|
||||
* translate函数,这里编译器会在params里注入两个参数 #oakNamespace 和 #oakModule,用以标识文件路径
|
||||
* @param key
|
||||
|
|
|
|||
|
|
@ -446,6 +446,9 @@ var oakBehavior = Behavior({
|
|||
});
|
||||
});
|
||||
},
|
||||
loadMissedLocales: function (key) {
|
||||
this.features.locales.loadMissedLocale(key);
|
||||
}
|
||||
},
|
||||
observers: {
|
||||
oakPath: function (data) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ function _getPlural(count) {
|
|||
var PlaceHolder = /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm;
|
||||
function interpolate(message, options) {
|
||||
if (typeof message === 'string') {
|
||||
// 实测下这个正则在小程序wxs环境中过不去,原因未知 by Xc
|
||||
var matches = message.match(PlaceHolder);
|
||||
if (!matches) {
|
||||
return message;
|
||||
|
|
@ -81,6 +82,7 @@ function constructFullKey(key, namespace, moduleName) {
|
|||
}
|
||||
return key2;
|
||||
}
|
||||
var Instance = undefined;
|
||||
function t(key, p1, p2, p3, p4, p5, p6) {
|
||||
var fullKey = '';
|
||||
var hasLocale = false;
|
||||
|
|
@ -124,9 +126,13 @@ function t(key, p1, p2, p3, p4, p5, p6) {
|
|||
}
|
||||
}
|
||||
// 到这里说明miss了,通知AppService层,并返回value
|
||||
if (hasLocale) {
|
||||
if (hasLocale && Instance) {
|
||||
// todo
|
||||
Instance.callMethod('loadMissedLocales', fullKey);
|
||||
}
|
||||
return fullKey.split('.').pop();
|
||||
}
|
||||
exports.t = t;
|
||||
function propObserver(locales, oldValue, instance) {
|
||||
Instance = instance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export declare function getWidth(attribute: OakAbsAttrDef, attrType: DataType |
|
|||
export declare function getValue<ED extends EntityDict & BaseEntityDict>(data: any, path: string, entity: keyof ED, attr: string, attrType: DataType | 'ref' | undefined, t: (k: string, params?: object) => string): any;
|
||||
export declare function getAlign(attrType: DataType): 'left' | 'right' | 'center';
|
||||
export declare function getType(attribute: OakAbsAttrDef, attrType: OakAbsDerivedAttrDef['type']): "link" | "ref" | DataType | undefined;
|
||||
export declare function makeDataTransformer<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: keyof ED, attrDefs: OakAbsAttrDef[], colorDict?: ColorDict<ED>): DataTransformer;
|
||||
export declare function makeDataTransformer<ED extends EntityDict & BaseEntityDict>(dataSchema: StorageSchema<ED>, entity: keyof ED, attrDefs: OakAbsAttrDef[], t: (k: string, params?: object) => string, colorDict?: ColorDict<ED>): DataTransformer;
|
||||
export declare function analyzeDataUpsertTransformer<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(dataSchema: StorageSchema<ED>, entity: T, attrUpsertDefs: OakAbsAttrUpsertDef<ED, T>[]): (data: any) => AttrUpsertRender<ED, T>[];
|
||||
declare type CoverData = {
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -178,14 +178,12 @@ function getLabelI18(dataSchema, entity, path, t) {
|
|||
var _a = resolvePath(dataSchema, entity, path), attr = _a.attr, entityI8n = _a.entity;
|
||||
return t("".concat(entityI8n, ":attr.").concat(attr), {});
|
||||
}
|
||||
function makeDataTransformer(dataSchema, entity, attrDefs,
|
||||
// t: (k: string, params?: object) => string,
|
||||
colorDict) {
|
||||
function makeDataTransformer(dataSchema, entity, attrDefs, t, colorDict) {
|
||||
var transformerFixedPart = attrDefs.map(function (ele) {
|
||||
if (typeof ele === 'string') {
|
||||
var path = ele;
|
||||
var _a = resolvePath(dataSchema, entity, path), attrType = _a.attrType, attr = _a.attr, entityI8n = _a.entity;
|
||||
var label = "".concat(entityI8n, ":attr.").concat(attr);
|
||||
var label = getLabel(ele, entityI8n, attr, t);
|
||||
var type = attrType;
|
||||
return {
|
||||
path: path,
|
||||
|
|
|
|||
|
|
@ -171,6 +171,14 @@ export class Locales<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 暴露给小程序的Wxs调用
|
||||
* @param key
|
||||
*/
|
||||
loadMissedLocale(key: string) {
|
||||
this.loadData(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* translate函数,这里编译器会在params里注入两个参数 #oakNamespace 和 #oakModule,用以标识文件路径
|
||||
* @param key
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ const oakBehavior = Behavior<
|
|||
callback?: () => void
|
||||
) => void;
|
||||
onLoad: (query: Record<string, any>) => Promise<void>;
|
||||
loadMissedLocales: (key: string) => void;
|
||||
},
|
||||
{
|
||||
prevState: Record<string, any>;
|
||||
|
|
@ -648,6 +649,10 @@ const oakBehavior = Behavior<
|
|||
aggregation
|
||||
);
|
||||
},
|
||||
|
||||
loadMissedLocales(key: string) {
|
||||
this.features.locales.loadMissedLocale(key);
|
||||
}
|
||||
},
|
||||
observers: {
|
||||
oakPath(data) {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ function _getPlural(count: number) {
|
|||
const PlaceHolder = /(?:\{\{|%\{)(.*?)(?:\}\}?)/gm;
|
||||
function interpolate(message: any, options: Record<string, any>): string {
|
||||
if (typeof message === 'string') {
|
||||
// 实测下这个正则在小程序wxs环境中过不去,原因未知 by Xc
|
||||
const matches = message.match(PlaceHolder);
|
||||
|
||||
if (!matches) {
|
||||
|
|
@ -92,6 +93,8 @@ function constructFullKey(key: string, namespace: string, moduleName: string) {
|
|||
return key2;
|
||||
}
|
||||
|
||||
let Instance:any = undefined;
|
||||
|
||||
|
||||
export function t(key: string, p1: any, p2: any, p3: any, p4: any, p5: any, p6: any): string {
|
||||
let fullKey = '';
|
||||
|
|
@ -137,8 +140,13 @@ export function t(key: string, p1: any, p2: any, p3: any, p4: any, p5: any, p6:
|
|||
}
|
||||
|
||||
// 到这里说明miss了,通知AppService层,并返回value
|
||||
if (hasLocale) {
|
||||
if (hasLocale && Instance) {
|
||||
// todo
|
||||
Instance.callMethod('loadMissedLocales', fullKey);
|
||||
}
|
||||
return fullKey.split('.').pop()!;
|
||||
}
|
||||
|
||||
function propObserver(locales: any, oldValue: any, instance: any) {
|
||||
Instance = instance;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue