道常無爲而無不爲html
cloudfunctions | - login | - index.js | - package.json | - package-lock.json | - arthurSlog_getInfo | - index.js | - package.json | - package-lock.json | - arthurSlog_methodAdd | - index.js | - package.json | - package-lock.json miniprogram | - images | - code-db-inc-dec.png | - code-db-onAdd.png | - code-db-onQuery.png | - code-db-onRemove.png | - code-func-sum.png | - console-entrance.png | - create-collection.png | - pages | - addFunction | - addFunction.js | - addFunction.json | - addFunction.wxml | - addFunction.wxss | - chooseLib | - chooseLib.js | - chooseLib.json | - chooseLib.wxml | - chooseLib.wsxx | - databaseGuide | - databaseGuide.js | - databaseGuide.json | - databaseGuide.wxml | - databaseGuide.wxss | - deployFunctions | - deployFunctions.js | - deployFunctions.json | - deployFunctions.wxml | - deployFunctions.wxss | - index | - index.js | - index.wxml | - index.wxss | - user-unlogin.png | - storageConsole | - storageConsole.js | - storageConsole.json | - storageConsole.wxml | - storageConsole.wxss | - userConsole | - userConsole.js | - userConsole.json | - userConsole.wxml | - userConsole.wxss | - style | - guide.wxss | - app.js | - app.json | - app.wxss README.md project.config.json
Client:
miniprogram/app.js前端
//app.js App({ onLaunch: function () { if (!wx.cloud) { console.error('請使用 2.2.3 或以上的基礎庫以使用雲能力') } else { wx.cloud.init({ env: 'arthurslog-test-d4537a', traceUser: true, }) } this.globalData = {} } })
Server:
cloudfunctions/arthurSlog_getInfo/index.jsgit
// 雲函數入口文件 const cloud = require('wx-server-sdk') cloud.init() // 雲函數入口函數 exports.main = async(event, context) => { return event.userInfo }
Server:
cloudfunctions/arthurSlog_getInfo/index.jsgithub
// 雲函數入口文件 //const cloud = require('wx-server-sdk') //cloud.init() // 雲函數入口函數 exports.main = async(event, context) => { return event.userInfo }
Client
miniprogram/pages/index/index.js數據庫
Page({ data: { avatarUrl: './user-unlogin.png', userInfo: {}, logged: false, takeSession: false, requestResult: '', fileID: '', cloudPath: '', imagePath: './user-unlogin.png', }, // ... // ... // ... // 添加前端代碼,向雲端上傳圖片 arthurSlog_uploadImg: function() { // 選擇圖片 const this_ = this wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success(res) { // tempFilePath能夠做爲img標籤的src屬性顯示圖片 const tempFilePaths = res.tempFilePaths this_.setData({ imagePath: tempFilePaths[0], }) console.log(tempFilePaths[0]) } }) }, })
Client
miniprogram/pages/index/index.jsnpm
const this_ = this
Client
miniprogram/pages/index/index.wxmljson
<!--index.wxml--> <view class="container"> <!-- ... --> <!-- 獲取 openid --> <view class="uploader"> <button class="userinfo-nickname" bindtap="arthurSlog_getInfo">點擊獲取 openid</button> </view> <!-- 返回兩個對象之和 --> <view class="uploader"> <button class="userinfo-nickname" bindtap="arthurSlog_methodAdd">點擊返回兩個對象之和</button> </view> <!-- 上傳圖片 --> <view class="uploader"> <button class="userinfo-nickname" bindtap="arthurSLog_uploadImg">上傳圖片</button> </view> <!-- 顯示圖片 --> <view> <image class="img" src="{{imagePath}}" mode="scaleToFill"></image> </view> </view>