W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋: 通過點(diǎn)贊組件,用戶可以對(duì)文章內(nèi)容或者評(píng)論內(nèi)容進(jìn)行點(diǎn)贊,被點(diǎn)贊的用戶可以收到消息通知。更多點(diǎn)贊設(shè)計(jì)指引,詳見 如何提升小程序互動(dòng)體驗(yàn) 。
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 | ||
---|---|---|---|---|---|---|
is-liked | Boolean | 否 | false | 是否已被點(diǎn)贊 | ||
mode | String | 否 | icon | 按鈕模式:icon 表示僅有圖標(biāo); mixture 表示圖標(biāo)文字結(jié)合 | ||
icon-type | String | 否 | hand | 圖標(biāo)類型:hand 表示手形和 heart 表示心形 | ||
style | String | 否 | none | 僅在 mode 為 mixture 時(shí)可配置, none:無邊框;border:有邊框 | ||
like-text | String | 否 | 贊 | 點(diǎn)贊按鈕上的文案,默認(rèn)為贊,僅在 mode 屬性值為’mixture’時(shí)有效 | ||
like-num | Number | 否 | 0 | 點(diǎn)贊數(shù)量 | ||
like-type | Number | 否 | 0 | 被點(diǎn)贊的對(duì)象類型,0 表示對(duì)文章內(nèi)容進(jìn)行點(diǎn)贊; 1 表示對(duì)評(píng)論內(nèi)容進(jìn)行點(diǎn)贊 | ||
animation-type | Number | 否 | 1 | 點(diǎn)贊動(dòng)效形式,0 無動(dòng)效;1 輕動(dòng)效;2 強(qiáng)動(dòng)效 | ||
is-show-toast | Boolean | 否 | false | 點(diǎn)贊后是否彈出 toast 提示 | ||
toast-text | Array | 否 | [‘已點(diǎn)贊’, ‘已取消’] | toast 文案,默認(rèn)為已點(diǎn)贊、已取消 | ||
like-param | Object | 是 | 點(diǎn)贊服務(wù)需要的必要參數(shù) | |||
bind:error | EventHandle | 點(diǎn)擊按鈕時(shí)在用戶未登錄狀態(tài)下觸發(fā)的事件 | ||||
bind:success | EventHandle | 點(diǎn)擊點(diǎn)贊按鈕,在點(diǎn)贊服務(wù)成功后將狀態(tài)返回給使用組件者 | ||||
bind:fail | EventHandle | 點(diǎn)擊點(diǎn)贊按鈕,在點(diǎn)贊服務(wù)失敗后將狀態(tài)返回給使用組件者 |
like-param 點(diǎn)贊服務(wù)參數(shù)說明
snid 和 srid 分別是文章內(nèi)容和評(píng)論內(nèi)容的唯一標(biāo)識(shí),由開發(fā)者創(chuàng)建和維護(hù)。當(dāng)對(duì)文章內(nèi)容進(jìn)行點(diǎn)贊時(shí),只需要填寫 snid;當(dāng)對(duì)文章下某一評(píng)論進(jìn)行點(diǎn)贊時(shí),需要填寫 snid 和 spid。
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 | |||
---|---|---|---|---|---|---|---|
openid | String | 是 | 用戶身份唯一標(biāo)識(shí),獲取方法 | ||||
snid | String | 是 | 被點(diǎn)贊的文章的 id,與 path 參數(shù)一一對(duì)應(yīng),例如值為’20200101’ | ||||
spid | String | 否 | 被點(diǎn)贊的評(píng)論 id | ||||
title | String | 是 | 文章標(biāo)題 | ||||
path | String | 是 | 文章頁面地址,用于消息推送等流量入口跳轉(zhuǎn)回訪,與 snid 參數(shù)一一對(duì)應(yīng),例如/page/home/index?snid=20200101 |
方式一:npm
# 進(jìn)入項(xiàng)目根目錄, 路徑以./projectRoot為例
cd ./projectRoot
# 未安裝過點(diǎn)贊組件
npm install @smt-ui/content-component
# 以前安裝過點(diǎn)贊組件
npm update
{
"usingComponents": {
"smt-like": "@smt-ui/content-component/src/like"
}
}
方式二:動(dòng)態(tài)庫
在 app.json 中引入內(nèi)容服務(wù)組件動(dòng)態(tài)庫
{
"dynamicLib": {
"myDynamicLib": {
"provider": "smart-sc"
}
}
}
在頁面配置 json 文件中,以動(dòng)態(tài)庫方式引入
{
"usingComponents": {
"smt-like": "dynamicLib://myDynamicLib/like"
}
}
<custom chineseName="點(diǎn)贊" engName="like"></custom>
<view class="container">
<view class="card-area">
<view class="top-description border-bottom">圖標(biāo)按鈕樣式</view>
<view class="button-box">
<smt-like
class="custom-class"
like-param="{{likeParam}}"
bind:error="error"
bind:success="clicksucc">
</smt-like>
<smt-like
icon-type="heart"
like-param="{{likeParam}}"
bind:error="error">
</smt-like>
</view>
</view>
<view class="card-area">
<view class="top-description border-bottom">組合按鈕樣式</view>
<view class="button-box button-box-mixture">
<smt-like
class="custom-class-mixture"
mode="mixture"
like-param="{{likeParam}}"
like-text="{{likeText}}"
bind:error="error">
</smt-like>
<smt-like
class="custom-class-mixture"
likeNum="12"
mode="mixture"
icon-type="heart"
like-param="{{likeParam}}"
like-text="{{likeText}}"
bind:error="error">
</smt-like>
<smt-like
class="custom-class-mixture"
mode="mixture"
style="border"
like-param="{{likeParam}}"
like-text="{{likeText}}"
bind:error="error">
</smt-like>
<smt-like
mode="mixture"
likeNum="12"
style="border"
icon-type="heart"
like-param="{{likeParam}}"
bind:error="error">
</smt-like>
</view>
</view>
<view class="card-area">
<view class="top-description border-bottom">動(dòng)效組合樣式1</view>
<view class="button-box button-box-mix">
<view class="button-item">
<smt-like
animation-type="{{0}}"
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
<view class="button-tip">無動(dòng)效</view>
</view>
<view class="button-item">
<smt-like
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
<view class="button-tip">輕動(dòng)效</view>
</view>
<view class="button-item">
<smt-like
animation-type="{{2}}"
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
<view class="button-tip">強(qiáng)動(dòng)效</view>
</view>
</view>
</view>
<view class="card-area">
<view class="top-description border-bottom">動(dòng)效組合樣式2</view>
<view class="button-box button-box-mix">
<view class="button-item">
<smt-like
icon-type="heart"
animation-type="{{0}}"
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
<view class="button-tip">無動(dòng)效</view>
</view>
<view class="button-item">
<smt-like
icon-type="heart"
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
<view class="button-tip">輕動(dòng)效</view>
</view>
<view class="button-item">
<smt-like
icon-type="heart"
animation-type="{{2}}"
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
<view class="button-tip">強(qiáng)動(dòng)效</view>
</view>
</view>
</view>
<view class="card-area">
<view class="top-description border-bottom">點(diǎn)擊提示反饋</view>
<view class="button-box">
<smt-like
is-show-toast="{{true}}"
like-param="{{likeParam}}"
bind:success="clicksucc"
bind:error="error">
</smt-like>
</view>
</view>
<view class="space"></view>
</view>
Page({
data: {
likeParam: {}
},
onLoad() {
const pageStack = getCurrentPages();
const currentPage = pageStack[pageStack.length - 1];
const privateProperties = currentPage.privateProperties || {};
const currentUri = privateProperties.accessUri || currentPage.uri;
const snid = 'test_snid';
this.setData('likeParam', {
snid: snid,
spid: '' + Date.now(),
openid: 'mVMFstfXtsndgnRObr7BoP9hoL',
title: '我是文章標(biāo)題',
path: currentUri + '&snid=' + snid
});
},
error() {
// 處理未登錄
swan.login({
success: res => {
console.log('login success', res);
},
fail: err => {
console.log('login fail', err);
}
});
}
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: