├── .DS_Store ├── .gitignore ├── .vscode └── settings.json ├── README.md ├── app.js ├── app.json ├── app.wxss ├── dist ├── Bmob-1.1.1.min.js ├── Bmob-1.3.0.min.js ├── Bmob-1.3.1.min.js ├── Bmob-1.4.0.min.js ├── Bmob-1.4.1.min.js ├── Bmob-1.4.2.min.js ├── Bmob-1.4.3.min.js ├── Bmob-1.4.4.min.js ├── Bmob-2.2.5.min.js ├── Bmob-hap.1.1.1.js ├── Bmob-hap.1.1.1.min.js ├── bmob.js ├── bmobSocketIo.js ├── index.html └── underscore.js ├── images ├── add.png ├── addAddress.png ├── autologin.png ├── banner.png ├── chatroom.png ├── checkCon.png ├── checkEmail.png ├── code.png ├── database.png ├── database1.png ├── dels.png ├── edit.png ├── edits.png ├── getInfo.png ├── getOpenid.png ├── green_tri.png ├── help.png ├── icon64_appwx_logo.png ├── icon_API.png ├── icon_API_HL copy.png ├── icon_API_HL.png ├── icon_component.png ├── icon_component_HL copy.png ├── icon_component_HL.png ├── icon_foot.png ├── icon_tabbar.png ├── liao.png ├── list.png ├── list1.png ├── location.png ├── login.png ├── logout.png ├── me.png ├── me1.png ├── open.png ├── openid.png ├── pause.png ├── pay.png ├── phone.png ├── pic.png ├── play.png ├── plus.png ├── pswdreset.jpg ├── pswdreset.png ├── record.png ├── reg.png ├── select.png ├── sms.png ├── stop.png ├── template.png ├── token.png ├── trash.png ├── updateInfo.png ├── wechat.png ├── wechatHL copy.png └── wechatHL.png ├── jsconfig.json ├── package-lock.json ├── package.json ├── pages ├── .DS_Store ├── center │ ├── feedback │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── index.js │ ├── index.json │ ├── index.wxml │ ├── index.wxss │ └── release │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss ├── common │ └── index.wxss ├── database │ ├── detail │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss ├── index │ ├── index.js │ ├── index.wxml │ └── index.wxss ├── interface │ ├── addAddress │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── chatai │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── chatroom │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── checkContent │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── code │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── decryption.js │ ├── decryption.json │ ├── decryption.wxml │ ├── decryption.wxss │ ├── decryption │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── getToken │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── index.js │ ├── index.json │ ├── index.wxml │ ├── index.wxss │ ├── main.go │ ├── pay │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── select │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ ├── shop.js │ ├── shop.json │ ├── shop.wxml │ ├── shop.wxss │ ├── template │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss │ └── upload │ │ ├── index.js │ │ ├── index.json │ │ ├── index.wxml │ │ └── index.wxss ├── logs │ ├── logs.js │ ├── logs.json │ ├── logs.wxml │ └── logs.wxss └── user │ ├── checkEmail │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── getOpenid │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── index.js │ ├── index.json │ ├── index.wxml │ ├── index.wxss │ ├── interface │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── login │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── register │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── resetPswd │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── smsLogin │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ ├── updateInfo │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss │ └── userInfo │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss ├── project.config.json ├── project.private.config.json ├── sitemap.json ├── style ├── footer.wxml ├── header.wxml └── weui.wxss ├── typings └── wx.d.ts └── utils ├── .DS_Store ├── common.js └── util.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /node_modules/* 3 | !/node_modules/axios/ 4 | hydrogen-js-sdk -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.wxml": "html", 4 | "*.wxss": "css" 5 | } 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bmob 微信小程序 Demo 2 | =================== 3 | 4 | 打开Demo你可以这样操作: 5 | 6 | 7 | ![](http://i.imgur.com/61gfDgW.gif) 8 | ![](http://i.imgur.com/0uHVr5W.gif) -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | // app.js 2 | // 源码引入方式,方便调试 3 | import Bmob from 'utils/hydrogen-js-sdk/src/lib/app.js' 4 | // import Bmob from 'utils/hydrogen-js-sdk/dist/Bmob-2.4.13.min.js' 5 | 6 | Bmob.initialize('bc7814ffb203da9f', '123456'); 7 | // 初始化 Bmob.initialize('你的Application ID', '你的REST API Key'); 8 | // Bmob.initialize('9731770784b8c006', '111111') 9 | // Bmob.domain('http://website-restful.bmobapp.com') 10 | // Bmob.domain('http://apitest.codenow.cn') 11 | // Bmob.domain('https://api.codenow.cn') 12 | 13 | 14 | 15 | App({ 16 | onLaunch: function () { 17 | 18 | 19 | 20 | // 按钮点击发送消息 21 | setTimeout(()=>{ 22 | // 发送消息 23 | // console.log(ChatAi,"x"); 24 | // console.log(12); 25 | // session 会话id,可以传用户objectId,或者随机数 26 | // content 内容,提问的内容,如果希望上下文,可以这样传入 27 | // {"model":"gpt-3.5-turbo","messages":[{"content":"你好","role":"user"},{"content":"你好,有什么我可以为你提供的帮助吗?","role":"assistant"},{"content":"请问Bmob是什么产品","role":"user"}],"stream":true} 28 | // let datas = {"messages":[{"content":"你好","role":"user"}],"session":"b1"} 29 | // ChatAi.send(JSON.stringify(datas)) 30 | },3000) 31 | 32 | 33 | 34 | 35 | const query = Bmob.Query('_User') 36 | // query.equalTo('username','!=','ff') 37 | query.find().then(res => { 38 | console.log(res) 39 | }) 40 | // 一键登录 41 | Bmob.User.auth().then(res => { 42 | console.log(res); 43 | console.log('一键登录成功') 44 | var userData = { nickName: res.nickName, objectId: res.objectId, openid: res.openid, userPic: res.userPic, username: res.username }; 45 | wx.setStorageSync('userData', userData); 46 | wx.setStorageSync('openid', res.openid) 47 | }).catch(err => { 48 | console.log(err); 49 | }) 50 | }, 51 | globalData: { 52 | userInfo: null 53 | } 54 | }) -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/user/index", 4 | "pages/user/login/index", 5 | "pages/user/register/index", 6 | "pages/user/smsLogin/index", 7 | "pages/user/userInfo/index", 8 | "pages/user/checkEmail/index", 9 | "pages/user/resetPswd/index", 10 | "pages/user/updateInfo/index", 11 | "pages/user/getOpenid/index", 12 | "pages/interface/index", 13 | "pages/interface/shop", 14 | "pages/interface/upload/index", 15 | "pages/interface/code/index", 16 | "pages/interface/checkContent/index", 17 | "pages/interface/pay/index", 18 | "pages/interface/getToken/index", 19 | "pages/interface/template/index", 20 | "pages/interface/addAddress/index", 21 | "pages/interface/select/index", 22 | "pages/interface/chatroom/index", 23 | "pages/interface/chatai/index", 24 | "pages/database/index", 25 | "pages/database/detail/index", 26 | "pages/center/index", 27 | "pages/center/release/index", 28 | "pages/center/feedback/index", 29 | "pages/interface/decryption", 30 | "pages/interface/decryption/index" 31 | ], 32 | "window": { 33 | "backgroundTextStyle": "light", 34 | "navigationBarBackgroundColor": "#3891f8", 35 | "navigationBarTitleText": "增删改查-小程序Demo", 36 | "navigationBarTextStyle": "white" 37 | }, 38 | "tabBar": { 39 | "color": "#7A7E83", 40 | "selectedColor": "#318efb", 41 | "borderStyle": "white", 42 | "backgroundColor": "#ffffff", 43 | "list": [ 44 | { 45 | "pagePath": "pages/user/index", 46 | "iconPath": "images/icon_API.png", 47 | "selectedIconPath": "images/icon_API_HL.png", 48 | "text": "用户操作" 49 | }, 50 | { 51 | "pagePath": "pages/interface/index", 52 | "iconPath": "images/list.png", 53 | "selectedIconPath": "images/list1.png", 54 | "text": "常用接口" 55 | }, 56 | { 57 | "pagePath": "pages/database/index", 58 | "iconPath": "images/database.png", 59 | "selectedIconPath": "images/database1.png", 60 | "text": "数据库操作" 61 | }, 62 | { 63 | "pagePath": "pages/center/index", 64 | "iconPath": "images/me.png", 65 | "selectedIconPath": "images/me1.png", 66 | "text": "我的" 67 | } 68 | ] 69 | }, 70 | "sitemapLocation": "sitemap.json" 71 | } -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | 3 | /* reset */ 4 | page { 5 | background-color: #F8F8F8; 6 | height: 100%; 7 | font-size: 32rpx; 8 | line-height: 1.6; 9 | } 10 | checkbox, radio{ 11 | margin-right: 10rpx; 12 | } 13 | button{ 14 | margin-top: 20rpx; 15 | margin-bottom: 20rpx; 16 | } 17 | form{ 18 | width: 100%; 19 | } 20 | 21 | /* lib */ 22 | .strong{ 23 | font-weight: bold; 24 | } 25 | .tc{ 26 | text-align: center; 27 | } 28 | .f12{ 29 | font-size: 12px; 30 | } 31 | 32 | /* page */ 33 | .container { 34 | display: flex; 35 | flex-direction: column; 36 | min-height: 100%; 37 | justify-content: space-between; 38 | font-size: 32rpx; 39 | font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif; 40 | } 41 | .page-head{ 42 | padding: 60rpx 50rpx 80rpx; 43 | text-align: center; 44 | } 45 | .page-head-title{ 46 | display: inline-block; 47 | padding: 0 40rpx 20rpx 40rpx; 48 | font-size: 32rpx; 49 | color: #BEBEBE; 50 | } 51 | .page-head-line{ 52 | margin: 0 auto; 53 | width: 150rpx; 54 | height: 2rpx; 55 | background-color: #D8D8D8; 56 | } 57 | .page-head-desc{ 58 | padding-top: 20rpx; 59 | color: #9B9B9B; 60 | font-size: 32rpx; 61 | } 62 | 63 | .page-body { 64 | width: 100%; 65 | flex-grow: 1; 66 | overflow-x: hidden; 67 | } 68 | .page-body-wrapper { 69 | display: flex; 70 | flex-direction: column; 71 | align-items: center; 72 | width: 100%; 73 | } 74 | .page-body-wording { 75 | text-align: center; 76 | padding: 200rpx 100rpx; 77 | } 78 | .page-body-info { 79 | display: flex; 80 | flex-direction: column; 81 | align-items: center; 82 | background-color: #fff; 83 | width: 100%; 84 | padding: 50rpx 0 150rpx 0; 85 | } 86 | .page-body-title { 87 | margin-bottom: 100rpx; 88 | font-size: 32rpx; 89 | } 90 | .page-body-text { 91 | font-size: 30rpx; 92 | line-height: 26px; 93 | color: #ccc; 94 | } 95 | .page-body-text-small { 96 | font-size: 24rpx; 97 | color: #000; 98 | margin-bottom: 100rpx; 99 | } 100 | 101 | .page-foot{ 102 | margin: 100rpx 0 30rpx 0; 103 | text-align: center; 104 | color: #1aad19; 105 | font-size: 0; 106 | } 107 | .icon-foot{ 108 | width: 152rpx; 109 | height: 23rpx; 110 | } 111 | 112 | .page-section{ 113 | width: 100%; 114 | margin-bottom: 60rpx; 115 | } 116 | .page-section_center{ 117 | display: flex; 118 | flex-direction: column; 119 | align-items: center; 120 | } 121 | .page-section:last-child{ 122 | margin-bottom: 0; 123 | } 124 | .page-section-gap{ 125 | box-sizing: border-box; 126 | padding: 0 30rpx; 127 | } 128 | .page-section-spacing{ 129 | box-sizing: border-box; 130 | padding: 0 80rpx; 131 | } 132 | .page-section-title{ 133 | font-size: 28rpx; 134 | color: #999999; 135 | margin-bottom: 10rpx; 136 | padding-left: 30rpx; 137 | padding-right: 30rpx; 138 | } 139 | .page-section-gap .page-section-title{ 140 | padding-left: 0; 141 | padding-right: 0; 142 | } 143 | 144 | 145 | /* widget */ 146 | .btn-area{ 147 | margin-top: 60rpx; 148 | box-sizing: border-box; 149 | width: 100%; 150 | padding: 0 30rpx; 151 | } 152 | 153 | .image-plus { 154 | width: 150rpx; 155 | height: 150rpx; 156 | border: 2rpx solid #D9D9D9; 157 | position: relative; 158 | } 159 | .image-plus-nb{ 160 | border: 0; 161 | } 162 | .image-plus-text{ 163 | color: #888888; 164 | font-size: 28rpx; 165 | } 166 | .image-plus-horizontal { 167 | position: absolute; 168 | top: 50%; 169 | left: 50%; 170 | background-color: #d9d9d9; 171 | width: 4rpx; 172 | height: 80rpx; 173 | transform: translate(-50%, -50%); 174 | } 175 | .image-plus-vertical { 176 | position: absolute; 177 | top: 50%; 178 | left: 50%; 179 | background-color: #d9d9d9; 180 | width: 80rpx; 181 | height: 4rpx; 182 | transform: translate(-50%, -50%); 183 | } 184 | 185 | .demo-text-1{ 186 | position: relative; 187 | align-items: center; 188 | justify-content: center; 189 | background-color: #1AAD19; 190 | color: #FFFFFF; 191 | font-size: 36rpx; 192 | } 193 | .demo-text-1:before{ 194 | content: 'A'; 195 | position: absolute; 196 | top: 50%; 197 | left: 50%; 198 | transform: translate(-50%, -50%); 199 | } 200 | .demo-text-2{ 201 | position: relative; 202 | align-items: center; 203 | justify-content: center; 204 | background-color: #2782D7; 205 | color: #FFFFFF; 206 | font-size: 36rpx; 207 | } 208 | .demo-text-2:before{ 209 | content: 'B'; 210 | position: absolute; 211 | top: 50%; 212 | left: 50%; 213 | transform: translate(-50%, -50%); 214 | } 215 | .demo-text-3{ 216 | position: relative; 217 | align-items: center; 218 | justify-content: center; 219 | background-color: #F1F1F1; 220 | color: #353535; 221 | font-size: 36rpx; 222 | } 223 | .demo-text-3:before{ 224 | content: 'C'; 225 | position: absolute; 226 | top: 50%; 227 | left: 50%; 228 | transform: translate(-50%, -50%); 229 | } 230 | .i-header{ 231 | height: 350rpx; 232 | background-color: #3891f8; 233 | text-align: center; 234 | } 235 | .i-header-h1{ 236 | color:#fff; 237 | font-size: 40rpx; 238 | font-family: Georgia, 'Times New Roman', Times, serif; 239 | font-weight: bold; 240 | } 241 | .h50{ 242 | padding-top: 50px; 243 | } 244 | .g-bda-userinfo { 245 | padding-top: 50rpx; 246 | display: flex; 247 | flex-direction: column; 248 | align-items: center; 249 | } 250 | 251 | .userinfo-avatar { 252 | width: 180rpx; 253 | height: 180rpx; 254 | margin: 20rpx; 255 | margin-bottom: 2rpx; 256 | border-radius: 50%; 257 | border: 2px solid #fff; 258 | } 259 | .userinfo-nickname{ 260 | color: #fff; 261 | } 262 | 263 | 264 | 265 | .weui-dialog { 266 | position: fixed; 267 | z-index: 5000; 268 | width: 80%; 269 | max-width: 300px; 270 | top: 50%; 271 | left: 50%; 272 | -webkit-transform: translate(-50%, -50%); 273 | transform: translate(-50%, -50%); 274 | background-color: #FFFFFF; 275 | text-align: center; 276 | border-radius: 3px; 277 | overflow: hidden; 278 | } 279 | .weui-dialog__hd { 280 | padding: 1.3em 1.6em 0.5em; 281 | } 282 | .weui-dialog__title { 283 | font-weight: 400; 284 | font-size: 18px; 285 | } 286 | .weui-dialog__bd { 287 | padding: 0 1.6em 0.8em; 288 | min-height: 40px; 289 | font-size: 15px; 290 | line-height: 1.3; 291 | word-wrap: break-word; 292 | word-break: break-all; 293 | color: #999999; 294 | } 295 | .weui-dialog__bd:first-child { 296 | padding: 2.7em 20px 1.7em; 297 | color: #353535; 298 | } 299 | .weui-dialog__ft { 300 | position: relative; 301 | line-height: 48px; 302 | font-size: 18px; 303 | display: -webkit-box; 304 | display: -webkit-flex; 305 | display: flex; 306 | } 307 | .weui-dialog__ft:after { 308 | content: " "; 309 | position: absolute; 310 | left: 0; 311 | top: 0; 312 | right: 0; 313 | height: 1px; 314 | border-top: 1px solid #D5D5D6; 315 | color: #D5D5D6; 316 | -webkit-transform-origin: 0 0; 317 | transform-origin: 0 0; 318 | -webkit-transform: scaleY(0.5); 319 | transform: scaleY(0.5); 320 | } 321 | .weui-dialog__btn { 322 | display: block; 323 | -webkit-box-flex: 1; 324 | -webkit-flex: 1; 325 | flex: 1; 326 | color: #3CC51F; 327 | text-decoration: none; 328 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 329 | position: relative; 330 | } 331 | .weui-dialog__btn:active { 332 | background-color: #EEEEEE; 333 | } 334 | .weui-dialog__btn:after { 335 | content: " "; 336 | position: absolute; 337 | left: 0; 338 | top: 0; 339 | width: 1px; 340 | bottom: 0; 341 | border-left: 1px solid #D5D5D6; 342 | color: #D5D5D6; 343 | -webkit-transform-origin: 0 0; 344 | transform-origin: 0 0; 345 | -webkit-transform: scaleX(0.5); 346 | transform: scaleX(0.5); 347 | } 348 | .weui-dialog__btn:first-child:after { 349 | display: none; 350 | } 351 | .weui-dialog__btn_default { 352 | color: #353535; 353 | } 354 | .weui-dialog__btn_primary { 355 | color: #3cc51f; 356 | } 357 | .weui-mask { 358 | position: fixed; 359 | z-index: 1000; 360 | top: 0; 361 | right: 0; 362 | left: 0; 363 | bottom: 0; 364 | background: rgba(0, 0, 0, 0.6); 365 | } 366 | .notice { 367 | margin-top: 15px; 368 | } 369 | 370 | @import 'style/weui.wxss'; -------------------------------------------------------------------------------- /dist/bmobSocketIo.js: -------------------------------------------------------------------------------- 1 | const Emitter = { 2 | setup(target) { 3 | let listeners = [] 4 | 5 | Object.assign(target, { 6 | on(type, handle) { 7 | if (typeof handle == 'function') { 8 | listeners.push([type, handle]) 9 | } 10 | }, 11 | emit(type, ...params) { 12 | listeners.forEach( 13 | ([listenType, handle]) => type == listenType && handle(...params) 14 | ) 15 | }, 16 | removeAllListeners() { 17 | listeners = [] 18 | } 19 | }) 20 | } 21 | } 22 | 23 | /** 24 | * 基于小程序 WebSocket 接口封装信道 25 | */ 26 | module.exports = class BmobSocketIo { 27 | constructor(applicationId) { 28 | 29 | this.config = { 30 | host: 'wss.bmobcloud.com' 31 | } 32 | Emitter.setup((this.emitter = {})) 33 | this.applicationId = applicationId 34 | this.initialize() 35 | } 36 | handshake() { 37 | function complete(data) { 38 | if (data instanceof Error) { 39 | self.connecting = false 40 | self.onError(data.message) 41 | } else { 42 | return data.split(':')[0] 43 | } 44 | } 45 | 46 | var url = 'https://'+this.config.host+'/socket.io/1/?t=' + new Date().getTime() 47 | var dataObject = {} 48 | var data = JSON.stringify(dataObject) 49 | 50 | var method = 'GET' 51 | 52 | return new Promise((resolve, reject) => { 53 | wx.request({ 54 | method: method, 55 | url: url, 56 | data: data, 57 | header: { 58 | 'content-type': 'text/plain' 59 | }, 60 | success: function(res) { 61 | if (res.data && res.data.statusCode) { 62 | return resolve('request error', e) 63 | } else if (res.statusCode != 200) { 64 | return resolve('request error', e) 65 | } else { 66 | return resolve(complete(res.data)) 67 | } 68 | }, 69 | fail: function(e) { 70 | return resolve('request error', e) 71 | } 72 | }) 73 | }) 74 | } 75 | initialize() { 76 | this.handshake().then(protocol => { 77 | try { 78 | this.connect( 79 | `wss://${this.config.host}/socket.io/1/websocket/` + protocol, 80 | {} 81 | ) 82 | } catch (connectError) { 83 | console.error({ connectError }) 84 | throw connectError 85 | } 86 | }) 87 | this.on('close', () => { 88 | console.log('连接已中断') 89 | }) 90 | 91 | return new Promise((resolve, reject) => { 92 | this.on('server_pub', data => { 93 | switch (data.action) { 94 | case 'updateTable': 95 | this.onUpdateTable(data.tableName, data.data) 96 | break 97 | case 'updateRow': 98 | this.onUpdateRow(data.tableName, data.objectId, data.data) 99 | break 100 | case 'deleteTable': 101 | this.onDeleteTable(data.tableName, data.data) 102 | break 103 | case 'deleteRow': 104 | this.onDeleteRow(data.tableName, data.objectId, data.data) 105 | break 106 | } 107 | }) 108 | 109 | //连接上socket.io服务器后触发的事件 110 | this.on('client_send_data', resp => { 111 | this.onInitListen() 112 | }) 113 | }) 114 | } 115 | 116 | onInitListen() {} 117 | 118 | connect(url, header) { 119 | // 小程序 wx.connectSocket() API header 参数无效,把会话信息附加在 URL 上 120 | const query = Object.keys(header) 121 | .map(key => `${key}=${encodeURIComponent(header[key])}`) 122 | .join('&') 123 | const seperator = url.indexOf('?') > -1 ? '&' : '?' 124 | url = [url, query].join(seperator) 125 | 126 | return new Promise((resolve, reject) => { 127 | wx.onSocketOpen(resolve) 128 | wx.onSocketError(reject) 129 | wx.onSocketMessage(packet => { 130 | try { 131 | let filter = function(str) { 132 | const { name, args } = JSON.parse(str) 133 | return { name, args } 134 | } 135 | let str = packet.data 136 | let startStr = str.slice(0,4) 137 | // 检测心跳 138 | if('2:::'===startStr){ 139 | this.emit(false,true) 140 | } 141 | str = str.slice(4) 142 | 143 | // 截取后不能为空 144 | if (str == null || str == '') { 145 | return 146 | } 147 | const { name, args } = filter(str) 148 | let data = args == null ? '' : JSON.parse(args[0]) 149 | this.emitter.emit(name, data) 150 | } catch (e) { 151 | console.log('Handle packet failed: ' + packet.data, e) 152 | } 153 | }) 154 | wx.onSocketClose(() => this.emitter.emit('close')) 155 | wx.connectSocket({ url, header }) 156 | }) 157 | } 158 | 159 | on(message, handle) { 160 | this.emitter.on(message, handle) 161 | } 162 | 163 | emit(message, data) { 164 | data=data==undefined?'5:::':'2:::' 165 | message = message?JSON.stringify(message):'' 166 | wx.sendSocketMessage({ 167 | data: data + message 168 | }) 169 | } 170 | 171 | emitData(name, data) { 172 | data = JSON.stringify(data) 173 | return { name: name, args: [data] } 174 | } 175 | 176 | //"unsub_updateTable" ,"unsub_updateRow", "unsub_deleteTable", "unsub_deleteRow" 177 | //订阅更新数据表的数据 178 | updateTable = function(tablename) { 179 | var data = { 180 | appKey: this.applicationId, 181 | tableName: tablename, 182 | objectId: '', 183 | action: 'updateTable' 184 | } 185 | data = this.emitData('client_sub', data) 186 | this.emit(data) 187 | } 188 | 189 | //取消订阅更新数据表的数据 190 | unsubUpdateTable = function(tablename) { 191 | var data = { 192 | appKey: this.applicationId, 193 | tableName: tablename, 194 | objectId: '', 195 | action: 'unsub_updateTable' 196 | } 197 | data = this.emitData('client_sub', data) 198 | this.emit(data) 199 | } 200 | 201 | //订阅行更新的数据 202 | updateRow = function(tablename, objectId) { 203 | var data = { 204 | appKey: this.applicationId, 205 | tableName: tablename, 206 | objectId: objectId, 207 | action: 'updateRow' 208 | } 209 | data = this.emitData('client_sub', data) 210 | this.emit(data) 211 | } 212 | 213 | //取消订阅行更新的数据 214 | unsubUpdateRow = function(tablename, objectId) { 215 | var data = { 216 | appKey: this.applicationId, 217 | tableName: tablename, 218 | objectId: objectId, 219 | action: 'unsub_updateRow' 220 | } 221 | data = this.emitData('client_sub', data) 222 | this.emit(data) 223 | } 224 | 225 | //订阅表删除的数据 226 | deleteTable = function(tablename) { 227 | var data = { 228 | appKey: this.applicationId, 229 | tableName: tablename, 230 | objectId: '', 231 | action: 'deleteTable' 232 | } 233 | data = this.emitData('client_sub', data) 234 | this.emit(data) 235 | } 236 | 237 | //取消订阅表删除的数据 238 | unsubDeleteTable = function(tablename) { 239 | var data = { 240 | appKey: this.applicationId, 241 | tableName: tablename, 242 | objectId: '', 243 | action: 'unsub_deleteTable' 244 | } 245 | data = this.emitData('client_sub', data) 246 | this.emit(data) 247 | } 248 | 249 | //订阅更新数据表的数据 250 | deleteRow = function(tablename, objectId) { 251 | var data = { 252 | appKey: this.applicationId, 253 | tableName: tablename, 254 | objectId: objectId, 255 | action: 'deleteRow' 256 | } 257 | data = this.emitData('client_sub', data) 258 | this.emit(data) 259 | } 260 | 261 | //订阅更新数据表的数据 262 | unsubDeleteRow = function(tablename, objectId) { 263 | var data = { 264 | appKey: this.applicationId, 265 | tableName: tablename, 266 | objectId: objectId, 267 | action: 'unsub_deleteRow' 268 | } 269 | data = this.emitData('client_sub', data) 270 | this.emit(data) 271 | } 272 | 273 | //监听服务器返回的更新数据表的数据,需要用户重写 274 | onUpdateTable = function(tablename, data) {} 275 | 276 | //监听服务器返回的更新数据表的数据,需要用户重写 277 | onUpdateRow = function(tablename, objectId, data) {} 278 | 279 | //监听服务器返回的更新数据表的数据,需要用户重写 280 | onDeleteTable = function(tablename, data) {} 281 | 282 | //监听服务器返回的更新数据表的数据,需要用户重写 283 | onDeleteRow = function(tablename, objectId, data) {} 284 | } 285 | -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Page Title 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/add.png -------------------------------------------------------------------------------- /images/addAddress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/addAddress.png -------------------------------------------------------------------------------- /images/autologin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/autologin.png -------------------------------------------------------------------------------- /images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/banner.png -------------------------------------------------------------------------------- /images/chatroom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/chatroom.png -------------------------------------------------------------------------------- /images/checkCon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/checkCon.png -------------------------------------------------------------------------------- /images/checkEmail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/checkEmail.png -------------------------------------------------------------------------------- /images/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/code.png -------------------------------------------------------------------------------- /images/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/database.png -------------------------------------------------------------------------------- /images/database1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/database1.png -------------------------------------------------------------------------------- /images/dels.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/dels.png -------------------------------------------------------------------------------- /images/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/edit.png -------------------------------------------------------------------------------- /images/edits.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/edits.png -------------------------------------------------------------------------------- /images/getInfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/getInfo.png -------------------------------------------------------------------------------- /images/getOpenid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/getOpenid.png -------------------------------------------------------------------------------- /images/green_tri.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/green_tri.png -------------------------------------------------------------------------------- /images/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/help.png -------------------------------------------------------------------------------- /images/icon64_appwx_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon64_appwx_logo.png -------------------------------------------------------------------------------- /images/icon_API.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_API.png -------------------------------------------------------------------------------- /images/icon_API_HL copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_API_HL copy.png -------------------------------------------------------------------------------- /images/icon_API_HL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_API_HL.png -------------------------------------------------------------------------------- /images/icon_component.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_component.png -------------------------------------------------------------------------------- /images/icon_component_HL copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_component_HL copy.png -------------------------------------------------------------------------------- /images/icon_component_HL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_component_HL.png -------------------------------------------------------------------------------- /images/icon_foot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_foot.png -------------------------------------------------------------------------------- /images/icon_tabbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/icon_tabbar.png -------------------------------------------------------------------------------- /images/liao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/liao.png -------------------------------------------------------------------------------- /images/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/list.png -------------------------------------------------------------------------------- /images/list1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/list1.png -------------------------------------------------------------------------------- /images/location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/location.png -------------------------------------------------------------------------------- /images/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/login.png -------------------------------------------------------------------------------- /images/logout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/logout.png -------------------------------------------------------------------------------- /images/me.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/me.png -------------------------------------------------------------------------------- /images/me1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/me1.png -------------------------------------------------------------------------------- /images/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/open.png -------------------------------------------------------------------------------- /images/openid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/openid.png -------------------------------------------------------------------------------- /images/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/pause.png -------------------------------------------------------------------------------- /images/pay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/pay.png -------------------------------------------------------------------------------- /images/phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/phone.png -------------------------------------------------------------------------------- /images/pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/pic.png -------------------------------------------------------------------------------- /images/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/play.png -------------------------------------------------------------------------------- /images/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/plus.png -------------------------------------------------------------------------------- /images/pswdreset.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/pswdreset.jpg -------------------------------------------------------------------------------- /images/pswdreset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/pswdreset.png -------------------------------------------------------------------------------- /images/record.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/record.png -------------------------------------------------------------------------------- /images/reg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/reg.png -------------------------------------------------------------------------------- /images/select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/select.png -------------------------------------------------------------------------------- /images/sms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/sms.png -------------------------------------------------------------------------------- /images/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/stop.png -------------------------------------------------------------------------------- /images/template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/template.png -------------------------------------------------------------------------------- /images/token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/token.png -------------------------------------------------------------------------------- /images/trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/trash.png -------------------------------------------------------------------------------- /images/updateInfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/updateInfo.png -------------------------------------------------------------------------------- /images/wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/wechat.png -------------------------------------------------------------------------------- /images/wechatHL copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/wechatHL copy.png -------------------------------------------------------------------------------- /images/wechatHL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/images/wechatHL.png -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "commonjs" 5 | } 6 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "webpack": "^5.99.7", 4 | "webpack-cli": "^6.0.1" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /pages/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bmob/wechatapp-demo/5f3300f09cf9d7ccdd4330de9409160d1c83e491/pages/.DS_Store -------------------------------------------------------------------------------- /pages/center/feedback/index.js: -------------------------------------------------------------------------------- 1 | // pages/center/feedback/index.js 2 | var common = require('../../../utils/common.js'); 3 | Page({ 4 | 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | userInfo:{}, 10 | }, 11 | 12 | /** 13 | * 生命周期函数--监听页面加载 14 | */ 15 | onLoad: function (options) { 16 | var that = this; 17 | 18 | let userData = wx.Bmob.User.current() 19 | that.setData({ 20 | userInfo:userData 21 | }) 22 | }, 23 | 24 | /** 25 | * 生命周期函数--监听页面初次渲染完成 26 | */ 27 | onReady: function () { 28 | 29 | }, 30 | 31 | /** 32 | * 生命周期函数--监听页面显示 33 | */ 34 | onShow: function () { 35 | 36 | }, 37 | 38 | /** 39 | * 生命周期函数--监听页面隐藏 40 | */ 41 | onHide: function () { 42 | 43 | }, 44 | 45 | /** 46 | * 生命周期函数--监听页面卸载 47 | */ 48 | onUnload: function () { 49 | 50 | }, 51 | 52 | /** 53 | * 页面相关事件处理函数--监听用户下拉动作 54 | */ 55 | onPullDownRefresh: function () { 56 | 57 | }, 58 | 59 | /** 60 | * 页面上拉触底事件的处理函数 61 | */ 62 | onReachBottom: function () { 63 | 64 | }, 65 | 66 | /** 67 | * 用户点击右上角分享 68 | */ 69 | onShareAppMessage: function () { 70 | 71 | }, 72 | addFeedback: function (event) { 73 | var that = this; 74 | var contact = event.detail.value.contact; 75 | var content = event.detail.value.content; 76 | 77 | if (!contact) { 78 | common.showTip("标题不能为空", "loading"); 79 | return false; 80 | } 81 | else if (!content) { 82 | common.showTip("内容不能为空", "loading"); 83 | return false; 84 | } 85 | else { 86 | that.setData({ 87 | loading: true 88 | }) 89 | var query = wx.Bmob.Query("feedback"); 90 | query.set("contact", contact); 91 | query.set("content", content); 92 | query.save().then(res => { 93 | common.showModal('保存反馈成功,点击确定返回。', '提示', function () { 94 | wx.navigateBack(); 95 | }); 96 | that.setData({ 97 | loading: false 98 | }) 99 | }).catch(err => { 100 | // 添加失败 101 | common.showModal('保存反馈失败,请重新发布'); 102 | 103 | }) 104 | } 105 | 106 | }, 107 | }) -------------------------------------------------------------------------------- /pages/center/feedback/index.json: -------------------------------------------------------------------------------- 1 | { 2 | "navigationBarTitleText": "反馈建议" 3 | } -------------------------------------------------------------------------------- /pages/center/feedback/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{userInfo.nickName}} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 联系方式 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 建议内容 26 | 27 | 28 | 29 |