免费国产欧美国日产_少妇AV一区二区三区无码_蜜桃精品av无码喷奶水小说_jk18禁网站视频_精产国品一二三级产品区别_被夫の上司に犯波多野结衣_78m成人手机免费看_最爽最刺激18禁视频_偷偷色噜狠狠狠狠的777米奇

易優(yōu)GEO 重磅上線 ~ 一站式GEO優(yōu)化工具,讓豆包、文心一言、DeepSeek 在回答中主動(dòng)推薦你的品牌,搶占AI流量入口!  點(diǎn)擊查看

小程序模板網(wǎng)

小程序?qū)崿F(xiàn)選擇圖片九宮格帶預(yù)覽

發(fā)布時(shí)間:2017-12-21 09:55 所屬欄目:小程序開發(fā)教程

今天給大家?guī)?span style=" margin: 0px; padding: 0px;">小程序實(shí)現(xiàn)選擇圖片九宮格開發(fā)源碼資源:

效果圖數(shù)據(jù):依賴接口wx.upload、chooseImage與preview 數(shù)據(jù)請(qǐng)求通過LeanCloud完成圖片選擇:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html#wxchooseimageobject前端處理:1.保存images數(shù)組為 ...

效果圖

數(shù)據(jù):

依賴接口wx.upload、chooseImage與preview 數(shù)據(jù)請(qǐng)求通過LeanCloud完成

圖片選擇:

https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html#wxchooseimageobject

前端處理:

1.保存images數(shù)組為已選擇圖片 2.選擇了更多圖片后concat數(shù)組 3.預(yù)覽圖集 4.leancloud上傳多圖,目測順序一致

js代碼

const AV = require('../../../utils/av-weapp.js')
var that;
Page({
    data: {
        images: [],
        uploadedImages: [],
        imageWidth: getApp().screenWidth / 4 - 10
    },
    onLoad: function (options) {
        that = this;
        var objectId = options.objectId;
        console.log(objectId);
    },
    chooseImage: function () {
        // 選擇圖片
        wx.chooseImage({
            sizeType: ['compressed'], 
            sourceType: ['album', 'camera'], // 可以指定來源是相冊(cè)還是相機(jī),默認(rèn)二者都有
            success: function (res) {
                // 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標(biāo)簽的src屬性顯示圖片
                var tempFilePaths = res.tempFilePaths;
                console.log(tempFilePaths);
                that.setData({
                    images: that.data.images.concat(tempFilePaths)
                });
            }
        })
    },
    previewImage: function () {
        // 預(yù)覽圖集
        wx.previewImage({
            urls: that.data.images
        });
    },
    submit: function () {
        // 提交圖片,事先遍歷圖集數(shù)組
        that.data.images.forEach(function (tempFilePath) {
            new AV.File('file-name', {
                blob: {
                    uri: tempFilePath,
                },
            }).save().then(
                // file => console.log(file.url())
                function(file) {
                    // 先讀取
                    var uploadedImages = that.data.uploadedImages;
                    uploadedImages.push(file.url());
                    // 再寫入
                    that.setData({
                        uploadedImages: uploadedImages
                    });
                    console.log(uploadedImages);
                }
            ).catch(console.error);
        });
        wx.showToast({
            title: '評(píng)價(jià)成功',
            success: function () {
                wx.navigateBack();
            }
        });
    },
    delete: function (e) {
        var index = e.currentTarget.dataset.index;
        var images = that.data.images;
        images.splice(index, 1);
        that.setData({
            images: images
        });
    }
})

wxml代碼

<view class="gallery">
    <view class="item" wx:for="{{images}}" wx:key="">
        <image style="width: {{imageWidth}}px; height: {{imageWidth}}px" src=" {{item}}" bindtap="previewImage" mode="aspectFill" />
        <!-- 刪除按鈕 -->
        <view class="delete" bindtap="delete" data-index="{{index}}"><image style="left: {{imageWidth / 2 - 10}}px;" src="/images/icon_delete.png" /></view>
    </view>
    <view class="item">
        <image style="width: {{imageWidth}}px; height: {{imageWidth}}px" src="/images/icon_add.png" class="button-upload" bindtap="chooseImage" />
    </view>
</view>
<button type="primary" bindtap="submit">提交</button>

wxss代碼

/*畫廊*/
.gallery {
    /*margin-bottom: 100rpx;*/
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
}

/*每張圖片所占容器*/
.item {
    position: relative;
    margin: 5px;
}

/*刪除按鈕*/
.delete {
    position: absolute;
    height: 20px;
    bottom: 0;
    width: 100%;
    background: #ccc;
    opacity: .8;
}

.delete image {
    position: absolute;
    width: 20px;
    height: 20px;
}

源碼下載:http://git.oschina.net/dotton/lendoo-wx,本文涉及代碼存于/pages/member/evalute文件夾中。



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://m.szcjxy.com/wxmini/doc/course/18212.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢: 點(diǎn)擊咨詢
在線客服