李汶隆吧 关注:9贴子:182
  • 14回复贴,共1

微信小程序学习资料

只看楼主收藏回复

学习


1楼2021-06-29 22:23回复
    云开发配置
    1.修改project.config.json内容
    //第二行增加:"cloudfunctionRoot":"cloud", //配置云开发的路径
    2、更改app.js文件内容,
    // app.jsApp({onLaunch() {// 云开发环境初始化wx.cloud.init({env:"yunjisaun-5gscklsyde3525d6"})}})
    3.新建文件夹为cloud


    2楼2021-06-29 22:28
    回复
      2、商品详情页
      demo1-1.wxml
      <view> 商品名:{{good.name}},价格:{{good.price}}</view>
      demo1-1.js
      // pages/demo1-1/demo1-1.js
      Page({
      onLoad(){
      wx.cloud.database().collection("goods")
      .doc("b00064a7609b87f016c9854a3d397552")
      .get()
      .then(res =>{
      console.log("商品列表请求成功",res)
      this.setData({
      good:res.data
      })
      })
      .catch(res=>{
      console.log("商品列表请求失败",res)
      })
      }
      })


      5楼2021-06-30 10:35
      回复
        3、点击列表中的商品,实现跳转
        demo1.wxml
        <view bindtap="goDetail" data-id="{{item._id}}"> 商品名:{{item.name}},价格:
        {{item.price}}</view>
        demo1.js
        goDetail(e){
        console.log('点击了跳转商品详情',e.currentTarget.dataset.id)
        wx.navigateTo({
        url: '/pages/demo1-1/demo1-1?id=' + e.currentTarget.dataset.id,
        })
        },
        demo1-1.js--点击不同行出现不同的信息
        onLoad(options){
        var id=options.id
        .doc(id)
        }


        6楼2021-06-30 10:37
        回复
          4、添加商品
          新建页面pages/demo-add/demo-add
          demo-add.wxml
          <input placeholder="请输入商品名" bindinput="addName"></input>
          <input placeholder="请输入价格" bindinput="addPrice"></input>
          <button bindtap="addDate" type="primary">添加商品</button>
          demo-add.js
          // pages/demo-add/demo-add.js
          const DB = wx.cloud.database().collection("goods")
          var name
          var price
          var id
          Page({
          addName(e){
          name=e.detail.value
          },
          addPrice(e){
          price=e.detail.value
          },
          // 添加数据
          addDate(){
          if(name==null){ //商品为空时的提示
          wx.showToast({
          icon:'none',
          title: '商品名空了',
          })
          }else if(price==null){
          wx.showToast({
          icon:'none',
          title: '价格空了',
          })
          }else{
          DB.add({
          data:{
          name:name,
          price:price
          },
          success(res){
          console.log("添加成功",res)
          },
          fail(res){
          console.log("添加失败",res)
          }
          })
          }
          },
          })
          demo1.wxml
          <view bindtap="addGoods" class="addprice">添加商品</view>
          demo1.js
          addGoods(){
          wx.navigateTo({
          url: '/pages/demo-add/demo-add',
          })
          },


          7楼2021-06-30 10:41
          回复
            上传文件
            .wxml
            <button bindtap="chooseFile">选择文件</button>
            .js
            Page({
            chooseFile(){
            var that=this
            wx.chooseMessageFile({
            count: 1,
            type: 'all',
            success (res) {
            const tempFilePaths = res.tempFiles
            console.log(tempFilePaths[0])
            that.upload(tempFilePaths[0].path,tempFilePaths[0].name)
            }
            })
            },
            upload(tmpFile){
            wx.cloud.uploadFile({
            cloudPath: '上传的名字',
            filePath: tmpFile,
            success: res => {
            console.log("上传成功",res)
            },
            fail: err => {
            console.log("上传失败",err)
            }
            })
            },
            })
            下载文件并打开
            .wxml
            <view>请输入下载链接</view>
            <input class="lianjie" bindinput="getContent"></input>
            <button bindtap="downLoad">下载</button>
            .wxss
            .lianjie{
            border: 1rpx solid black;
            }
            .js
            Page({
            chooseView(){
            var that=this
            wx.chooseVideo({
            sourceType: ['album','camera'],
            maxDuration: 60,
            camera: 'back',
            success(res) {
            console.log(res.tempFilePath)
            that.uploadView(res.tempFilePath)
            }
            })
            },
            uploadView(tmpFile){
            wx.cloud.uploadFile({
            cloudPath: 'acy.mp4',
            filePath: tmpFile,
            success: res => {
            console.log("上传成功",res)
            },
            fail: err => {
            console.log("上传失败",err)
            }
            })
            },
            chooseFile(){
            var that=this
            wx.chooseMessageFile({
            count: 1,
            type: 'all',
            success (res) {
            const tempFilePaths = res.tempFiles
            console.log(tempFilePaths[0])
            that.upload(tempFilePaths[0].path,tempFilePaths[0].name)
            }
            })
            },
            getContent(e){
            console.log(e.detail.value)
            this.setData({
            fileID:e.detail.value
            })
            },
            downLoad(){
            var fileID
            fileID=this.data.fileID
            console.log("下载链接为:",fileID)
            wx.cloud.downloadFile({
            fileID: fileID,
            success: res => {
            console.log("下载成功",res)
            },
            fail: err => {
            console.log("下载失败",res)
            }
            })
            },
            downLoad(){
            var fileID
            fileID=this.data.fileID
            console.log("下载链接为:",fileID)
            wx.cloud.downloadFile({
            fileID:fileID,
            success:res=>{
            console.log("下载成功",res)
            const filePath = res.tempFilePath
            wx.openDocument({
            filePath: filePath,
            success:function(res){
            console.log('打开文档成功')
            }
            })
            }
            })
            }
            })


            8楼2021-06-30 10:55
            回复
              识别身份证
              card02/index
              const cloud = require('wx-server-sdk')
              cloud.init({
              })
              exports.main = async (event, context) => {
              try {
              const result = await cloud.openapi.ocr.idcard({
              "type": 'photo',
              "imgUrl": event.acy02
              })
              console.log(result)
              return result
              } catch (err) {
              return err
              }
              }
              .wxml
              <button bindtap="shibie">识别身份证</button>
              <view>姓名是:{{name}}</view>
              <view>身份证号是:{{id}}</view>
              <view>性别是:{{gender}}</view>
              .js
              Page({
              shibie(){
              var that=this
              wx.cloud.callFunction({
              name:"card01",
              data:{
              acy01:"下载地址"
              },
              success(res){
              console.log("识别成功",res)
              that.setData({
              name:res.result.name,
              id:res.result.id,
              gender:res.result.gender
              })
              },
              fail(res){
              console.log("识别失败",res)
              },
              })
              },
              })


              9楼2021-06-30 10:55
              回复
                wx35a7ff57185ab700
                配置云开发环境
                "cloudfunctionRoot":"cloud",
                .js
                App({
                onLaunch(){
                wx.cloud.init({
                env:"lhg-2g7jq8bb8504af6c"
                })
                }
                })
                云数据库
                商品详情页
                wxml
                <view wx:for="{{list}}">
                <view> 商品名:{{item.name}},价格:{{item.price}}</view>
                </view>
                .js
                Page({
                onLoad(){
                wx.cloud.database().collection("fruit")//这题只改数据库名字
                .get()
                .then(res =>{
                console.log("商品列表请求成功",res)
                this.setData({
                list:res.data
                })
                })
                .catch(res=>{
                console.log("商品列表请求失败",res)
                })
                },
                })
                上传图片
                新建数据库别忘记更改权限
                上传文件
                .wxml
                <button bindtap="chooseFile">选择文件</button>
                .js
                Page({
                chooseFile(){
                var that=this
                wx.chooseMessageFile({
                count: 1,
                type: 'all',
                success (res) {
                const tempFilePaths = res.tempFiles
                console.log(tempFilePaths[0])
                that.upload(tempFilePaths[0].path,tempFilePaths[0].name)
                }
                })
                },
                upload(tmpFile){
                wx.cloud.uploadFile({
                cloudPath: '上传的名字',//上传给起个名字
                filePath: tmpFile,
                success: res => {
                console.log("上传成功",res)
                },
                fail: err => {
                console.log("上传失败",err)
                }
                })
                },
                })
                下载文件并打开
                .wxml
                <view>请输入下载链接</view>
                <input class="lianjie" bindinput="getContent"></input>
                <button bindtap="downLoad">下载</button>
                .wxss
                .lianjie{
                border: 1rpx solid black;
                }
                .js
                Page({
                chooseView(){
                var that=this
                wx.chooseVideo({
                sourceType: ['album','camera'],
                maxDuration: 60,
                camera: 'back',
                success(res) {
                console.log(res.tempFilePath)
                that.uploadView(res.tempFilePath)
                }
                })
                },
                uploadView(tmpFile){
                wx.cloud.uploadFile({
                cloudPath: 'lhg05',//给下载的文件起个名字
                filePath: tmpFile,
                success: res => {
                console.log("上传成功",res)
                },
                fail: err => {
                console.log("上传失败",err)
                }
                })
                },
                chooseFile(){
                var that=this
                wx.chooseMessageFile({
                count: 1,
                type: 'all',
                success (res) {
                const tempFilePaths = res.tempFiles
                console.log(tempFilePaths[0])
                that.upload(tempFilePaths[0].path,tempFilePaths[0].name)
                }
                })
                },
                getContent(e){
                console.log(e.detail.value)
                this.setData({
                fileID:e.detail.value
                })
                },
                downLoad(){
                var fileID
                fileID=this.data.fileID
                console.log("下载链接为:",fileID)
                wx.cloud.downloadFile({
                fileID: fileID,
                success: res => {
                console.log("下载成功",res)
                },
                fail: err => {
                console.log("下载失败",res)
                }
                })
                },
                downLoad(){
                var fileID
                fileID=this.data.fileID
                console.log("下载链接为:",fileID)
                wx.cloud.downloadFile({
                fileID:fileID,
                success:res=>{
                console.log("下载成功",res)
                const filePath = res.tempFilePath
                wx.openDocument({
                filePath: filePath,
                success:function(res){
                console.log('打开文档成功')
                }
                })
                }
                })
                }
                })
                识别身份证
                先创建card02
                card02/index
                const cloud = require('wx-server-sdk')
                cloud.init({
                })
                exports.main = async (event, context) => {
                try {
                const result = await cloud.openapi.ocr.idcard({
                "type": 'photo',
                "imgUrl": event.lhg05//改名字
                })
                console.log(result)
                return result
                } catch (err) {
                return err
                }
                }
                .wxml
                <button bindtap="shibie">识别身份证</button>
                <view>姓名是:{{name}}</view>
                <view>身份证号是:{{id}}</view>
                <view>性别是:{{gender}}</view>
                .js
                Page({
                shibie(){
                var that=this
                wx.cloud.callFunction({
                name:"card01",//跟创建的card名字一样
                data:{
                acy01:"下载地址"//跟index.js名字一样,并复制身份证链接
                },
                success(res){
                console.log("识别成功",res)
                that.setData({
                name:res.result.name,
                id:res.result.id,
                gender:res.result.gender
                })
                },
                fail(res){
                console.log("识别失败",res)
                },
                })
                },
                })
                添加商品
                .wxml
                <input placeholder="请输入商品名" bindinput="addName"></input>
                <input placeholder="请输入价格" bindinput="addPrice"></input>
                <button bindtap="addDate" type="primary">添加商品</button>
                .js
                const DB=wx.cloud.database().collection("haha")
                var name
                var price
                var id
                Page({
                addName(e){
                name=e.detail.value
                },
                addPrice(e){
                price=e.detail.value
                },
                addDate(){
                if(name==null){
                wx.showToast({
                icon:'none',
                title:'商品名空了',
                })
                }else if(price==null){
                wx.showToast({
                icon:'none',
                title:'价格空了'
                })
                }else{
                DB.add({
                data:{
                name:name,
                price:price
                },
                success(res){
                console.log("添加成功",res)
                },
                fail(res){
                console.log("添加失败",res)
                }
                })
                }
                }
                })
                删除商品
                .wxml
                <input placeholder="请输入ID" bindinput="delDataInput"></input>
                <button bindtap="delData" type="primary">删除数据</button>
                .js
                var id
                Page({
                delDataInput(e){
                id=e.detail.value
                console.log(id)
                },
                delData(){
                wx.cloud.database().collection("haha")
                .doc(id).remove()
                .then(res => {
                console.log("删除成功",res)
                })
                .catch(err =>{
                console.log("删除失败",err)
                })
                },
                })


                10楼2021-06-30 11:00
                回复
                  魏大林是**


                  IP属地:北京11楼2021-06-30 11:19
                  收起回复
                    我是赵庆,我看到你们了


                    IP属地:北京12楼2021-06-30 21:18
                    收起回复
                      wx.chooseImage({
                      count: 1,
                      sizeType: ['original', 'compressed'],
                      sourceType: ['album', 'camera'],
                      success (res) { // tempFilePath可以作为img标签的src属性显示图片
                      const tempFilePaths = res.tempFilePaths }
                      })


                      IP属地:北京13楼2021-07-01 09:10
                      回复
                        实验1:“商品详情页展示图片
                        demo.wxml
                        <!--pages/demo/demo.wxml-->
                        <view wx:for="{{list}}" >
                        <image src="{{item.img}}" class="img"></image>
                        <view> 商品名:{{item.name}},价格:{{item.price}}</view>
                        </view>
                        demo.wxss
                        /* pages/demo/demo.wxss */
                        .img{
                        width: 200rpx;
                        height:200rpx;
                        }
                        demo.js(与之前内容一样)
                        Page({
                        onLoad(){
                        wx.cloud.database().collection("goods")
                        .get()
                        .then(res =>{
                        console.log("商品列表请求成功",res)
                        this.setData({
                        list:res.data
                        })
                        })
                        .catch(res=>{
                        console.log("商品列表请求失败",res)
                        })
                        },
                        })
                        -------
                        实现照片js
                        // pages/yuncunchu/yuncunchu.js
                        Page({
                        choose(){
                        var that=this
                        wx.chooseImage({ //选择图片
                        count: 1, //上传数量
                        sizeType: ['original', 'compressed'],
                        sourceType: ['album', 'camera'],
                        success (res) {
                        console.log(res)
                        // tempFilePath可以作为img标签的src属性显示图片
                        const tempFilePaths = res.tempFilePaths
                        that.upload(tempFilePaths[0])
                        }
                        })
                        },
                        upload(tmpFile){
                        wx.cloud.uploadFile({ //上传图片
                        cloudPath: 'example.png',
                        filePath: tmpFile, // 文件路径
                        success: res => {
                        // get resource ID
                        console.log("上传成功",res)
                        },
                        fail: err => {
                        // handle error
                        console.log("上传失败",err)
                        }
                        })
                        },
                        })


                        14楼2021-07-01 09:16
                        回复
                          wx16d660a8f41a4f09
                          gzddengh


                          15楼2021-07-01 09:37
                          回复