如何获得输入框数字传到云函数里?
发布于 5 年前 作者 hdeng 10667 次浏览 来自 官方Issues

各位大神 我还是在做那个小程序发送邮件的学生 我感觉就差一点了希望得到大佬们的帮助!

我修改了修改云函数 想从从index.js里获得值,贴一下代码!

发送邮件的云函数:(我就是想实时改变邮件的内容,即用户输入一下数据我这就能接受并发到邮箱里)


const cloud = require('wx-server-sdk')
 
cloud.init({
  traceUser: true,
  env: 'wx1c875541493fc5fd'
})
 
var db = cloud.database()
//引入发送邮件的类库
var nodemailer = require('nodemailer')
// 创建一个SMTP客户端配置
var config = {
  host: 'smtp.qq.com'//网易163邮箱 smtp.163.com
  port: 465//网易邮箱端口 25
  auth: {
    user: '[email protected]'//邮箱账号
  }
};
// 创建一个SMTP客户端对象
var transporter = nodemailer.createTransport(config);
// 云函数入口函数
exports.main = async(event, context) => {
const db = cloud.database()    //链接数据库
  // 创建一个邮件对象
  var mail = {
    // 发件人
    from'来自小程序管理员 <[email protected]>',
    // 主题
    subject: '有一位车主拨打了维修店电话',
    // 收件人
    to: '[email protected]',
    // text:'姓名为曹博信的车主拨打了维修厂的电话'
    // 邮件内容,text或者html格式
    text:event.text
  };

  let res = await transporter.sendMail(mail);
  return res;
}


