未验证 提交 7a2bbab3 编写于 作者: 1 189******51 提交者: Gitee

IssueNo: #I7X5WW:[新需求]: Rectify the arkts syntax of qs on monthly

Description: Rectify the arkts syntax of qs on monthly
Sig: SIG_ApplicaitonFramework
Feature or Bugfix: Feature
Binary Source: No
Signed-off-by: N189******51 <lipeicheng5@huawei.com>
上级 8eacd65a
......@@ -144,21 +144,22 @@ AppStorage是单例,它的所有API都是静态的,使用方法类似于中L
```ts
AppStorage.SetOrCreate('PropA', 47);
let storage: LocalStorage = new LocalStorage({ 'PropA': 17 });
let propA: number = AppStorage.Get('PropA') // propA in AppStorage == 47, propA in LocalStorage == 17
var link1: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link1.get() == 47
var link2: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link2.get() == 47
var prop: SubscribedAbstractProperty<number> = AppStorage.Prop('PropA'); // prop.get() = 47
let storage: LocalStorage = new LocalStorage();
storage['PropA'] = 17;
let propA: number | undefined = AppStorage.Get('PropA') // propA in AppStorage == 47, propA in LocalStorage == 17
let link1: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link1.get() == 47
let link2: SubscribedAbstractProperty<number> = AppStorage.Link('PropA'); // link2.get() == 47
let prop: SubscribedAbstractProperty<number> = AppStorage.Prop('PropA'); // prop.get() = 47
link1.set(48); // two-way sync: link1.get() == link2.get() == prop.get() == 48
prop.set(1); // one-way sync: prop.get()=1; but link1.get() == link2.get() == 48
link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
storage.get('PropA') // == 17
storage.get<number>('PropA') // == 17
storage.set('PropA', 101);
storage.get('PropA') // == 101
storage.get<number>('PropA') // == 101
AppStorage.Get('PropA') // == 49
AppStorage.Get<number>('PropA') // == 49
link1.get() // == 49
link2.get() // == 49
prop.get() // == 49
......@@ -172,7 +173,8 @@ prop.get() // == 49
```ts
AppStorage.SetOrCreate('PropA', 47);
let storage = new LocalStorage({ 'PropA': 48 });
let storage = new LocalStorage();
storage['PropA'] = 48;
@Entry(storage)
@Component
......@@ -242,8 +244,13 @@ struct Gallery2 {
export struct TapImage {
@StorageLink('tapIndex') @Watch('onTapIndexChange') tapIndex: number = -1;
@State tapColor: Color = Color.Black;
private index: number;
private uri: Resource;
private index: number = 0;
private uri: Resource = {
id: 0,
type: 0,
moduleName: "",
bundleName: ""
};
// 判断是否被选中
onTapIndexChange() {
......@@ -313,9 +320,9 @@ struct Gallery2 {
if (this.preIndex === item.id) {
return
}
var innerEvent = { eventId: item.id }
let innerEvent: emitter.InnerEvent = { eventId: item.id }
// 选中态:黑变红
var eventData = {
let eventData: emitter.EventData = {
data: {
"colorTag": 1
}
......@@ -324,9 +331,9 @@ struct Gallery2 {
if (this.preIndex != -1) {
console.info(`preIndex: ${this.preIndex}, index: ${item.id}, black`)
var innerEvent = { eventId: this.preIndex }
let innerEvent: emitter.InnerEvent = { eventId: this.preIndex }
// 取消选中态:红变黑
var eventData = {
let eventData: emitter.EventData = {
data: {
"colorTag": 0
}
......@@ -335,7 +342,6 @@ struct Gallery2 {
}
this.preIndex = item.id
})
}, (item: ViewData) => JSON.stringify(item))
}.columnsTemplate('1fr 1fr')
}
......@@ -346,17 +352,26 @@ struct Gallery2 {
@Component
export struct TapImage {
@State tapColor: Color = Color.Black;
private index: number;
private uri: Resource;
private index: number = 0;
private uri: Resource = {
id: 0,
type: 0,
moduleName: "",
bundleName: ""
};
onTapIndexChange(colorTag: emitter.EventData) {
this.tapColor = colorTag.data.colorTag ? Color.Red : Color.Black
if (colorTag.data != null) {
this.tapColor = colorTag.data.colorTag ? Color.Red : Color.Black
}
}
aboutToAppear() {
//定义事件ID
var innerEvent = { eventId: this.index }
emitter.on(innerEvent, this.onTapIndexChange.bind(this))
let innerEvent: emitter.InnerEvent = { eventId: this.index }
emitter.on(innerEvent, data => {
this.onTapIndexChange(data)
})
}
build() {
......@@ -414,8 +429,13 @@ struct Gallery2 {
export struct TapImage {
@StorageLink('tapIndex') tapIndex: number = -1;
@State tapColor: Color = Color.Black;
private index: number;
private uri: Resource;
private index: number = 0;
private uri: Resource = {
id: 0,
type: 0,
moduleName: "",
bundleName: ""
};
build() {
Column() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册