Skip to content
静心静心
HOME
DoubtfulCases
github icon
  • uniapp开发

    • uniapp 开发微信小程序
      • uniCloud云函数
        • Python 爬取网站中美女图片

        uniapp 开发微信小程序

        author iconYYtimer icon大约 1 分钟

        # uniapp 开发微信小程序

        # 格式化当前日期

         
        async getDate() {
                var t = new Date(),
                  e = (t.getFullYear(), t.getMonth() + 1),
                  o = t.getDate(),
                  a = t.getHours(),
                  n = t.getMinutes(),
                  i = (t.getSeconds(), e + "月" + o + "日"),
                  s = [a, n].map(this.formatNumber).join(":");
                 console.log(i), console.log(s), 
                    this.setData({
                  date: i,
                  time: s
                });
        },
            
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16

        # 用时间来拼凑路径

                        var path = imgs[i].url;
                        var extension = path.substring(path.lastIndexOf('.') + 1)
                        var random = String(Math.random()*100000).split('.')[0]
                        var now = new Date()
                        var year = now.getFullYear()
                        var month = (now.getMonth() + 1) < 10?'0'+(now.getMonth() + 1):(now.getMonth() + 1)
        				var day = now.getDate() < 10?'0'+now.getDate():now.getDate()
        				var hours = now.getHours() < 10?'0'+now.getHours():now.getHours()
        				var minutes = now.getMinutes() < 10?'0'+now.getMinutes():now.getMinutes()
        				var seconds = now.getSeconds() < 10?'0'+now.getSeconds():now.getSeconds()
        				
        				var cloudPath = 								'wall'+'/'+year+'/'+month+'/'+day+'/'+hours+minutes+seconds+'_'+random+'.'+extension
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12

        # 格式化数字为最低报错两位数

         formatNumber: function(t) {
                return (t = t.toString())[1] ? t : "0" + t;
        },
        
        1
        2
        3

        # uniapp 上传图片到uniCloud 云存储

        利用uview写的css部分(具体参数查看uview)

        <u-upload
                ref="uUpload"
                action=""
                max-count="100"
                :file-list="''"
                :auto-upload="false"
                :uploadText="cover.mode == 0 ? '上传壁纸' : '上传图片'"
                :width="cover.mode == 0 ? 203 : 203"
                :height="cover.mode == 0 ? 325 : 203"
                :maxSize="10 * 1024 * 1024"
                :show-progress="false"
                :size-type="['original']"
                :source-type="['album']"
                :multiple="true"
                del-icon="close"
                del-bg-color="#ff7c7c"
                del-color="#FFFFFF"
                :limitType="['png', 'jpg', 'jpeg']"
        ></u-upload>
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19

        JavaScript部分

        async submit() {
            var that = this;
            var imgs = that.$refs.uUpload.lists;
            await uniCloud.uploadFile({
                filePath: path,    	  // 文件路径
                cloudPath: cloudPath  // 存入云存储的路径
            }).then(async res => {
                console.log(res,'resUploadFile')
                await uniCloud.getTempFileURL({    // 根据返回的id 来获取云存储上的路径
                    fileList: [res.fileID]
                }).then(res => {
                    console.log(res,'getTempFileURL')
                    if(res.fileList.length > 0){
                        imgPaths.push(res.fileList[0].tempFileURL)
                    }else{
                        that.$u.toast("图片上传失败");
                        return;
                    }
                });
            })
        }
        
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        edit icon编辑此页open in new window
        下一页
        uniCloud云函数
        傻瓜都能写出计算机可以理解的代码。唯有能写出人类容易理解的代码的,才是优秀的程序员。
        Copyright © 2022 YY

        该应用可以安装在您的 PC 或移动设备上。这将使该 Web 应用程序外观和行为与其他应用程序相同。它将在出现在应用程序列表中,并可以固定到主屏幕,开始菜单或任务栏。此 Web 应用程序还将能够与其他应用程序和您的操作系统安全地进行交互。

        详情