Skip to content

Commit 4d4a4a7

Browse files
committed
fix: adjust wx
1 parent d48cf36 commit 4d4a4a7

File tree

12 files changed

+108
-25
lines changed

12 files changed

+108
-25
lines changed

copilot-demo/pages/Actions/index.axml

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
<ant-container title="基础用法">
2-
<ant-actions
3-
items="{{basicActions}}"
4-
onItemTap="handleTapAction"
5-
/>
2+
<ant-actions items="{{basicActions}}" onItemTap="handleTapAction" />
63
</ant-container>
74

85
<ant-container title="配合bubble使用">
96
<ant-switch checked="{{ showBubble }}" onChange="toggleBubble" />
10-
<ant-bubble a:if="{{ showBubble }}" content="永和九年,岁在癸丑,暮春之初,会于会稽山阴之兰亭,修禊事也。群贤毕至,少长咸集。此地有崇山峻岭,茂林修竹,又有清流激湍,映带左右,引以为流觞曲水,列坐其次。虽无丝竹管弦之盛,一觞一咏,亦足以畅叙幽情。" typing="{{ { step: 2, interval: 50 } }}" onTypingComplete="onTypingComplete">
11-
<ant-actions a:if="{{ loaded }}" slot="footer" items="{{bubbleActions}}" onItemTap="handleBubbleAction" />
7+
<ant-bubble
8+
a:if="{{ showBubble }}"
9+
content="永和九年,岁在癸丑,暮春之初,会于会稽山阴之兰亭,修禊事也。群贤毕至,少长咸集。此地有崇山峻岭,茂林修竹,又有清流激湍,映带左右,引以为流觞曲水,列坐其次。虽无丝竹管弦之盛,一觞一咏,亦足以畅叙幽情。"
10+
typing="{{ { step: 2, interval: 50 } }}"
11+
onTypingComplete="onTypingComplete"
12+
>
13+
<ant-actions
14+
a:if="{{ loaded }}"
15+
slot="footer"
16+
items="{{bubbleActions}}"
17+
onItemTap="handleBubbleAction"
18+
/>
1219
</ant-bubble>
1320
</ant-container>

copilot-demo/pages/Actions/index.ts

