最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)多圖上傳

 更新時間:2020年06月19日 17:17:24   作者:Rechal_Mei  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)多圖上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序?qū)崿F(xiàn)多圖上傳的具體代碼,供大家參考,具體內(nèi)容如下

前言

純屬是筆記,復(fù)用性太高,前后端封裝的上傳的多圖方法

看一下效果圖

index.html

<view class="imgs">
 <block wx:for="{{ imgs }}" wx:key="{{ index }}">
 <view class="img-box">
 <image src="{{ item }}" />
 <icon class="iconfont" size='18px' color="gray" data-index='{{ index }}' bind:tap="close" type='cancel'></icon>
 </view>
 </block>
 <image bind:tap="uploadImg" class="add" src="./upload.png" />
</view>

index.css

/* 上傳照片 */

.imgs {
 margin-top: 20rpx;
 display: flex;
 flex-wrap: wrap;
}

.img-box {
 width: 100rpx;
 height: 100rpx;
 margin: 0 10rpx;
 flex-shink: 0;
 position: relative;
 margin-bottom: 10rpx;
}

.img-box .iconfont {
 position: absolute;
 top: -10rpx;
 right: 3rpx;
 font-size: 16rpx;
 width: 20rpx;
 height: 20rpx;
 line-height: 30rpx;
 text-align: center;
 border-radius: 50%;
 color: #fff;
}

.imgs image {
 width: 100rpx;
 height: 100rpx;
}

.add {
 margin-left: 10rpx;
}

util.js封裝上傳照片的方法

var app = getApp()

// const host = "http://www.xxx.com"
// const host = "http://192.168.1.200"
// const host = "https://work.xxx.cn"
// const host = "http://192.168.1.151"
// const host = "http://192.168.1.9.8083"
// const host ="http://192.168.1.244"
const host = "http://192.168.10.9:8085"http://郭

const formatTime = () => {
 const date = new Date()
 const year = date.getFullYear()
 const month = date.getMonth() + 1
 const day = date.getDate()
 const hour = date.getHours()
 const minute = date.getMinutes()
 return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute].map(formatNumber).join(':')
}


const formatNumber = n => {
 n = n.toString()
 return n[1] ? n : '0' + n
}
function pxToRpx(px) {
 const systemInfo = wx.getSystemInfoSync()
 return px / systemInfo.windowWidth * 750
}

function rpxToPx(rpx) {
 const systemInfo = wx.getSystemInfoSync()
 return rpx / 750 * systemInfo.windowWidth
}

function isBlank(str) {
 //判斷對象是否為空值
 if (Object.prototype.toString.call(str) === '[object Undefined]') { //空
 return true
 } else if (
 Object.prototype.toString.call(str) === '[object String]' ||
 Object.prototype.toString.call(str) === '[object Array]') { //字條串或數(shù)組
 return str.length == 0 ? true : false
 } else if (Object.prototype.toString.call(str) === '[object Object]') {
 return JSON.stringify(str) == '{}' ? true : false
 } else {
 return true
 }

}

**//上傳圖片 //遞歸上傳
function uploadImage(url, filePaths, i = 0, callback) {
 const length = filePaths.length
 wx.showLoading({
 title: '上傳中..',
 mask: true
 })
 wx.uploadFile({
 header: app.globalData.header,
 url: host + url,
 filePath: filePaths[i],
 name: 'file', 
 success: res => {
 callback && callback(res)
 i++ 
 if (i < length) {
 this.uploadImage(url, filePaths, i, callback)
 } else {
 wx.hideLoading()
 wx.showToast({
 title: '上傳完成!',
 })
 }
 },
 fail: res => {
 callback && callback(res)
 wx.hideLoading()
 wx.showToast({
 title: '上傳失敗!',
 icon: 'none'
 })
 }
 })
}**


//生成隨機字符串
function generateMixed(n) {
 var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G']
 var res = "";
 for (var i = 0; i < n; i++) {
 var id = Math.round(Math.random() * (chars.length - 1));
 res += chars[id];
 }
 return res;
}

// 打開地圖選擇器
var getPosition = (that) => {
 wx.chooseLocation({
 success: (res) => {
 var newAddress = {
 addressName: res.name,
 address: res.address,
 latitude: res.latitude, //緯度
 longitude: res.longitude //經(jīng)度 
 }
 that.data.addresses.unshift(newAddress)
 that.setData({
 addresses: that.data.addresses,
 chooseLocation: true
 })
 wx.showToast({
 title: '添加成功',
 icon: 'success'
 })
 }
 })
}

function userInfo() {
 //獲取用戶信息存儲到全局變量
 return new Promise((resolve, failed) => wx.getUserInfo({
 success: res => {
 app.globalData.userInfo = res.userInfo,
 resolve(res)
 },
 fail: err => {
 wx.showToast({
 title: '網(wǎng)絡(luò)錯誤',
 icon: 'none'
 }),
 failed()
 }
 }))
}

function login() {
 return new Promise((resolve, failed) => wx.login({
 success: res => {
 app.globalData.header = {
 "Content-Type": "application/x-www-form-urlencoded",
 "Cookie": 'code=' + res.code,
 },
 resolve(res)
 },
 fail: err => {
 wx.showToast({
 title: '網(wǎng)絡(luò)錯誤',
 icon: 'none'
 }),
 failed()
 }

 }))
}

/**
 * [checkPhone 驗證手機號]
 * @Author tomorrow-here
 * @DateTime 2018-12-20
 * @param {string} phone [要驗證的手機號字符串]
 * @return {boolean} [手機號正確,返回true,否則返回false]
 */
function checkPhone(phone) {
 if (!(/^1[34578]\d{9}$/.test(phone))) {
 wx.showToast({
 title: '請輸入正確的手機號!',
 icon: 'none'
 })
 return false
 } else {
 return true
 }
}


module.exports = {
 formatTime,
 getPosition,
 post,
 get,
 login,
 isBlank,
 userInfo,
 generateMixed,
 uploadImage,
 pxToRpx,
 rpxToPx,
 checkPhone
}

index.js

import {
 uploadImg
} from '../../utils/util.js';
const tool = require("../../utils/util.js")
pages({
data:{
imgs:[],
imgsArr:[],//裝后臺要的數(shù)據(jù)格式
}
 //多圖 圖片上傳
 uploadImg() {
 wx.chooseImage({
 success: res => {
 tool.uploadImage("/returnFileInfo", res.tempFilePaths, 0, (res) => {
 var imgsrc = {
 src: JSON.parse(res.data).path,//后臺返回的事json格式,需要轉(zhuǎn)換
 relateType: 2}
 this.data.imgsArr.push(imgsrc)
 this.setData({
 imgsArr: this.data.imgsArr
 }, () => {
 console.log(this.data.imgsArr, '|imgsrc')
 })
 })
 this.setData({
 imgs: [...this.data.imgs, ...res.tempFilePaths]
 })
 }
 })
 },
 /** 
 * @Author: tomorrow-here 
 * @Date: 2019-1-22
 * @Desc: 刪除圖片 
 */
 close(e) {
 const index = e.currentTarget.dataset.index
 this.data.imgs.splice(index, 1)
 this.setData({
 imgs: this.data.imgs
 })
 },
 })

為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 微信小程序圖片上傳組件實現(xiàn)圖片拖拽排序

    微信小程序圖片上傳組件實現(xiàn)圖片拖拽排序

    最近在寫小程序過程中遇到一個拖拽排序需求,上網(wǎng)一頓搜索未果,遂自行實現(xiàn),下面這篇文章主要給大家介紹了關(guān)于微信小程序圖片上傳組件實現(xiàn)圖片拖拽排序的相關(guān)資料,需要的朋友可以參考下
    2022-03-03
  • javascript 學(xué)習(xí)筆記(onchange等)

    javascript 學(xué)習(xí)筆記(onchange等)

    javascript 學(xué)習(xí)筆記,一些簡單的小技巧,學(xué)習(xí)js的朋友可以看下。
    2010-11-11
  • JavaScript兩種跨域技術(shù)全面介紹

    JavaScript兩種跨域技術(shù)全面介紹

    JavaScript是一種在Web開發(fā)中經(jīng)常使用的前端動態(tài)腳本技術(shù)。在JavaScript中,有一個很重要的安全性限制,被稱為“Same-Origin Policy”(同源策略)
    2014-04-04
  • JsDom 編程小結(jié)

    JsDom 編程小結(jié)

    JsDom編程小結(jié),需要進(jìn)行dom操作的朋友可以參考下。
    2011-08-08
  • JavaScript前端超時異步操作完美解決過程

    JavaScript前端超時異步操作完美解決過程

    這篇文章主要為大家介紹了JavaScript前端超時異步操作的完美解決方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2021-11-11
  • JS實現(xiàn)放煙花效果

    JS實現(xiàn)放煙花效果

    這篇文章主要為大家詳細(xì)介紹了JS實現(xiàn)放煙花效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Bootstrap3多級下拉菜單

    Bootstrap3多級下拉菜單

    這篇文章主要為大家詳細(xì)介紹了Bootstrap3多級下拉菜單的相關(guān)資料,需引用bootstrap.min.css和bootstrap.min.css.js,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • 解決layui中table異步數(shù)據(jù)請求不支持自定義返回數(shù)據(jù)格式的問題

    解決layui中table異步數(shù)據(jù)請求不支持自定義返回數(shù)據(jù)格式的問題

    今天小編就為大家分享一篇解決layui中table異步數(shù)據(jù)請求不支持自定義返回數(shù)據(jù)格式的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 微信小程序支付功能完整流程記錄(前端)

    微信小程序支付功能完整流程記錄(前端)

    微信小程序的商戶系統(tǒng)一般是以接口的形式開發(fā)的,小程序通過調(diào)用與后端約定好的接口進(jìn)行參數(shù)的傳遞以及數(shù)據(jù)的接收,下面這篇文章主要給大家介紹了關(guān)于微信小程序支付功能(前端)的相關(guān)資料,需要的朋友可以參考下
    2023-02-02
  • Javascript操作cookie的函數(shù)代碼

    Javascript操作cookie的函數(shù)代碼

    之前發(fā)布了javascript操作cookie一個大全里面有很多知識,大家可以在本站搜索,另外今天遇到j(luò)s操作cookie又增加2款方法一個是簡單版本、一個是封裝版本,特意分享給大家
    2012-10-10

最新評論

祁门县| 分宜县| 休宁县| 合川市| 绥中县| 麦盖提县| 通江县| 保亭| 安达市| 宣恩县| 石屏县| 黄骅市| 望江县| 高淳县| 普洱| 邯郸县| 墨竹工卡县| 渝北区| 格尔木市| 图们市| 兴安县| 三台县| 嫩江县| 共和县| 都匀市| 辉南县| 上思县| 藁城市| 宾阳县| 洛阳市| 松江区| 安仁县| 太湖县| 东兴市| 屏东县| 隆昌县| 柞水县| 张家界市| 瑞丽市| 金乡县| 赞皇县|