Compare commits

...

2 Commits

@ -0,0 +1,135 @@
// pages/navigation/index/add/add.js
let app=getApp();
import Toast from './@vant/weapp/toast/toast';
Page({
/**
* 页面的初始数据
*/
 
data: {
name:"",
pattern:"",
kind:"",
style:"",
colour:"",
T:"",
thickness:"",
season:"" ,
url:""
},
cancel()
{
this.setData({ name:"",
pattern:"",
kind:"",
style:"",
colour:"",
T:"",
thickness:"",
season:"" ,
url:""});
},
//提交
submit()
{
console.log("名称",this.data.name)
for(let n in app.globalData.clothes)
{
if(this.data.name==app.globalData.clothes[n].name)
{
Toast.fail('名称重复');
//返回0
return 0;
}
wx.showToast({
title: '添加成功',
})
}
//初始化云
wx.cloud.init({
env:'cloud1-5ggzbo3kcd4ea4e2'
});
//初始化数据库
const db=wx.cloud.database();
let clothes=this.data.clothes;
db.collection('cloth').add({
data: {
name:this.data.name,
pattern:this.data.pattern,
kind:this.data.kind,
style:this.data.style,
colour:this.data.colour,
T:this.data.T,
thickness:this.data.thickness,
season:this.data.season,
url:app.globalData.url
},
sucess:function(res){
console.log(res);
}
})
let s=JSON.stringify(this.data);
app.globalData.clothes.push(JSON.parse(s))
console.log("数据123",this.data,app.globalData.clothes)
this.cancel();
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
 onShareAppMessage() {
  },
  
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText":""
}

@ -0,0 +1,75 @@
<!--pages/navigation/index/add/add.wxml-->
<van-toast id="van-toast" />
<view style="padding:80rpx;">
<van-cell-group>
<van-field clearable
model:value="{{name}}"
label="服装名"
placeholder="请输入服装名"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{pattern}}"
label="模式"
placeholder="请输入模式"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{kind}}"
label="类型"
placeholder="请输入模式"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{style}}"
label="样式"
placeholder="请输入样式"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{colour}}"
label="颜色"
placeholder="请输入颜色"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{T}}"
label="温度"
placeholder="请输入温度"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{thickness}}"
label="厚度"
placeholder="请输入厚度"
/>
</van-cell-group>
<van-cell-group>
<van-field clearable
model:value="{{season}}"
label="季节"
placeholder="请输入季节"
/>
</van-cell-group>
<view style="display: -webkit-flex;display: flex;justify-content: space-between;margin-top:30rpx;">
<van-button round color="#a7a7a7" bindtap="cancel" type="info">取 消</van-button>
<van-button round type="info" bindtap="submit">提 交</van-button>
</view>
</view>

@ -0,0 +1 @@
/* pages/navigation/index/add/add.wxss */

@ -0,0 +1,137 @@
// pages/navigation/index/add/camera/camera.js
Page({
  /**
   * 页面的初始数据
   */
  
  data: {
    src:null
  },
  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
           src: res.tempImagePath
         
        
        })
        console.log(this.data.src)
        var app = getApp();
        app.globalData.url = this.data.src;
      }
    })
    
  },error(e) {
   console.log(e.detail)
  },
  see:function(e){
    var current = e.currentTarget.dataset.src;
    console.log(current);
    
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: [this.data.src],
      
    })
   },
   // 获取图片上传后的url路径
  // addImagePath(fileId) {
  //   console.log("diaoyongla")
  //   console.log(fileId)
  //   wx.cloud.getTempFileURL({
  //     fileList: [fileId],
  //     success: res => {
  //       app.globalData.url = res.fileList[0].tempFileURL
  //     },
  //     fail: console.error
  //   })
 //},
   upload:function(e){
    wx.cloud.uploadFile({
      cloudPath: 'photo/one.jpg', // 上传至云端的路径
      
      filePath: this.data.src, // 小程序临时文件路径
      success: res => {
        // 返回文件 ID
        console.log(res.fileID)
        wx.showToast({
          title: '上传成功',
          icon:'success',
         
        })
        //获取图片的http路径
        //that.addImagePath(res.fileID)
      },
      fail: console.error
    })
   },
   gotoPage: function (options) {
    wx.navigateTo({
          //url: '../add/add',//要跳转到的页面路径
          url:'../add',
 })  
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  }
})
  

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

@ -0,0 +1,14 @@
<!--pages/navigation/index/add/camera/camera.wxml-->
<!--<text>pages/navigation/index/add/camera/camera.wxml<text>-->
<!--camera.wxml-->>
<camera device-postition="back" flash="off" binderror="error" style="width:100%;height:300px;"></camera>
<button type="primary" bindtap="takePhoto">拍照</button>
<view>预览</view>>
<image mode="widthFix" src="{{src}}" bindtap="see"></image>
<button type="primary" bindtap="upload">上传</button>
<button type="primary" bindtap="gotoPage">添加服饰信息</button>

@ -0,0 +1 @@
/* pages/navigation/index/add/camera/camera.wxss */

@ -0,0 +1,127 @@
// pages/navigation/index/delete/delete.js
const db=wx.cloud.database();
let app=getApp();
Page({
/**
* 页面的初始数据
*/
data: {
clothes:[]
},
//定义按钮的事件处理函数
clear(e)
{
var clothes=this.data.clothes
console.log(clothes)
let index=e.currentTarget.dataset.index
console.log(index)
let id=clothes[index]._id
console.log(id)
//界面数据删除
this.data.clothes.splice(e.currentTarget.dataset.index,1);
this.setData({ clothes: this.data.clothes });
console.log('删除成功');
wx.showToast({
title: '删除成功',
})
//初始化云
wx.cloud.init({
env:'cloud1-5ggzbo3kcd4ea4e2'
});
wx.cloud.callFunction({
name:'get',
complete:res=>{
console.log('云函数获取openid:',res.result.openid);
wx.setStorageSync('openid',res.result.openid);
console.log(res);
}
}),
//删除数据库中记录
db.collection('cloth').where({
'_id':id
}).remove({
success: function(res) {
console.log(res.data)
wx.showToast({
title: '删除成功',
})
console.log('数据库删除成功')
}
})
db.collection('cloth').where({
'_id':id
}).get({
success: res =>{
console.log('');
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
db.collection('cloth').get({
success: res =>{
console.log(res.data);
this.setData({
clothes:app.globalData.clothes
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText":""
}

@ -0,0 +1,41 @@
<!--pages/navigation/index/delete/delete.wxml-->
<view>
<view style=" display: -webkit-flex;display: flex;gap:50rpx;justify-content:space-around;" >
<view>
名称
</view>
<view>
模式
</view>
<view>
类型
</view>
<view>
操作
</view>
</view>
<view style="height:90vh;overflow:auto">
<view wx:for="{{clothes}}"wx:for-index="index" wx:for-item="item" wx:key="index" >
<view style=" display: -webkit-flex;display: flex;gap:50rpx;justify-content:space-around;" data-index="{{idx}}" >
<view>
{{item.name}}
</view>
<view>
{{item.pattern}}
</view>
<view>
{{item.kind}}
</view>
<van-icon color="red" name="close" bindtap="clear" data-index='{{index}}' />
</view>
<van-divider />
</view>
</view>
</view>

@ -0,0 +1,6 @@
/* pages/navigation/index/delete/delete.wxss */
Loading…
Cancel
Save