Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
add upload function
Browse files Browse the repository at this point in the history
  • Loading branch information
zzsqwq committed Dec 16, 2021
1 parent 53e67c1 commit 5de4bf4
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 13 deletions.
19 changes: 19 additions & 0 deletions cloudfunctions/add/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 云函数入口文件
const cloud = require('qq-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {

const {
OPENID,
APPID,
ENV
} = cloud.getQQContext()

return {
sum: event.a + event.b
}
}
14 changes: 14 additions & 0 deletions cloudfunctions/add/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "add",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"qq-server-sdk": "latest"
}
}
Empty file added config.js
Empty file.
81 changes: 74 additions & 7 deletions pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@
const sourceType = [['camera'], ['album'], ['camera', 'album']]
const sizeType = [['compressed'], ['original'], ['compressed', 'original']]



Page({
data: {
imageList: [],
},
onLoad(options) {
qq.cloud.init({
env: 'postwall-4gy7eykl559a475a',
traceUser: true
})

const db = qq.cloud.database();

db.collection('books').where(
{
publishInfo: {
country: 'test'
}
}
).get({
success: function(res) {
console.log(res)
},
// fail: function(res) {
// console.log("failed! res:",res)
// }
})
// Do some initialize when page load.
},
onReady() {
Expand Down Expand Up @@ -57,6 +80,24 @@ Page({
},
formSubmit(e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value)
submit_data = e.detail.value
const db = qq.cloud.database()
db.collection("postwall").add( {
data: {
post_type : submit_data.post_type,
post_title : submit_data.post_title,
post_text : submit_data.post_text,
post_contact_qq : submit_data.post_contact_qq,
post_contact_wechat : submit_data.post_contact_wechat,
post_contact_tel : submit_data.post_contact_tel,
post_done : false,
post_data : new Date(),
image_list : imageList
}
})
.then(res => {console.log(res)})
.catch(res => {console.error(res)})

qq.showToast({
title: '提交成功',
icon: 'success',
Expand All @@ -65,20 +106,45 @@ Page({
},
formReset() {
console.log('form发生了reset事件')
},
chooseImage:function () {
// qq.showToast(
// {
// title: '清空成功',
// icon: 'success',
// duration: 500
// }
// )
},
chooseImage: function () {
const that = this
imageList = this.data.imageList
qq.chooseImage({
sourceType: ['album','camera'],
sizeType: ['original','compressed'],
count: 9 - imageList.length,
success(res) {
console.log(res);
imageList = imageList.concat(res.tempFilePaths);
console.log(res.tempFilePaths);
success: async res => {
console.log(res)
imageList = imageList.concat(res.tempFilePaths)
// console.log(res.tempFilePaths)
//image_list = imageList
console.log(res.tempFilePaths[0])
// qq.cloud.uploadFile( {
// cloudPath: "1.png",

// filePath: res.tempFilePaths[0],

// success : res => {
// console.log('photo upload success, resid is ',res.fileID),
// image_list.push(res.fileID)
// // that.setData( {
// // imageList : image_list
// // })
// //console.log("imagelist: ", image_list)
// }
// }
// )
//console.log("imagelist: ",image_list)
that.setData({
imageList: imageList
imageList: image_list
})
}
}
Expand All @@ -93,6 +159,7 @@ Page({
urls: this.data.imageList
})
},

deleteImage(e) {
var imgs = this.data.imageList;
var index = e.target.dataset.index;
Expand Down
12 changes: 6 additions & 6 deletions pages/index/index.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
<view class="section">
<view class="section__title">投稿类型</view>
<view class="input-section">
<input class="input_text" name="post-type" maxlength="4" placeholder="不超过 4 个字(如表白、提问等)" />
<input class="input_text" name="post_type" maxlength="4" placeholder="不超过 4 个字(如表白、提问等)" />
</view>
</view>
<view class="section">
<view class="section__title">投稿标题</view>
<view class="input-section">
<input class="input_text" name="post-title" maxlength="8" placeholder="不超过 8 个字" />
<input class="input_text" name="post_title" maxlength="8" placeholder="不超过 8 个字" />
</view>
</view>

<view class="section">
<view class="section__title">内容文本</view>
<textarea class="textarea_text" name="post-text" auto-height placeholder="在这里输入具体内容" placeholder-class="input_text-placeholder"/>
<textarea class="textarea_text" name="post_text" auto-height placeholder="在这里输入具体内容" placeholder-class="input_text-placeholder"/>
</view>

<view class="section">
Expand All @@ -45,21 +45,21 @@
<view class="section__title">联系方式</view>
<view class="contact-block">
<image class="contact-icon-class" src="../../images/pages/home/icon-qq-3.png" mode="aspectFill"></image>
<input class="contact-input_text" name="post-contact-qq" maxlength="11" placeholder="QQ" />
<input class="contact-input_text" name="post_contact_qq" maxlength="11" placeholder="QQ" />
</view>
</view>

<view class="section-mid" >
<view class="contact-block">
<image class="contact-icon-class" src="../../images/pages/home/icon-wechat.png" mode="aspectFill"></image>
<input class="contact-input_text" name="post-contact-wechat" maxlength="20" placeholder="微信" />
<input class="contact-input_text" name="post_ontact_wechat" maxlength="20" placeholder="微信" />
</view>
</view>

<view class="section-mid" >
<view class="contact-block">
<image class="contact-icon-phone-class" src="../../images/pages/home/icon-phone.png" mode="aspectFill"></image>
<input class="contact-input_text" name="post-contact-email" placeholder="联系电话" />
<input class="contact-input_text" name="post_contact_tel" maxlength="11" placeholder="联系电话" />
</view>
</view>

Expand Down

0 comments on commit 5de4bf4

Please sign in to comment.