From 2ded20b71d649e56fb6205a0ccf6c55374b84695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=85=E9=A3=8E?= <64198909+FlyQingfeng@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:53:42 +0800 Subject: [PATCH] Delete src/Public/attribute.ts --- src/Public/attribute.ts | 97 ----------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 src/Public/attribute.ts diff --git a/src/Public/attribute.ts b/src/Public/attribute.ts deleted file mode 100644 index 1a9b1e3..0000000 --- a/src/Public/attribute.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { hasFun } from "../Public/stdlib"; - -//属性类 -export class Attribute { - private properties: { [key: string]: any } = {}; - _obj:any; - constructor(obj:any){ - // 保证有这两个函数 - if (hasFun(obj,"getDynamicProperty") - &&hasFun(obj,"setDynamicProperty")) { - this._obj=obj; - let data=obj.getDynamicProperty("Attribute"); - if (data) { - this.properties=JSON.parse(data); - }else{ - this.save() - } - }else{//抛出异常 - throw new Error("SuperAPI[Attribute:constructor]:The constructor you want to pass using the class must have two functions,"); - } - } - private save(){ - let data=JSON.stringify(this.properties); - if (this._obj) { - this._obj.setDynamicProperty("Attribute",data); - } - } - init(key: string, value: any){ - let data=this._obj.getDynamicProperty("Attribute"); - let json=JSON.parse(data); - if (!json[key]) {//只有在该值不存在的时候才能初始化,避免覆盖值 - this.set(key,value); - } - } - // 添加或更新属性 - set(key: string, value: any): void { - this.properties[key] = value; - this.save(); - } - - // 获取属性值 - get(key: string): any { - return this.properties[key]; - } - - // 删除属性 - delete(key: string): void { - delete this.properties[key]; - this.save(); - } - - // 检查属性是否存在 - has(key: string): boolean { - return key in this.properties; - } - - // 获取所有属性键 - keys(): string[] { - return Object.keys(this.properties); - } - - // 获取所有属性值 - values(): any[] { - return Object.values(this.properties); - } - - // 获取所有属性键值对 - entries(): [string, any][] { - return Object.entries(this.properties); - } - - // 清空所有属性 - clear(): void { - Object.keys(this.properties).forEach(key => { - delete this.properties[key]; - }); - this.save(); - } -} - -// 使用示例 -// const dynProps = new Attribute(); -// dynProps.set('name', 'John Doe'); -// dynProps.set('age', 30); - -// console.log(dynProps.get('name')); // 输出:John Doe -// console.log(dynProps.has('age')); // 输出:true - -// dynProps.delete('age'); -// console.log(dynProps.has('age')); // 输出:false - -// console.log(dynProps.keys()); // 输出:['name'] -// console.log(dynProps.values()); // 输出:['John Doe'] -// console.log(dynProps.entries()); // 输出:[['name', 'John Doe']] - -// dynProps.clear(); -// console.log(dynProps.keys()); // 输出:[] \ No newline at end of file