前端转vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PageHelper.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // 假设 IPage 接口定义如下
  2. interface IPage {}
  3. // 假设 TradeModel 类型定义如下
  4. interface TradeModel {}
  5. // 定义一个全局对象来存储附加属性的值
  6. const attachedProperties = new WeakMap<object, { [key: string]: any }>();
  7. function getAttachedProperty<T>(obj: object, propertyName: string): T | undefined {
  8. const properties = attachedProperties.get(obj);
  9. return properties?.[propertyName];
  10. }
  11. function setAttachedProperty(obj: object, propertyName: string, value: any) {
  12. let properties = attachedProperties.get(obj);
  13. if (!properties) {
  14. properties = {};
  15. attachedProperties.set(obj, properties);
  16. }
  17. properties[propertyName] = value;
  18. }
  19. export class PageHelper {
  20. // OwnerPage 附加属性
  21. static get OwnerPageProperty() { return "OwnerPage"; }
  22. static GetOwnerPage(d: object): IPage | undefined {
  23. return getAttachedProperty<IPage>(d, this.OwnerPageProperty);
  24. }
  25. static SetOwnerPage(d: object, value: IPage) {
  26. setAttachedProperty(d, this.OwnerPageProperty, value);
  27. }
  28. // ViewStateData 附加属性
  29. static get ViewStateDataProperty() { return "ViewStateData"; }
  30. static GetViewStateData(obj: object): Record<string, object> | undefined {
  31. return getAttachedProperty<Record<string, object>>(obj, this.ViewStateDataProperty);
  32. }
  33. static SetViewStateData(obj: object, value: Record<string, object>) {
  34. setAttachedProperty(obj, this.ViewStateDataProperty, value);
  35. }
  36. // TradeModel 附加属性
  37. static get TradeModelProperty() { return "TradeModel"; }
  38. static GetTradeModel(obj: object): TradeModel | undefined {
  39. return getAttachedProperty<TradeModel>(obj, this.TradeModelProperty);
  40. }
  41. static SetTradeModel(obj: object, value: TradeModel) {
  42. setAttachedProperty(obj, this.TradeModelProperty, value);
  43. }
  44. }