index.js(就是sendEmail函数里!data:{里面的TEXT,到底应该怎么养活的我输入的数字啊wuwu,我贴一下界面)

我这个它显示Undenfinded,不行

Page({
 
  data: {
    text:null
  },
  onLoadfunction (options{
  },

  sendEmail(e){
    this.setData({
      text:e.detail.value
            }),
    wx.cloud.callFunction({
      name:"sendEmail",

      data:{
      text:"asdas"+console.log(this.data.value)
      
      },
      success(res){
        console.log("发送成功",res)
      },
      fail(res){
        console.log("发送失败",res)
      }
    })
  },

  
  formSubmitfunction (e{
    // wx.redirectTo({
    //   url: '/pages/4s/4s',
    // })
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
    var data=e.detail.value
    if (e.detail.value.userName.length <11) {
      wx.navigateTo({
        url'index',
      })
      wx.showToast({
      title'号码应为11位!',
      icon'loading',
      duration5000,
      })      
      }else{
        wx.redirectTo({
          url'/pages/4s/4s',
        })
        wx.showLoading({
          title'数据正在提交中......',
          mask:"true"
        })
  
        const db = wx.cloud.database()
        db.collection('test').add({
        data: data,
        successres => {
          // 在返回结果中会包含新创建的记录的 _id
          this.setData({
            counterId: res._id
          })
          wx.showToast({
            title'新增记录成功',
          })
          wx.hideLoading()
         console.log('[数据库] [新增记录] 成功,记录 _id: ', res._id)
        },
        failerr => {
          wx.showToast({
            icon'none',
            title'新增记录失败'
          })
          console.error('[数据库] [新增记录] 失败:', err)
        }
      })
    }
  },
  //   bindDateChange: function (e) {
  //     console.log('picker发送选择改变,携带值为', e.detail.value)
  //     this.setData({
  //       date: e.detail.value
  //     })
  // },

  wxccall:function(e){
    // wx.redirectTo({
    //   url: '/pages/wxc/wxc',
    // })
    console.log('form发生了submit事件,携带数据为:', e.detail.value)
    var data=e.detail.value
    if (e.detail.value.userName.length <11) {
      wx.navigateTo({
        url'index',
      })
      wx.showToast({
      title'号码应为11位!',
      icon'loading',
      duration5000,
      })      
      }else{
        wx.redirectTo({
          url'/pages/wxc/wxc',
        })
        wx.showLoading({
          title'数据正在提交中......',
          mask:"true"
        })
  
        const db = wx.cloud.database()
        db.collection('test').add({
        data: data,
        successres => {
          // 在返回结果中会包含新创建的记录的 _id
          this.setData({
            counterId: res._id
          })
          wx.showToast({
            title'新增记录成功',
          })
          wx.hideLoading()
         console.log('[数据库] [新增记录] 成功,记录 _id: ', res._id)
        },
        failerr => {
          wx.showToast({
            icon'none',
            title'新增记录失败'
          })
          console.error('[数据库] [新增记录] 失败:', err)
        }
      })
    }
    
   
        wx.showLoading({
          title'数据正在提交中......',
          mask:"true"
        })
  
        const db = wx.cloud.database()
        db.collection('test').add({
        data: data,
        successres => {
          // 在返回结果中会包含新创建的记录的 _id
          this.setData({
            counterId: res._id
          })
          wx.showToast({
            title'请您拨打电话',
          })
          wx.hideLoading()
         console.log('[数据库] [新增记录] 成功,记录 _id: ', res._id)
        },
        failerr => {
          wx.showToast({
            icon'none',
            title'新增记录失败'
          })
          console.error('[数据库] [新增记录] 失败:', err)
        }
      })
    
  },

})


html
<view class="index-wrap">
<image class="index-wrap-img" src="../images/background.png"></image>
<image class="myself1" src="../images/jixiangruyi.png"></image>
<form bindsubmit="formSubmit">
<view data-action="father" class="page-section">
    <view class="weui-cells__title">联系方式:</view>
    <view class="weui-cells weui-cells_after-title">
      <view class="weui-cell weui-cell_input">
        <input class="weui-input" name="userName" placeholder-style="color:##FFFFF" placeholder="请输入您的手机号码" />
      </view>
    </view>
  </view>

  <view class="section section_gap">
    <view class="weui-cells__title">您的爱车坏了,您打算去哪里修车呢?</view>
    <radio-group name="sex">
      <label><radio value="选择4S店修车"/>4S店(推荐)</label>
      <label><radio value="选择维修店修车"/>维修厂</label>
    </radio-group>
  </view>
  <!-- <view class="page-section">
    <view class="weui-cells__title">身高</view>
    <view class="weui-cells weui-cells_after-title">
      <view class="weui-cell weui-cell_input">
        <input class="weui-input" name="hight" type="digit" placeholder="带小数点的数字键盘"/>cm
      </view>
    </view>
  </view>
  <view class="page-section">
    <view class="weui-cells__title">身份证输入的input</view>
    <view class="weui-cells weui-cells_after-title">
      <view class="weui-cell weui-cell_input">
        <input class="weui-input" name="idcard" type="idcard" placeholder="请输入身份证" />
      </view>
    </view>
  </view>
  <view class="section">
  <view class="section__title">出生日期选择</view>
  <picker mode="date" value="{{date}}" name="birthday" start="1990-09-01" end="2017-09-01" bindchange="bindDateChange">
    <view class="picker">
       当前选择: {{date}}
    </view>
  </picker>
</view>
<view class="section">
  <view class="section__title">出生地选择</view>
  <picker mode="region" bindchange="bindRegionChange" name="birthplace" value="{{region}}" custom-item="{{customItem}}">
    <view class="picker">
      当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
    </view>
  </picker>
</view>
  -->
  <button catchtap="sendEmail1" formType="submit">获得4S店电话</button>
  <button catchtap="sendEmail" formType="submit">获得维修厂电话</button>
</form>

<view class="guide" >
   
  
    <div class="nav">
    </div>
  </view>

  <!-- <button bindtap="sendEmail">发送邮件</button> -->
</view>


跪求大佬指点,如何把我输入的值传到sendEmail里的data:{text中!

回到顶部