找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

黄秀杰--小程序实现选择图片九宫格带预览

作者:模板之家 2018-4-21 08:54 7342人关注

效果图 数据: 依赖接口wx.upload、chooseImage与preview 数据请求通过LeanCloud完成 图片选择: https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html#wxchooseimageobject 前端处理: 1.保存images ...

效果图

数据:

依赖接口wx.upload、chooseImage与preview 数据请求通过LeanCloud完成

图片选择:

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

前端处理:

1.保存images数组为已选择图片 2.选择了更多图片后concat数组 3.预览图集 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'], // 可以指定来源是相册还是相机,默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths;
                console.log(tempFilePaths);
                that.setData({
                    images: that.data.images.concat(tempFilePaths)
                });
            }
        })
    },
    previewImage: function () {
        // 预览图集
        wx.previewImage({
            urls: that.data.images
        });
    },
    submit: function () {
        // 提交图片,事先遍历图集数组
        that.data.images.forEach(function (tempFilePath) {
            new AV.File('file-name', {
                blob: {
                    uri: tempFilePath,
                },
            }).save().then(
                // file => console.log(file.url())


路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)