時(shí)間:2023-05-13 21:42:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-05-13 21:42:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)
微信小程序版豆瓣電影:最近,工作沒(méi)有那么忙,終于有時(shí)間學(xué)習(xí)微信小程序的開發(fā)了。學(xué)習(xí)的過(guò)程還是比較順利的,入門相對(duì)簡(jiǎn)單,即便沒(méi)有多少前端開發(fā)經(jīng)驗(yàn)的人也能很快上手。 /** 滑動(dòng)屏幕 */ handleTouchMove: function (event) { var offsetTop = event.target.offsetTop; console.log("handleTouchMove offsetTop: " + offsetTop); if (offsetTop > 10 && !this.data.acquiredSelected) { this.getSelectedListData(); } },
“更多”右側(cè)的箭頭這里并沒(méi)有使用圖標(biāo),而是使用樣式來(lái)實(shí)現(xiàn)的。微信小程序?qū)?app 的體積有限制,超過(guò)1M就不能上傳。其實(shí),不只是微信小程序,網(wǎng)頁(yè)也一樣。能用樣式實(shí)現(xiàn)的就不用字體圖標(biāo);能用字體圖標(biāo)實(shí)現(xiàn)的就不用 sprite 圖;能用 sprite 圖實(shí)現(xiàn)的就不用單一圖標(biāo)。樣式 > 字體圖標(biāo) > sprite 圖 > 單一圖標(biāo),不能說(shuō)是絕對(duì),但基本原則是這樣。這樣做的目的也是為了減少 app 的體積,減少 HTTP 的請(qǐng)求次數(shù),減輕服務(wù)器的壓力。<text class="session-header-more" bindtap="bindMore" data-type-id="intheaters">更多</text>
顯示更多樣式.session-header-more { font-size: 28rpx; color: #32cd32; font-weight: 500; position: relative; padding-right: 20rpx;}.session-header-more::after { content: " "; display: inline-block; position: absolute; top: 50%; width: 12rpx; height: 12rpx; transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0); margin-top: -8rpx; border-width: 2rpx 2rpx 0px 0px; border-color: #32cd32; border-style: solid;}
微信小程序提供了模板功能,可以在模板中定義代碼片段,在不同的地方調(diào)用。模板可以減少重復(fù)性代碼,使代碼結(jié)構(gòu)更加清晰,增強(qiáng)代碼的可讀性,也方便以后維護(hù)代碼。模板粒度的劃分可以根據(jù)頁(yè)面的復(fù)雜度跟組件被重用的頻率。模板可以組合嵌套使用,大的功能組件可以利用模板劃分成更小的功能組件。在電影首頁(yè)中,“影院熱映”,“即將上映”展示的是電影信息列表,可以將電影海報(bào),電影名字,評(píng)分,想看人數(shù)作為一個(gè)大的“組件”抽象出來(lái)形成電影信息塊模板組件。評(píng)分在首頁(yè)電影,更多列表中多次被使用,可以抽象出評(píng)分模板組件。<!--pages/movie/movie-rating/movie-rating-template.wxml--><template name="rating-template"> <view class="rating"> <view class="rating-star allstar{{rating.average | 0}}"></view> <text class="rating-average">{{rating.average}}</text> </view></template>
電影信息塊模板<!--pages/movie/movie-grid/movie-grid-template.wxml--><import src="/pages/movie/movie-rating/movie-rating-template.wxml" /><template name="movie-grid-template"> <view class="movie-wrapper" bindtap="bindMovieDetail" data-id="{{id}}"> <view class="movie-content"> <image class="poster" src="{{images.medium}}"></image> <text class="name">{{title}}</text> <template is="rating-template" data="{{rating}}" /> <text class="wish-count">{{collect_count}}人想看</text> </view> </view></template>
評(píng)分用星星表示不同的分?jǐn)?shù),10分用5星表示,1分顯示半星。這里使用 sprite 圖,可以減少圖片的數(shù)量。在組件樣式中指定圖片位置的偏移量,用于顯示不同的圖標(biāo)。.rating { display: flex; flex-direction: row; position: relative; margin-top: 10rpx; margin-bottom: 10rpx;}.rating-star { content: ""; display: inline-block; width: 55px; height: 11px; position: absolute; background-repeat: no-repeat; background-image: url(/images/icon/ic_rating_s.png);}.allstar10 { background-position: 0px 0px;}.allstar9 { background-position: 0px -11px;}.allstar8 { background-position: 0px -22rpx;}.allstar7 { background-position: 0px -33px;}.allstar6 { background-position: 0px -44px;}.allstar5 { background-position: 0px -55px;}.allstar4 { background-position: 0px -66px;}.allstar3 { background-position: 0px -77px;}.allstar2 { background-position: 0px -88px;}.allstar1 { background-position: 0px -99px;}.allstar0 { background-position: 0px -110px;}.rating-average { margin-left: 120rpx; font-size: 20rpx; line-height: 22rpx; color: #878787; height: 22rpx;}
<!--pages/movie/movie-list/movie-list.wxml--><import src="/pages/movie/movie-rating/movie-rating-template.wxml" /><template name="movie-list-template"> <view class="movie-wrapper" bindtap="bindMovieDetail" data-id="{{id}}"> <view class="movie-content"> <image class="poster" src="{{images.medium}}"></image> <view class="movie-summary"> <text class="name">{{title}}</text> <text class="directors">導(dǎo)演:{{directors}}</text> <text class="casts">主演:{{casts}}</text> <text class="genres">類型:{{genres}}</text> <template is="rating-template" data="{{rating}}" /> <text class="wish-count" style="color:#9bdff9;">{{collectCount}}人想看</text> </view> <block wx:if="{{typeId == 'comingsoon'}}"> <text class="wish-btn" style="color:#de9703;border-color:#de9703" catchtap="handleWishtap">想看</text> </block> <block wx:if="{{typeId == 'intheaters'}}"> <text class="ticket-btn" style="color:#9bdff9;border-color:#9bdff9" catchtap="handleTickettap">購(gòu)票</text> </block> </view> </view></template>
<text class="selected-index">{{index + 1}}</text>
列表序號(hào)樣式.selected-index::before { content: ""; width: 80rpx; border-bottom: 2rpx solid #e9e9e9; box-sizing: border-box; display: inline-block; margin-right: 15rpx; margin-bottom: 10rpx;}.selected-index::after { content: ""; width: 80rpx; border-bottom: 2rpx solid #e9e9e9; box-sizing: border-box; display: inline-block; margin-left: 15rpx; margin-bottom: 10rpx;}.selected-wrapper:first-child .selected-index { color: #e14c63;}.selected-wrapper:nth-child(2) .selected-index { color: #fca167;}.selected-wrapper:nth-child(3) .selected-index { color: #f5c564;}
<icon class="search-icon" type="search" size="16"></icon><input class="search-content" placeholder-class="search-placeholder" bindinput="bindSearchInput" placeholder="搜索電影" value="{{searchValue}}" /><block wx:if="{{showDelete}}"> <text class="search-delete" bindtap="bindSearchDelete">x</text></block><text class="search-cancel" bindtap="bindSearchCancel">取消</text>
使用bindinput獲取輸入框的值/** 搜索影視 */bindSearchInput: function (event) { var value = event.detail.value; var readyData = { showDelete: false }; if (value.length > 0) { readyData = { showDelete: true }; this.handleSearchData(value); } this.setData(readyData);},/**清空輸入框 */bindSearchDelete: function (event) { var readyData = { searchValue: "", showDelete: false, result: {} }; this.setData(readyData);},
bindMark: function (event) { var id = event.target.dataset.id; this.setData({ "mark": id }); },<view class="rating"> <view class="rating-desc"> <text class="desc-text {{mark == 1 ? 'desc-text-show' : ''}}">很差</text> <text class="desc-text {{mark == 2 ? 'desc-text-show' : ''}}">較差</text> <text class="desc-text {{mark == 3 ? 'desc-text-show' : ''}}">還行</text> <text class="desc-text {{mark == 4 ? 'desc-text-show' : ''}}">推薦</text> <text class="desc-text {{mark == 5 ? 'desc-text-show' : ''}}">力薦</text> </view> <view class="rating-stars-wrapper" bindtap="bindMark"> <block wx:for="{{[1,2,3,4,5]}}" wx:for-item="id"> <image class="{{mark >= id ? 'star-HL' : 'star'}}" src="#" data-id="{{id}}"></image> </block> </view> <!-- Don't use sprite, can't give a mark --> <!--<image class="rating-star" bindtap="handleRating" src="#"></image>--></view>
評(píng)分組件樣式.desc-text { width: 32px; height: 22px; font-size: 15px; line-height: 22px; text-align: center; color: #9e9e9e; opacity: 0;}.desc-text-show { opacity: 1;}.star { width: 32px; height: 32px; background: url("/images/icon/ic_rating_star.png") no-repeat;}.star-HL { width: 32px; height: 32px; background: url("/images/icon/ic_rating_star_HL.png") no-repeat;}
這個(gè)項(xiàng)目還是比較簡(jiǎn)單的,前后花了5天的時(shí)間就完成了。所使用的接口是豆瓣電影的公開接口,限定40次請(qǐng)求/分鐘。對(duì)于學(xué)習(xí)來(lái)說(shuō)已經(jīng)足夠了。如果運(yùn)行時(shí)出現(xiàn)400的錯(cuò)誤,是請(qǐng)求過(guò)于頻繁,稍等一會(huì)就好了。關(guān)鍵詞:電影,程序
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。