+24
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Page({
3434
},
3535

3636
handleTapAction(item) {
37+
/// #if WECHAT
38+
// @ts-ignore
39+
item = item.detail;
40+
/// #endif
3741
const basicActions = [...this.data.basicActions];
3842
if (item.label === 'like') {
3943
this.setData({
@@ -43,18 +47,38 @@ Page({
4347
? 'https://mdn.alipayobjects.com/huamei_bsws4g/afts/img/JmVoRp-2UwMAAAAAAAAAAAAADoEQAQFr/original'
4448
: 'LikeOutline';
4549
} else {
50+
/// #if ALIPAY
4651
my.showToast({
4752
content: `${item.label} tapped`,
4853
});
54+
/// #endif
55+
/// #if WECHAT
56+
// @ts-ignore
57+
wx.showToast({
58+
title: `${item.label} tapped`,
59+
});
60+
/// #endif
4961
}
5062
this.setData({
5163
basicActions,
5264
});
5365
},
5466
handleBubbleAction(item) {
67+
/// #if WECHAT
68+
// @ts-ignore
69+
item = item.detail;
70+
/// #endif
71+
/// #if ALIPAY
5572
my.showToast({
5673
content: `${item.label} tapped`,
5774
});
75+
/// #endif
76+
/// #if WECHAT
77+
// @ts-ignore
78+
wx.showToast({
79+
title: `${item.label} tapped`,
80+
});
81+
/// #endif
5882
},
5983
onTypingComplete() {
6084
this.setData({

copilot-demo/pages/Sender/index.ts

+16
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ Page({
2121
},
2222
/** 基础用法 */
2323
handleChange(value: string) {
24+
/// #if WECHAT
25+
// @ts-ignore
26+
value = value.detail;
27+
/// #endif
2428
this.setData({ value });
2529
},
2630
handleSend() {
2731
this.setData({ value: '' });
2832
},
2933
/** 发送loading状态 */
3034
handleChange1(value: string) {
35+
/// #if WECHAT
36+
// @ts-ignore
37+
value = value.detail;
38+
/// #endif
3139
this.setData({ value1: value });
3240
},
3341
handleSend1() {
@@ -42,6 +50,10 @@ Page({
4250
},
4351
/** 配合upload组件 */
4452
handleChange3(value: string) {
53+
/// #if WECHAT
54+
// @ts-ignore
55+
value = value.detail;
56+
/// #endif
4557
this.setData({ value3: value });
4658
},
4759
handleSend3() {
@@ -56,6 +68,10 @@ Page({
5668
});
5769
},
5870
handleChange4(value: string) {
71+
/// #if WECHAT
72+
// @ts-ignore
73+
value = value.detail;
74+
/// #endif
5975
this.setData({ value4: value });
6076
},
6177
handleSend4() {

copilot-demo/pages/ThoughtChain/index.axml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
<view a:else>{{module.content}}</view>
3434
</view>
3535
</thought-chain>
36-
</ant-container>
36+
</ant-container>

copilot/Actions/check.sjs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/// #if ALIPAY
12
export function checkIcon(icon = '') {
23
return getRegExp('^[a-zA-Z]+$').test(icon);
34
}
5+
/// #endif
6+
/// #if WECHAT
7+
function checkIcon(icon = '') {
8+
return getRegExp('^[a-zA-Z]+$').test(icon);
9+
}
10+
module.exports = {
11+
checkIcon
12+
}
13+
/// #endif

copilot/Actions/index.axml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<import-sjs from="./check.sjs" name="{ checkIcon }" />
1+
<import-sjs from="./check.sjs" name="sjs" />
22

33
<view class="ant-copilot-actions {{className}}" style="{{style}}">
44
<view
@@ -9,7 +9,7 @@
99
data-action="{{item}}"
1010
>
1111
<ant-icon
12-
a:if="{{checkIcon(item.icon)}}"
12+
a:if="{{sjs.checkIcon(item.icon)}}"
1313
className="ant-copilot-actions-item-icon"
1414
type="{{item.icon}}"
1515
/>

copilot/Bubble/index.ts

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
import { Component } from '../../src/_util/simply';
1+
import { Component, getValueFromProps, triggerEventOnly } from '../../src/_util/simply';
22
import { BubbleProps } from './props';
33

44
Component(
55
BubbleProps,
66
{
77
startTyping() {
8-
if (this.props.loading) {
8+
const [loading, typing, content] = getValueFromProps(this, [
9+
'loading',
10+
'typing',
11+
'content',
12+
]);
13+
if (loading) {
914
return;
1015
}
11-
if (this.props.content) {
12-
const typingOptions = this.props.typing
13-
? this.props.typing === true
16+
if (content) {
17+
const typingOptions = typing
18+
? typing === true
1419
? { step: 1, interval: 100 }
15-
: this.props.typing
20+
: typing
1621
: false;
1722
if (typingOptions) {
1823
const { step = 1, interval = 100 } = typingOptions;
19-
const content = this.props.content;
24+
const bubbleText = content;
2025
// todo 待优化
2126
const typingLoop = (length: number, typedLength: number) => {
22-
const typingText = content.slice(0, typedLength);
27+
const typingText = bubbleText.slice(0, typedLength);
2328
this.setData({
2429
bubbleText: typingText,
2530
});
@@ -28,15 +33,15 @@ Component(
2833
typingLoop(length, typedLength + step);
2934
}, interval);
3035
} else {
31-
this.props.onTypingComplete?.();
36+
triggerEventOnly(this, 'typingComplete')
3237
}
3338
};
34-
typingLoop(content.length, step);
39+
typingLoop(bubbleText.length, step);
3540
} else {
3641
this.setData({
37-
bubbleText: this.props.content,
42+
bubbleText: content,
3843
});
39-
this.props.onTypingComplete?.();
44+
triggerEventOnly(this, 'typingComplete')
4045
}
4146
}
4247
},
@@ -58,8 +63,15 @@ Component(
5863
}
5964
},
6065
},
66+
/// #if ALIPAY
6167
didMount() {
6268
this.startTyping();
6369
},
70+
/// #endif
71+
/// #if WECHAT
72+
attached() {
73+
this.startTyping();
74+
},
75+
/// #endif
6476
}
6577
);

copilot/Bubble/props.ts

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const BubbleProps: IBubbleProps = {
4545
placement: 'start',
4646
loading: false,
4747
typing: false,
48-
onTypingComplete: () => {},
4948
shape: 'default',
5049
variant: 'filled',
5150
avatar: '',

copilot/Sender/index.less

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
box-sizing: border-box;
3131
overflow: hidden;
3232
.ant-copilot-sender-input {
33+
width: 100%;
3334
margin-left: @size-1;
3435
padding: 0;
3536
font-size: 30rpx;

copilot/Sender/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { Component, triggerEvent, triggerEventOnly } from '../../src/_util/simply';
1+
import { Component, getValueFromProps, triggerEvent, triggerEventOnly } from '../../src/_util/simply';
22
import { SenderProps } from './props';
33

44
Component(SenderProps, {
55
handleMainBtn() {
6-
if (this.props.loading) {
6+
const [ loading ] = getValueFromProps(this, ['loading']);
7+
if (loading) {
78
this.handleCancel();
89
} else {
910
this.handleSubmit();
1011
}
1112
},
1213
handleSubmit() {
13-
triggerEvent(this, 'submit', this.props.value);
14+
const [ value ] = getValueFromProps(this, ['value']);
15+
triggerEvent(this, 'submit', value);
1416
},
1517
handleCancel() {
1618
triggerEventOnly(this, 'cancel');

copilot/Sender/props.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const SenderProps: ISenderProps = {
3838
value: '',
3939
placeholder: '可以问我任何问题~',
4040
disabled: false,
41+
loading: false,
4142
};
4243

4344
export type { ISenderProps };

scripts/axml/mapping.ts

+11
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,15 @@ export const wechatCustomMapping = {
209209
'ant-empty': {
210210
onClickButton: 'bindclickbutton',
211211
},
212+
'ant-actions': {
213+
onItemTap: 'binditemtap',
214+
},
215+
'ant-bubble': {
216+
onTypingComplete: 'bindtypingcomplete',
217+
},
218+
'ant-sender': {
219+
onChange: 'bindchange',
220+
onSubmit: 'bindsubmit',
221+
onCancel: 'bindcancel',
222+
},
212223
};

0 commit comments

Comments
 (0)