zoukankan      html  css  js  c++  java
  • demo_03 云数据库文件操作

    <template>
        <view>
            首页
            <button type="primary" @click="getList">调用get_list云函数</button>
            <button type="primary" @click="uploadImg">上传图片</button>
            <button type="primary" @click="deleteImg">删除图片</button>
        </view>
    </template>

    <script>
        export default {
            data() {
                return {
                    title: 'Hello'
                }
            },
            onLoad() {
                console.log("页面加载:首页")
            },
            // tarbar 点击触发 可以做页面数据重新渲染的动作
            onTabItemTap(e) {
                console.log(e);
            },
            methods: {
                getList(){
                    uniCloud.callFunction({
                        name:"get_list",
                        data:{
                            // 请求name 为 name1 的数据
                            name: 'name1'
                        },
                        success(res) {
                            console.log(res);
                        },
                        fail(err) {
                            console.log(err)
                        }
                    })
                },
                uploadImg() {
                    new Promise((resolve, reject) => {
                        uni.chooseImage({
                            count: 1,
                            success: res => {
                                const path = res.tempFilePaths[0]
                                console.log('path是:' + path)
                                let ext
                                // #ifdef H5
                                ext = res.tempFiles[0].name.split('.').pop()
                                // #endif
                                // #ifndef H5
                                // 字节跳动小程序ios端选择文件会带query
                                ext = res.tempFilePaths[0].split('?')[0].split('.').pop()
                                // #endif
                                // 图片后缀
                                console.log('ext是:' + ext)
                                const options = {
                                    filePath: path,
                                    cloudPath: Date.now() + '.' + ext
                                }
                                resolve(options)
                            },
                            fail: () => {
                                reject(new Error('Fail_Cancel'))
                            }
                        })
                    }).then((options) => {
                        uni.showLoading({
                            title: '文件上传中...'
                        })
                        return uniCloud.uploadFile({
                            ...options,
                            onUploadProgress(e) {
                                console.log(e)
                            }
                        })
                    }).then(res => {
                        uni.hideLoading()
                        console.log(res);
                        uni.showModal({
                            content: '图片上传成功,fileId为:' + res.fileID,
                            showCancel: false
                        })
                    }).catch((err) => {
                        uni.hideLoading()
                        console.log(err);
                        if (err.message !== 'Fail_Cancel') {
                            uni.showModal({
                                content: `图片上传失败,错误信息为:${err.message}`,
                                showCancel: false
                            })
                        }
                    })
                },
                deleteImg(){
                    uniCloud.deleteFile({
                        fileList:['https://vkceyugu.cdn.bspapp.com/VKCEYUGU-zk-demo/fec169cc-d907-4392-b834-c31da3f6f662.png'],
                        success(res) {
                            console.log(res)
                        },
                        fail(err) {
                            console.log(err)
                        }
                    })
                }
            }
        }
    </script>

    <style>
        
    </style>
  • 相关阅读:
    李开复:如何设计你的2015年度计划(转)
    深入浅出 Java 多线程(转)
    maven常见问题汇总 专题
    Introduction to the Build Lifecycle
    具体解释EBS接口开发之WIP模块接口
    Shell脚本编程具体解释
    [数字图像处理]图像去噪初步(1)--均值滤波器
    hdu-4302-Holedox Eating-线段树-单点更新,有策略的单点查询
    响应式设计:理解设备像素,CSS像素和屏幕分辨率
    #define
  • 原文地址:https://www.cnblogs.com/luwei0915/p/13335649.html
Copyright © 2011-2022 走看看