|
@@ -1,7 +1,12 @@
|
|
|
-import WxValidate from '../../utils/WxValidate.js'
|
|
|
+import WxValidate from '../../utils/WxValidate.js';
|
|
|
+const app = require('../../utils/util.js');
|
|
|
+const request = require('../../utils/request.js');
|
|
|
+const COS = require('../../utils/cos.js');
|
|
|
+const tool = require('../../utils/tool.js');
|
|
|
Page({
|
|
|
data: {
|
|
|
form: {
|
|
|
+ phone: '',
|
|
|
height: '',
|
|
|
weight: '',
|
|
|
education: '',
|
|
@@ -22,57 +27,18 @@ Page({
|
|
|
parents: '',
|
|
|
fatherWork: '',
|
|
|
motherWork: '',
|
|
|
+ parentAssets:'',
|
|
|
composition: '',
|
|
|
motionState: '',
|
|
|
- hobby: ''
|
|
|
+ hobby: '',
|
|
|
+ photo: ''
|
|
|
},
|
|
|
- heightArr: [
|
|
|
- '150以下',
|
|
|
- '150-155',
|
|
|
- '155-160',
|
|
|
- '160-165',
|
|
|
- '165-170',
|
|
|
- '170-175',
|
|
|
- '175-185',
|
|
|
- '185-190',
|
|
|
- '190以上'
|
|
|
- ],
|
|
|
- weightArr: [
|
|
|
- "50kg以下", "50-60", "60-70", "70-80", "80-90", "90-100", "100以上"
|
|
|
- ],
|
|
|
- educationArr: ["初中", "中专", "高中", "大专", "本科", "硕士", "博士"],
|
|
|
- incomeArr: ["2000-5000", "5000-10000", "10000-20000", "20000以上"],
|
|
|
- marriageList: [{
|
|
|
- name: '未婚',
|
|
|
- value: '未婚',
|
|
|
- checked: true
|
|
|
- },
|
|
|
- {
|
|
|
- name: '离异',
|
|
|
- value: '离异',
|
|
|
- checked: false
|
|
|
- }
|
|
|
- ],
|
|
|
- childrenArr: [{
|
|
|
- name: '无',
|
|
|
- value: '无',
|
|
|
- checked: true
|
|
|
- },
|
|
|
- {
|
|
|
- name: '有',
|
|
|
- value: '有',
|
|
|
- checked: false
|
|
|
- }, {
|
|
|
- name: '同住',
|
|
|
- value: '同住',
|
|
|
- checked: false
|
|
|
- },
|
|
|
- {
|
|
|
- name: '不同住',
|
|
|
- value: '不同住',
|
|
|
- checked: false
|
|
|
- }
|
|
|
- ],
|
|
|
+ heightArr: [],
|
|
|
+ weightArr: [],
|
|
|
+ educationArr: [],
|
|
|
+ incomeArr: [],
|
|
|
+ marriageList: [],
|
|
|
+ childrenArr: [],
|
|
|
deposit: '',
|
|
|
assetHouseArr: ['租房', '购房'],
|
|
|
assetAreaArr: ['80平以下', '80-120平', '120平以上'],
|
|
@@ -100,44 +66,13 @@ Page({
|
|
|
checked: false
|
|
|
}
|
|
|
],
|
|
|
- // 工作时间自由、朝九晚五、偶尔加班、经常加班、偶尔出差、经常出差、常有应酬
|
|
|
- workStatusArr: [{
|
|
|
- name: '工作时间自由',
|
|
|
- value: '工作时间自由',
|
|
|
- checked: true
|
|
|
- },
|
|
|
- {
|
|
|
- name: '朝九晚五',
|
|
|
- value: '朝九晚五',
|
|
|
- checked: false
|
|
|
- }, {
|
|
|
- name: '偶尔加班',
|
|
|
- value: '偶尔加班',
|
|
|
- checked: false
|
|
|
- }, {
|
|
|
- name: '经常加班',
|
|
|
- value: '经常加班',
|
|
|
- checked: false
|
|
|
- },
|
|
|
- {
|
|
|
- name: '偶尔出差',
|
|
|
- value: '偶尔出差',
|
|
|
- checked: false
|
|
|
- }, {
|
|
|
- name: '经常出差',
|
|
|
- value: '经常出差',
|
|
|
- checked: false
|
|
|
- }, {
|
|
|
- name: '常有应酬',
|
|
|
- value: '常有应酬',
|
|
|
- checked: false
|
|
|
- }
|
|
|
- ],
|
|
|
- workplaceArr: ['政府机关', '事业单位', '外企企业', '世界500强', '上市公司', '国有企业', '私营企业', '个体'],
|
|
|
+ workStatusArr: [],
|
|
|
+ companyNatureArr: [],
|
|
|
parentsArr: ['爹妈比我都健康,一直很恩爱', '爹妈比我都健康,离婚了', '世事无常'],
|
|
|
- dadworkplaceArr: ['退休', '政府机关', '事业单位', '外企企业', '世界500强', '上市公司', '国有企业', '私营企业', '个体'],
|
|
|
- momworkplaceArr: ['退休', '政府机关', '事业单位', '外企企业', '世界500强', '上市公司', '国有企业', '私营企业', '个体'],
|
|
|
- otherchildArr: [{
|
|
|
+ fatherWorkArr: ['退休', '政府机关', '事业单位', '外企企业', '世界500强', '上市公司', '国有企业', '私营企业', '个体'],
|
|
|
+ motherWorkArr: ['退休', '政府机关', '事业单位', '外企企业', '世界500强', '上市公司', '国有企业', '私营企业', '个体'],
|
|
|
+ parentAssetsArr:[],
|
|
|
+ compositionArr: [{
|
|
|
name: '没有唯我独尊',
|
|
|
value: '没有唯我独尊',
|
|
|
checked: false
|
|
@@ -186,7 +121,7 @@ Page({
|
|
|
[income]: this.data.incomeArr[e.detail.value]
|
|
|
})
|
|
|
},
|
|
|
- marriageChange: function (e) {
|
|
|
+ marriageChange(e) {
|
|
|
console.log(e.detail.value)
|
|
|
const items = this.data.marriageList
|
|
|
let checked = 'marriageList[0].checked';
|
|
@@ -209,7 +144,7 @@ Page({
|
|
|
[marriage]: e.detail.value
|
|
|
})
|
|
|
},
|
|
|
- childrenChange: function (e) {
|
|
|
+ childrenChange (e) {
|
|
|
console.log(e.detail.value)
|
|
|
const items = this.data.childrenArr;
|
|
|
const values = e.detail.value;
|
|
@@ -320,7 +255,7 @@ Page({
|
|
|
[workStatus]: e.detail.value
|
|
|
})
|
|
|
},
|
|
|
- workplacePicker: function (e) {
|
|
|
+ workplacePicker (e) {
|
|
|
let companyNature = 'form.companyNature'
|
|
|
this.setData({
|
|
|
[companyNature]: this.data.workplaceArr[e.detail.value]
|
|
@@ -332,19 +267,25 @@ Page({
|
|
|
[parents]: this.data.parentsArr[e.detail.value]
|
|
|
})
|
|
|
},
|
|
|
- dadworkplacePicker: function (e) {
|
|
|
+ fatherworkPicker (e) {
|
|
|
let fatherWork = 'form.fatherWork'
|
|
|
this.setData({
|
|
|
[fatherWork]: this.data.dadworkplaceArr[e.detail.value]
|
|
|
})
|
|
|
},
|
|
|
- momworkplacePicker: function (e) {
|
|
|
+ motherworkPicker (e) {
|
|
|
let motherWork = 'form.motherWork'
|
|
|
this.setData({
|
|
|
[motherWork]: this.data.momworkplaceArr[e.detail.value]
|
|
|
})
|
|
|
},
|
|
|
- otherchildChange: function (e) {
|
|
|
+ parentAssetsPicker(e){
|
|
|
+ let parentAssets = 'form.parentAssets'
|
|
|
+ this.setData({
|
|
|
+ [parentAssets]: this.data.parentAssetsArr[e.detail.value]
|
|
|
+ })
|
|
|
+ },
|
|
|
+ compositionChange(e) {
|
|
|
console.log(e.detail.value)
|
|
|
const items = this.data.otherchildArr;
|
|
|
const values = e.detail.value;
|
|
@@ -365,13 +306,13 @@ Page({
|
|
|
[composition]: e.detail.value
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
figurePicker(e) {
|
|
|
let motionState = 'form.motionState'
|
|
|
this.setData({
|
|
|
[motionState]: this.data.figureArr[e.detail.value]
|
|
|
})
|
|
|
},
|
|
|
+ // 提交
|
|
|
formSubmit(e) {
|
|
|
const params = e.detail.value
|
|
|
//校验表单
|
|
@@ -380,8 +321,26 @@ Page({
|
|
|
this.showModal(error)
|
|
|
return false
|
|
|
}
|
|
|
- wx.navigateTo({
|
|
|
- url: '/pages/targetInfo/targetInfo',
|
|
|
+ wx.request({
|
|
|
+ url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/info',
|
|
|
+ method: "POST",
|
|
|
+ data: params,
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res)
|
|
|
+ if (res.data.code == 0) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '上传成功',
|
|
|
+ showCancel: false,
|
|
|
+ success(res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/targetInfo/targetInfo',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
//报错
|
|
@@ -394,222 +353,426 @@ Page({
|
|
|
//验证函数
|
|
|
initValidate() {
|
|
|
const rules = {
|
|
|
+ phone: {
|
|
|
+ required: true
|
|
|
+ },
|
|
|
height: {
|
|
|
required: true
|
|
|
},
|
|
|
- weight: {
|
|
|
+ weight: {
|
|
|
required: true
|
|
|
},
|
|
|
- education: {
|
|
|
+ education: {
|
|
|
required: true
|
|
|
},
|
|
|
- income: {
|
|
|
+ income: {
|
|
|
required: true
|
|
|
},
|
|
|
- marriage: {
|
|
|
+ marriage: {
|
|
|
required: true
|
|
|
},
|
|
|
- children: {
|
|
|
+ children: {
|
|
|
required: true
|
|
|
},
|
|
|
- assetHouse: {
|
|
|
+ assetHouse: {
|
|
|
required: true
|
|
|
},
|
|
|
- assetArea: {
|
|
|
+ assetArea: {
|
|
|
required: true
|
|
|
},
|
|
|
- assetHouseLoan: {
|
|
|
+ assetHouseLoan: {
|
|
|
required: true
|
|
|
},
|
|
|
- assetCar: {
|
|
|
+ assetCar: {
|
|
|
required: true
|
|
|
},
|
|
|
- assetCarValue: {
|
|
|
+ assetCarValue: {
|
|
|
required: true
|
|
|
},
|
|
|
- assetCarLoan: {
|
|
|
+ assetCarLoan: {
|
|
|
required: true
|
|
|
},
|
|
|
- isCommen: {
|
|
|
+ isCommen: {
|
|
|
required: true
|
|
|
},
|
|
|
- controlTime: {
|
|
|
+ controlTime: {
|
|
|
required: true
|
|
|
},
|
|
|
- workStatus: {
|
|
|
+ workStatus: {
|
|
|
required: true
|
|
|
},
|
|
|
- companyNature: {
|
|
|
+ companyNature: {
|
|
|
required: true
|
|
|
},
|
|
|
- company: {
|
|
|
+ company: {
|
|
|
required: true
|
|
|
},
|
|
|
- parents: {
|
|
|
+ parents: {
|
|
|
required: true
|
|
|
},
|
|
|
- // fatherWork: {
|
|
|
- // required: true
|
|
|
- // },
|
|
|
- // motherWork: {
|
|
|
- // required: true
|
|
|
- // },
|
|
|
- composition: {
|
|
|
+ composition: {
|
|
|
required: true
|
|
|
},
|
|
|
- motionState: {
|
|
|
+ motionState: {
|
|
|
required: true
|
|
|
},
|
|
|
- hobby: {
|
|
|
+ hobby: {
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ photo: {
|
|
|
required: true
|
|
|
}
|
|
|
}
|
|
|
const messages = {
|
|
|
- // name: {
|
|
|
- // required: '请填写姓名',
|
|
|
- // minlength: '请输入正确的名称',
|
|
|
- // maxlength: '请输入正确的名称'
|
|
|
- // },
|
|
|
- // sex: {
|
|
|
- // required: '请选择性别'
|
|
|
- // },
|
|
|
- // age: {
|
|
|
- // required: '请填写年龄'
|
|
|
- // },
|
|
|
- // nativePlace: {
|
|
|
- // required: '请填写户籍地址'
|
|
|
- // },
|
|
|
- // nation: {
|
|
|
- // required: '请选择民族'
|
|
|
- // },
|
|
|
- // birthday: {
|
|
|
- // required: '请填写生日'
|
|
|
- // },
|
|
|
- // constellation: {
|
|
|
- // required: '请选择星座'
|
|
|
- // }
|
|
|
+ phone: {
|
|
|
+ required: '请输入联系方式'
|
|
|
+ },
|
|
|
height: {
|
|
|
required: '请选择身高'
|
|
|
},
|
|
|
- weight: {
|
|
|
+ weight: {
|
|
|
required: '请选择体重'
|
|
|
},
|
|
|
- education: {
|
|
|
+ education: {
|
|
|
required: '请选择教育程度'
|
|
|
},
|
|
|
- income: {
|
|
|
+ income: {
|
|
|
required: '请选择收入'
|
|
|
},
|
|
|
- marriage: {
|
|
|
+ marriage: {
|
|
|
required: '请选择婚姻状态'
|
|
|
},
|
|
|
- children: {
|
|
|
+ children: {
|
|
|
required: '请选择有没有孩子'
|
|
|
},
|
|
|
- assetHouse: {
|
|
|
+ assetHouse: {
|
|
|
required: '请选择是否买房子'
|
|
|
},
|
|
|
- assetArea: {
|
|
|
+ assetArea: {
|
|
|
required: '请选择房子多大面积'
|
|
|
},
|
|
|
- assetHouseLoan: {
|
|
|
+ assetHouseLoan: {
|
|
|
required: '请选择房子贷款了没'
|
|
|
},
|
|
|
- assetCar: {
|
|
|
+ assetCar: {
|
|
|
required: '请选择车子情况'
|
|
|
},
|
|
|
- assetCarValue: {
|
|
|
+ assetCarValue: {
|
|
|
required: '请选择车子的价值'
|
|
|
},
|
|
|
- assetCarLoan: {
|
|
|
+ assetCarLoan: {
|
|
|
required: '请选择车子贷款了没'
|
|
|
},
|
|
|
- isCommen: {
|
|
|
+ isCommen: {
|
|
|
required: '请选择是否与父母同住'
|
|
|
},
|
|
|
- controlTime: {
|
|
|
+ controlTime: {
|
|
|
required: '请选择您的空闲时间'
|
|
|
},
|
|
|
- workStatus: {
|
|
|
+ workStatus: {
|
|
|
required: '请选择您的工作状态'
|
|
|
},
|
|
|
- companyNature: {
|
|
|
+ companyNature: {
|
|
|
required: '请选择您的单位性质'
|
|
|
},
|
|
|
- company: {
|
|
|
+ company: {
|
|
|
required: '请输入您的单位具体名称'
|
|
|
},
|
|
|
- parents: {
|
|
|
+ parents: {
|
|
|
required: '请选择您的父母情况'
|
|
|
},
|
|
|
- // fatherWork: {
|
|
|
- // required:
|
|
|
- // },
|
|
|
- // motherWork: {
|
|
|
- // required:
|
|
|
- // },
|
|
|
- composition: {
|
|
|
+ composition: {
|
|
|
required: '请选择有没有兄弟姐妹'
|
|
|
},
|
|
|
- motionState: {
|
|
|
+ motionState: {
|
|
|
required: '请选择您是否喜欢运动'
|
|
|
},
|
|
|
- hobby: {
|
|
|
+ hobby: {
|
|
|
required: '请填写您的爱好'
|
|
|
+ },
|
|
|
+ photo: {
|
|
|
+ required: '请上传您的照片'
|
|
|
}
|
|
|
}
|
|
|
this.WxValidate = new WxValidate(rules, messages)
|
|
|
},
|
|
|
- onLoad: function (options) {
|
|
|
- this.initValidate()
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
- */
|
|
|
- onHide: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload: function () {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh: function () {
|
|
|
-
|
|
|
+ async onLoad(options) {
|
|
|
+ this.initValidate();
|
|
|
+ const getOpenid = await tool.openidStatus();
|
|
|
+ this.setData({
|
|
|
+ openid: getOpenid[0],
|
|
|
+ sessionkey: getOpenid[1]
|
|
|
+ })
|
|
|
+ tool.formDetails('he_body_height').then(result => {
|
|
|
+ this.setData({
|
|
|
+ heightArr: result[0],
|
|
|
+ heightArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_body_weight').then(result => {
|
|
|
+ this.setData({
|
|
|
+ weightArr: result[0],
|
|
|
+ weightArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_education').then(result => {
|
|
|
+ this.setData({
|
|
|
+ educationArr: result[0],
|
|
|
+ educationArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_income').then(result => {
|
|
|
+ this.setData({
|
|
|
+ incomeArr: result[0],
|
|
|
+ incomeArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_marriage').then(result => {
|
|
|
+ let marriageList = result[0].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ let marriageListValue = result[1].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ marriageList:marriageList,
|
|
|
+ marriageListValue: marriageListValue
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_children').then(result => {
|
|
|
+ let childrenArr = result[0].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ let childrenArrValue = result[1].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ childrenArr: childrenArr,
|
|
|
+ childrenArrValue: childrenArrValue
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_control_time').then(result => {
|
|
|
+ let controlTimeArr = result[0].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ let controlTimeArrValue = result[1].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ controlTimeArr: controlTimeArr,
|
|
|
+ controlTimeArrValue: controlTimeArrValue
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_work_status').then(result => {
|
|
|
+ let workStatusArr = result[0].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ let workStatusArrValue = result[1].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ workStatusArr: workStatusArr,
|
|
|
+ workStatusArrValue: workStatusArrValue
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_company_nature').then(result => {
|
|
|
+ this.setData({
|
|
|
+ companyNatureArr: result[0],
|
|
|
+ companyNatureArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_parents').then(result => {
|
|
|
+ this.setData({
|
|
|
+ parentsArr: result[0],
|
|
|
+ parentsArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_father_work').then(result => {
|
|
|
+ this.setData({
|
|
|
+ fatherWorkArr: result[0],
|
|
|
+ fatherWorkArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_mother_work').then(result => {
|
|
|
+ this.setData({
|
|
|
+ motherWorkArr: result[0],
|
|
|
+ motherWorkArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_parent_assets').then(result => {
|
|
|
+ this.setData({
|
|
|
+ parentAssetsArr: result[0],
|
|
|
+ parentAssetsArrValue: result[1]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ tool.formDetails('he_composition').then(result => {
|
|
|
+ let compositionArr = result[0].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ let compositionArrValue = result[1].map((item, index) => {
|
|
|
+ return Object.assign({}, {
|
|
|
+ 'name': item,
|
|
|
+ 'value':item,
|
|
|
+ 'checked':false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ compositionArr: compositionArr,
|
|
|
+ compositionArrValue: compositionArrValue
|
|
|
+ })
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom: function () {
|
|
|
-
|
|
|
+ // 上传头像
|
|
|
+ uploadPhoto() {
|
|
|
+ wx.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['original', 'compressed'],
|
|
|
+ sourceType: ['', 'camera'],
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res)
|
|
|
+ let path = res.tempFilePaths[0];
|
|
|
+ console.log(path)
|
|
|
+ this.setData({
|
|
|
+ carWin_img: path
|
|
|
+ })
|
|
|
+ this.toCos();
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage: function () {
|
|
|
-
|
|
|
+ // 传cos
|
|
|
+ toCos() {
|
|
|
+ var Bucket = 'yuehe-1257653330';
|
|
|
+ var Region = 'ap-beijing';
|
|
|
+ var ForcePathStyle = false;
|
|
|
+ var prefix = 'https://' + Bucket + '.cos.' + Region + '.myqcloud.com/';
|
|
|
+ if (ForcePathStyle) {
|
|
|
+ prefix = 'https://cos.' + Region + '.myqcloud.com/' + Bucket + '/';
|
|
|
+ }
|
|
|
+ var stsCache;
|
|
|
+ var getCredentials = function (callback) {
|
|
|
+ if (stsCache && Date.now() / 1000 + 30 < stsCache.expiredTime) {
|
|
|
+ callback(data.credentials);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ wx.request({
|
|
|
+ method: 'POST',
|
|
|
+ url: app.globalData.publicUrl + '/wx/member/' + this.data.openid + '/getCosSts',
|
|
|
+ // dataType: 'json',
|
|
|
+ success: function (result) {
|
|
|
+ console.log(result, '222222222222')
|
|
|
+ var credentials = result.data.credential.credentials;
|
|
|
+ if (credentials) {
|
|
|
+ stsCache = result.data.credential
|
|
|
+ } else {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showModal({
|
|
|
+ title: '临时密钥获取失败',
|
|
|
+ content: JSON.stringify(data),
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ callback(stsCache && stsCache.credentials);
|
|
|
+ },
|
|
|
+ error: function (err) {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showModal({
|
|
|
+ title: '临时密钥获取失败',
|
|
|
+ content: JSON.stringify(err),
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 计算签名
|
|
|
+ var getAuthorization = function (options, callback) {
|
|
|
+ getCredentials(function (credentials) {
|
|
|
+ callback({
|
|
|
+ XCosSecurityToken: credentials.sessionToken,
|
|
|
+ Authorization: COS({
|
|
|
+ SecretId: credentials.tmpSecretId,
|
|
|
+ SecretKey: credentials.tmpSecretKey,
|
|
|
+ Method: options.Method,
|
|
|
+ Pathname: options.Pathname,
|
|
|
+ })
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+ // 上传文件
|
|
|
+ var Key = this.data.carWin_img.substr(this.data.carWin_img.lastIndexOf('/') + 1); // 这里指定上传的文件名
|
|
|
+ var signPathname = '/';
|
|
|
+ if (ForcePathStyle) {
|
|
|
+ signPathname = '/' + Bucket + '/';
|
|
|
+ }
|
|
|
+ getAuthorization({
|
|
|
+ Method: 'POST',
|
|
|
+ Pathname: signPathname
|
|
|
+ }, (AuthData) => {
|
|
|
+ var requestTask = wx.uploadFile({
|
|
|
+ url: prefix,
|
|
|
+ name: 'file',
|
|
|
+ filePath: this.data.carWin_img,
|
|
|
+ formData: {
|
|
|
+ 'key': "face/" + Key,
|
|
|
+ 'success_action_status': 200,
|
|
|
+ 'Signature': AuthData.Authorization,
|
|
|
+ 'x-cos-security-token': AuthData.XCosSecurityToken,
|
|
|
+ 'Content-Type': '',
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res.header.Location)
|
|
|
+ let photo = 'form.photo'
|
|
|
+ this.setData({
|
|
|
+ [photo]: res.header.Location
|
|
|
+ })
|
|
|
+ // this.tj(params, res.header.Location)
|
|
|
+ },
|
|
|
+ fail: function () {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showModal({
|
|
|
+ title: '上传失败',
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ requestTask.onProgressUpdate(function (res) {
|
|
|
+ console.log('进度:', res.progress);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
})
|