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>
  • 相关阅读:
    mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.String'(转)
    Tomcat配置虚拟路径
    FireFox背景亮度修改
    简单的百度贴吧爬虫实现(urllib)
    python知识总结
    QT-- MainWindow外的cpp文件调用ui
    数据结构--栈的实现
    数据结构-- 队列的实现
    经典排序算法---归并排序
    经典排序算法---希尔排序
  • 原文地址:https://www.cnblogs.com/luwei0915/p/13335649.html
Copyright © 2011-2022 走看看