FileCarrier
This commit is contained in:
parent
8e484943c7
commit
497123ef10
|
|
@ -11,6 +11,7 @@ import { judgeRelation } from 'oak-domain/lib/store/relation';
|
||||||
import { StorageSchema } from 'oak-domain/lib/types/Storage';
|
import { StorageSchema } from 'oak-domain/lib/types/Storage';
|
||||||
import { Pagination } from '../types/Pagination';
|
import { Pagination } from '../types/Pagination';
|
||||||
import { NamedFilterItem, NamedSorterItem } from '../types/NamedCondition';
|
import { NamedFilterItem, NamedSorterItem } from '../types/NamedCondition';
|
||||||
|
import { FileCarrier } from '../types/FileCarrier';
|
||||||
|
|
||||||
export class Node<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>> {
|
export class Node<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>> {
|
||||||
protected entity: T;
|
protected entity: T;
|
||||||
|
|
@ -410,6 +411,7 @@ class SingleNode<ED extends EntityDict, T extends keyof ED, Cxt extends Context<
|
||||||
private children: {
|
private children: {
|
||||||
[K in keyof ED[T]['Schema']]?: SingleNode<ED, keyof ED, Cxt, AD> | ListNode<ED, keyof ED, Cxt, AD>;
|
[K in keyof ED[T]['Schema']]?: SingleNode<ED, keyof ED, Cxt, AD> | ListNode<ED, keyof ED, Cxt, AD>;
|
||||||
};
|
};
|
||||||
|
private fileCarrier?: FileCarrier;
|
||||||
|
|
||||||
constructor(entity: T, fullPath: string, schema: StorageSchema<ED>, cache: Cache<ED, Cxt, AD>, projection?: ED[T]['Selection']['data'],
|
constructor(entity: T, fullPath: string, schema: StorageSchema<ED>, cache: Cache<ED, Cxt, AD>, projection?: ED[T]['Selection']['data'],
|
||||||
parent?: Node<ED, keyof ED, Cxt, AD>, id?: string, action?: ED[T]['Action']) {
|
parent?: Node<ED, keyof ED, Cxt, AD>, id?: string, action?: ED[T]['Action']) {
|
||||||
|
|
@ -592,6 +594,14 @@ class SingleNode<ED extends EntityDict, T extends keyof ED, Cxt extends Context<
|
||||||
this.updateChildrenValues();
|
this.updateChildrenValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFileCarrier(fileCarrier: FileCarrier) {
|
||||||
|
this.fileCarrier = fileCarrier;
|
||||||
|
}
|
||||||
|
|
||||||
|
getFileCarrier() {
|
||||||
|
return this.fileCarrier;
|
||||||
|
}
|
||||||
|
|
||||||
resetUpdateData() {
|
resetUpdateData() {
|
||||||
this.updateData = undefined;
|
this.updateData = undefined;
|
||||||
// this.action = undefined;
|
// this.action = undefined;
|
||||||
|
|
@ -892,8 +902,8 @@ export class RunningNode<ED extends EntityDict, Cxt extends Context<ED>, AD exte
|
||||||
let iter = 1;
|
let iter = 1;
|
||||||
while (iter < paths.length) {
|
while (iter < paths.length) {
|
||||||
const childPath = paths[iter];
|
const childPath = paths[iter];
|
||||||
node = (await node.getChild<Cxt, AD>(childPath))!;
|
|
||||||
iter++;
|
iter++;
|
||||||
|
node = (await node.getChild<Cxt, AD>(childPath))!;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
@ -931,6 +941,14 @@ export class RunningNode<ED extends EntityDict, Cxt extends Context<ED>, AD exte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Action
|
||||||
|
async setFileCarrier(path: string, fileCarrier: FileCarrier) {
|
||||||
|
const node = await this.findNode(path);
|
||||||
|
assert(node instanceof SingleNode);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
async refresh(path: string) {
|
async refresh(path: string) {
|
||||||
const node = await this.findNode(path);
|
const node = await this.findNode(path);
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,4 @@ export {
|
||||||
export * from './types/Feature';
|
export * from './types/Feature';
|
||||||
export * from './types/ExceptionRoute';
|
export * from './types/ExceptionRoute';
|
||||||
export { BasicFeatures } from './features';
|
export { BasicFeatures } from './features';
|
||||||
|
export * from './utils/WechatMpFileCarrier';
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import assert from "assert";
|
||||||
import { assign, intersection, rest, union } from "lodash";
|
import { assign, intersection, rest, union } from "lodash";
|
||||||
import { ExceptionHandler, ExceptionRouters } from '../../types/ExceptionRoute';
|
import { ExceptionHandler, ExceptionRouters } from '../../types/ExceptionRoute';
|
||||||
import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition';
|
import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition';
|
||||||
|
import { FileCarrier } from '../../types/FileCarrier';
|
||||||
|
|
||||||
type OakComponentOption<
|
type OakComponentOption<
|
||||||
ED extends EntityDict,
|
ED extends EntityDict,
|
||||||
|
|
@ -19,7 +20,10 @@ type OakComponentOption<
|
||||||
FormedData extends WechatMiniprogram.Component.DataOption
|
FormedData extends WechatMiniprogram.Component.DataOption
|
||||||
> = {
|
> = {
|
||||||
entity: T;
|
entity: T;
|
||||||
formData: ($rows: SelectionResult<ED[T]['Schema'], Proj>['result'], features: BasicFeatures<ED, Cxt, AD> & FD) => Promise<FormedData>;
|
formData: (
|
||||||
|
$rows: SelectionResult<ED[T]['Schema'], Proj>['result'],
|
||||||
|
features: BasicFeatures<ED, Cxt, AD> & FD,
|
||||||
|
fileCarrier?: ED[T]['IsFileCarrier'] extends boolean ? FileCarrier : undefined) => Promise<FormedData>
|
||||||
};
|
};
|
||||||
|
|
||||||
interface OakPageOption<
|
interface OakPageOption<
|
||||||
|
|
@ -47,7 +51,10 @@ interface OakPageOption<
|
||||||
'#name'?: string;
|
'#name'?: string;
|
||||||
}>;
|
}>;
|
||||||
actions?: ED[T]['Action'][];
|
actions?: ED[T]['Action'][];
|
||||||
formData: ($rows: SelectionResult<ED[T]['Schema'], Proj>['result'], features: BasicFeatures<ED, Cxt, AD> & FD) => Promise<FormedData>;
|
formData: (
|
||||||
|
$rows: SelectionResult<ED[T]['Schema'], Proj>['result'],
|
||||||
|
features: BasicFeatures<ED, Cxt, AD> & FD,
|
||||||
|
fileCarrier?: ED[T]['IsFileCarrier'] extends boolean ? FileCarrier : undefined) => Promise<FormedData>
|
||||||
};
|
};
|
||||||
|
|
||||||
type OakComponentProperties = {
|
type OakComponentProperties = {
|
||||||
|
|
@ -88,6 +95,7 @@ type OakComponentMethods<ED extends EntityDict, T extends keyof ED> = {
|
||||||
callPicker: (attr: string, params: Record<string, any>) => void;
|
callPicker: (attr: string, params: Record<string, any>) => void;
|
||||||
setFilters: (filters: NamedFilterItem<ED, T>[]) => void;
|
setFilters: (filters: NamedFilterItem<ED, T>[]) => void;
|
||||||
navigateTo: <T2 extends keyof ED>(options: Parameters<typeof wx.navigateTo>[0] & OakNavigateToParameters<ED, T2>) => ReturnType<typeof wx.navigateTo>;
|
navigateTo: <T2 extends keyof ED>(options: Parameters<typeof wx.navigateTo>[0] & OakNavigateToParameters<ED, T2>) => ReturnType<typeof wx.navigateTo>;
|
||||||
|
setFileCarrier: (fileCarrier: ED[T]['IsFileCarrier'] extends true ? FileCarrier : never) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type OakPageMethods<ED extends EntityDict, T extends keyof ED> = OakComponentMethods<ED, T> & {
|
type OakPageMethods<ED extends EntityDict, T extends keyof ED> = OakComponentMethods<ED, T> & {
|
||||||
|
|
@ -276,6 +284,10 @@ function createPageOptions<ED extends EntityDict,
|
||||||
features.runningNode.setUpdateData(this.data.oakFullpath, attr, value);
|
features.runningNode.setUpdateData(this.data.oakFullpath, attr, value);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setFileCarrier(fileCarrier) {
|
||||||
|
return features.runningNode.setFileCarrier(this.data.oakFullpath, fileCarrier);
|
||||||
|
},
|
||||||
|
|
||||||
callPicker(attr: string, params: Record<string, any>) {
|
callPicker(attr: string, params: Record<string, any>) {
|
||||||
if (this.data.oakExecuting) {
|
if (this.data.oakExecuting) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -583,6 +595,10 @@ function createComponentOptions<ED extends EntityDict,
|
||||||
features.runningNode.setUpdateData(this.data.oakFullpath, attr, value);
|
features.runningNode.setUpdateData(this.data.oakFullpath, attr, value);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setFileCarrier(fileCarrier) {
|
||||||
|
return features.runningNode.setFileCarrier(this.data.oakFullpath, fileCarrier);
|
||||||
|
},
|
||||||
|
|
||||||
callPicker(attr: string, params: Record<string, any>) {
|
callPicker(attr: string, params: Record<string, any>) {
|
||||||
if (this.data.oakExecuting) {
|
if (this.data.oakExecuting) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1005,6 +1021,6 @@ export type MakeOakComponent<
|
||||||
OakComponentData & FormedData,
|
OakComponentData & FormedData,
|
||||||
OakComponentInstanceProperties<ED, Cxt, AD, FD>,
|
OakComponentInstanceProperties<ED, Cxt, AD, FD>,
|
||||||
IS,
|
IS,
|
||||||
true
|
false
|
||||||
>
|
>
|
||||||
) => string;
|
) => string;
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export abstract class FileCarrier {
|
||||||
|
abstract getBytes(): Promise<Uint8Array>;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { FileCarrier } from "../types/FileCarrier";
|
||||||
|
|
||||||
|
export class WechatMpFileCarrier extends FileCarrier {
|
||||||
|
getBytes(): Promise<Uint8Array> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue