subscribe-msg-mp
International subscription message component.
Install
npm install subscribe-msg-mp --save
Usage
step 1:
Add the usingComponents configuration to the index.json file to import the subscribe-msg component:
{
"usingComponents": {
"subscribe-msg": "subscribe-msg-mp/es/index"
}
}
step 2:
Call the subscribe-msg component in the index.axml file. The following sample code demonstrates the configuration to show the button and specifies whether to display the authorization panel according to the requestSubscribeMessage attribute:
<view>
<view class="btn-container">
<button onTap="onBtnTap">show</button>
</view>
<subscribe-msg requestSubscribeMessage={{requestSubscribeMessage}} appId="{{appId}}" authCode="{{authCode}}" templateIds={{templateIds}} onCallback="onHandleCallback" />
</view>
step 3:
In the index.js file, set the value of the requestSubscribeMessage attribute as true or false to display or hide the subscription panel. Pass in the handleCallback method and preset logic according to different subscription types (AGREE or REJECT).
Page({
data: {
appId: '${appId}',
authCode: '${authCode}',
templateIds: ${templateIds},
requestSubscribeMessage: false,
},
onBtnTap() {
this.setData({
requestSubscribeMessage: true,
});
},
handleCallback(res) {
this.setData({
requestSubscribeMessage: false,
});
if (res.success) {
my.alert({
title: res.type === 'AGREE' ? 'AGREE' : 'REJECT'
});
} else {
my.alert({
title: 'cancel'
});
}
}
});
Attribute
name | description | type | default |
---|---|---|---|
requestSubscribeMessage | request subscribe message | Boolean | false |
animation | Whether to enable animation | Boolean | true |
authCode | String | ||
templateIds | Array | [] | |
onCallback | Function | ||
theme | custom theme | Theme | {} |
Interface
Theme
name | description | type |
---|---|---|
colorTextPrimary | Primary text color | String |
colorTextSecond | Second text color | String |
colorContentPrimary | Primary content color | String |
colorCheckboxChecked | Checkbox checked color | String |
fontFamilyPrimary | Primary font-family | String |
borderRadiusButtonPrimary | Primary Button border-radius | String |
confirmButtonType | Confirm Button type | String |
Return value Description
success
- indicates whether the subscription action is successful.
- the user clicks Cancel to return false.(Click mask to cancel subscription process, and return errorCode)
- The user clicks Reject to return true.(Click Reject actually performs the subscription process, but the submission type is unsubscribe, so it returns true).
- Other exceptions also return false.
type
- 'AGREE': Agree to subscribe.
- 'REJECT': reject to subscribe.
errorCode
Code | description |
---|---|
CANCELLED | User cancelled |
NETWORK | Network error |
SYSTEM | System error |
INCONSISTENT_TEMPLATE_TYPE | Templates type must be same. |
INVALID_TEMPLATE_CODE | Invalid template code. |
EXCEEDING_SUBSCRIPTION_LIMIT | Templates count out of max bounds. |
INCOMING_EXCEEDED_THE_UPPER_LIMIT | The number of incoming templates exceeded the upper limit. |