-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
unknown
committed
Oct 17, 2018
0 parents
commit ef6ca16
Showing
137 changed files
with
36,489 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Windows | ||
[Dd]esktop.ini | ||
Thumbs.db | ||
$RECYCLE.BIN/ | ||
|
||
# macOS | ||
.DS_Store | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
|
||
# Node.js | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
LICENSE - "MIT License" | ||
|
||
Copyright (c) 2016 by Tencent Cloud | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# - | ||
一个用来背单词每天打卡的微信小程序,还有词汇测试,包含多种词库 | ||
后台由腾讯云wafer解决方案 | ||
===================================== | ||
![image](https://raw.githubusercontent.com/flymysql/WeChat-applets/master/12.jpg) | ||
|
||
## 源码简介 | ||
|
||
```tree | ||
Demo | ||
├── LICENSE | ||
├── README.md | ||
├── app.js | ||
├── app.json | ||
├── config.js | ||
├── package.json | ||
├── pages | ||
│ ├── about | ||
│ ├── audio_rest | ||
│ ├── choice | ||
│ ├── collect_test | ||
│ ├── detail_word | ||
│ ├── index | ||
│ ├── job | ||
│ ├── me | ||
│ ├── my_word | ||
│ ├── rank | ||
│ ├── search | ||
│ ├── study | ||
│ ├── suggestion | ||
│ └── test | ||
├── utils | ||
├── data | ||
├── assets | ||
├── images | ||
└── vendor | ||
└── qcloud-weapp-client-sdk/ | ||
``` | ||
|
||
`app.js` 是小程序入口文件。 | ||
|
||
`app.json` 是小程序的微信配置,其中指定了本示例的两个页面,页面分别在 `pages/index/` 和 `pages/chat/` 目录下。 | ||
|
||
`config.js` 是我们小程序自己的业务配置。 | ||
|
||
`wafer2-client-sdk` 是[客户端 SDK](https://github.com/tencentyun/wafer2-client-sdk) | ||
|
||
仅供学习,转载请注明出处 | ||
另外个人博客求一波友链 https://www.idealli.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
//app.js | ||
|
||
var qcloud = require('./vendor/wafer2-client-sdk/index'); | ||
var config = require('./config'); | ||
var util = require('./utils/util.js') | ||
|
||
App({ | ||
appData: { | ||
appId: config.service.appId, | ||
baseUrl: `${config.service.host}/weapp/`, | ||
tunnelStatus: 'close',//统一管理唯一的信道连接的状态:connect、close、reconnecting、reconnect、error | ||
friendsFightingRoom: undefined,//好友对战时创建的唯一房间名,作为好友匹配的标识 | ||
}, | ||
onLaunch(opt) { | ||
this.appData.opt = opt | ||
qcloud.setLoginUrl(config.service.loginUrl); //设置登录地址 | ||
this.doLogin(); | ||
}, | ||
onShow(opt) { | ||
this.storeUser_network(opt)//每次打开程序都启动存储用户关系表 | ||
}, | ||
doLogin() { //登录 | ||
let that = this | ||
util.showBusy('正在登录'); | ||
qcloud.login({ | ||
success(result) {//此处的result竟然不包含openid,所以res取缓存中的数据 | ||
util.showSuccess('登录成功') | ||
let res = wx.getStorageSync('user_info_F2C224D4-2BCE-4C64-AF9F-A6D872000D1A'); | ||
if (that.userInfoReadyCallback) { | ||
that.userInfoReadyCallback(res) | ||
} | ||
}, | ||
fail(error) { | ||
util.showModel('登录失败', error); | ||
} | ||
}); | ||
}, | ||
pageGetUserInfo(page, openIdReadyCallback) { //在page中获取用户信息 | ||
const userInfo = wx.getStorageSync('user_info_F2C224D4-2BCE-4C64-AF9F-A6D872000D1A') | ||
if (userInfo) { | ||
page.setData({ | ||
userInfo, | ||
openId: userInfo.openId | ||
}) | ||
this.appData.openId = userInfo.openId | ||
if (openIdReadyCallback) { | ||
openIdReadyCallback(userInfo.openId) | ||
} | ||
} else { | ||
this.userInfoReadyCallback = (userInfo) => { //获取用户信息后的回调函数 | ||
page.setData({ //每个page都会自动存储userInfo和openId | ||
userInfo, | ||
openId: userInfo.openId | ||
}) | ||
if (openIdReadyCallback) { //如果设置了openid的回调函数,则调用回调 | ||
openIdReadyCallback(userInfo.openId) | ||
} | ||
} | ||
} | ||
}, | ||
//tunnel:由于一个小程序只能同时连接一个信道而且设计页面跳转后信道对象会销毁问题,所以将其放在app.js中统一管理 | ||
tunnelCreate() {//创建一个新信道,并监听相关数据的变化 | ||
const that = this | ||
const tunnel = that.tunnel = new qcloud.Tunnel(config.service.tunnelUrl) //放在app对象下供全局使用 | ||
tunnel.open() | ||
tunnel.on('connect', () => {//监听信道连接 | ||
console.info("tunnelStatus = 'connect'") | ||
this.appData.tunnelStatus = 'connect' //改变信道状态为已连接 | ||
if (that.tunnelConnectCallback) {//设置回调 | ||
that.tunnelConnectCallback() | ||
} | ||
}) | ||
tunnel.on('close', () => {//监听信道断开 | ||
console.info("tunnelStatus = 'close'") | ||
this.appData.tunnelStatus = 'close' //改变信道状态为已断开 | ||
if (that.tunnelCloseCallback) {//设置回调 | ||
that.tunnelCloseCallback() | ||
} | ||
}) | ||
tunnel.on('reconnecting', () => {//监听信道重新链接 | ||
console.info("tunnelStatus = 'reconnecting'") | ||
this.appData.tunnelStatus = 'reconnecting' //改变信道状态为重新连接中 | ||
if (that.tunnelReconnectingCallback) {//设置回调 | ||
that.tunnelReconnectingCallback() | ||
} | ||
}) | ||
tunnel.on('reconnect', () => {//监听信道重新连接成功 | ||
console.info("tunnelStatus = 'reconnect'") | ||
console.info('重连后的信道为:' + tunnel.socketUrl.slice(tunnel.socketUrl.indexOf('tunnelId=') + 9, tunnel.socketUrl.indexOf('&'))) | ||
this.appData.tunnelStatus = 'reconnect' //改变信道状态为重新连接成功 | ||
if (that.tunnelReconnectCallback) {//设置回调 | ||
that.tunnelReconnectCallback() | ||
} | ||
}) | ||
tunnel.on('error', () => {//监听信道发生错误 | ||
console.info("tunnelStatus = 'error'") | ||
this.appData.tunnelStatus = 'error' //改变信道状态为发生错误 | ||
util.showSuccess('您已断线,请检查联网') | ||
wx.navigateBack({ | ||
url: '../entry/entry' | ||
}) | ||
if (that.tunnelErrorCallback) {//设置回调 | ||
that.tunnelErrorCallback() | ||
} | ||
}) | ||
tunnel.on('PING', () => {//PING-PONG机制:监听服务器PING | ||
console.info("接收到PING") | ||
tunnel.emit('PONG', {//给出回应 | ||
openId: this.appData.openId | ||
}) | ||
console.info("发出了PONG") | ||
}) | ||
|
||
}, | ||
|
||
/******************用户关系点击表操作******************/ | ||
//注意1:所有从分享中启动的页面onLoad都添加: | ||
/* | ||
app.appData.fromClickId = opt.currentClickId | ||
app.upDateUser_networkFromClickId = require('../../utils/upDateUser_networkFromClickId.js').upDateUser_networkFromClickId | ||
wx.showShareMenu({ | ||
withShareTicket: true | ||
}) | ||
*/ | ||
//注意2:所有分享页面路径都添加:?currentClickId=' + app.appData.currentClickId, | ||
//注意3:所有分享页面的分享成功回调都添加: require('../../utils/upDateShareInfoToUser_network.js').upDateShareInfoToUser_network(app,that,res) | ||
|
||
storeUser_network(opt) { | ||
const that = this | ||
const userInfo = wx.getStorageSync('user_info_F2C224D4-2BCE-4C64-AF9F-A6D872000D1A') | ||
if (userInfo) {//已缓存的用户数据直接用 | ||
getGId(that, userInfo, opt) | ||
} else { | ||
this.userInfoReadyCallback = (userInfo) => { //获取用户信息后的回调函数 | ||
getGId(that, userInfo, opt) | ||
} | ||
} | ||
function getGId(that, userInfo, opt) { | ||
//判断是否是从微信群内打开该程序的 | ||
wx.getShareInfo({ | ||
shareTicket: opt.shareTicket, | ||
//含GId的情况 | ||
success: (res) => { | ||
qcloud.request({ | ||
login: false, | ||
data: { | ||
appId: that.appData.appId, | ||
openId: userInfo.openId, | ||
encryptedData: res.encryptedData, | ||
iv: res.iv | ||
}, | ||
url: `${that.appData.baseUrl}getGId`, | ||
success: (res) => { | ||
let GId = res.data.data | ||
store(that, userInfo, opt, GId) | ||
} | ||
}) | ||
}, | ||
//不含GId的情况 | ||
fail: function (res) { | ||
store(that, userInfo, opt) | ||
} | ||
}) | ||
} | ||
function store(that, userInfo, opt, GId = '') { //参数内要写that:that作为一个对象不能凭空产生 | ||
let data = { | ||
//clickId:自动生成的数据, | ||
fromClickId: that.appData.fromClickId ? that.appData.fromClickId : 0,//从哪个clickId那里打开的 | ||
appId: that.appData.appId, | ||
openId: userInfo.openId, | ||
fromGId: GId, | ||
scene: opt.scene, | ||
//time:自动生成的数据, | ||
//param_1:转发时才会更新当前clickId中的param_1数据 | ||
} | ||
//将数据存储到数据库点击表中,同时将得到的clickId放在全局变量供page分享时调用 | ||
qcloud.request({ | ||
login: false, | ||
data, | ||
url: `${that.appData.baseUrl}storeUser_network`, | ||
success: (res) => { | ||
let currentClickId = res.data.data | ||
that.appData.currentClickId = currentClickId//设置当前新插入的clickId为全局fromClickId | ||
let fromClickId = that.appData.fromClickId | ||
if (that.upDateUser_networkFromClickId && fromClickId) {//存在fromClickId,则进行数据库更新 | ||
that.upDateUser_networkFromClickId(that, currentClickId, fromClickId) | ||
} | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"pages":[ | ||
"pages/job/job", | ||
"pages/study/study", | ||
"pages/search/search", | ||
"pages/detail-word/detail-word", | ||
"pages/me/me", | ||
"pages/choice/choice", | ||
"pages/test/test", | ||
"pages/collect_card/collect_card", | ||
"pages/audio_test/audio_test", | ||
"pages/about/about", | ||
"pages/my_word/my_word", | ||
"pages/suggestion/suggestion", | ||
"pages/sql/sql", | ||
|
||
"pages/rank/rank" | ||
|
||
], | ||
|
||
"window":{ | ||
"backgroundTextStyle":"light", | ||
"backgroundColor": "#fff", | ||
"navigationBarBackgroundColor": "#fff", | ||
"navigationBarTitleText": "小鸡单词", | ||
"navigationBarTextStyle":"black" | ||
} | ||
, | ||
"tabBar": { | ||
"color": "#000", | ||
"selectedColor": "#000", | ||
"borderStyle": "white", | ||
"backgroundColor": "#ffffff", | ||
"list": [ | ||
{ | ||
"pagePath": "pages/job/job", | ||
"text": "首页", | ||
"iconPath": "images/home2.png", | ||
"selectedIconPath": "images/home.png" | ||
}, | ||
{ | ||
"pagePath": "pages/search/search", | ||
"text": "查单词", | ||
"iconPath": "images/search2.png", | ||
"selectedIconPath": "images/search.png" | ||
}, | ||
{ | ||
"pagePath": "pages/me/me", | ||
"text": "我的", | ||
"iconPath": "images/ji.png", | ||
"selectedIconPath": "images/ji2.png" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/**app.wxss**/ | ||
|
||
page { | ||
background-color: #EFEFF4; | ||
} | ||
|
||
.container { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; | ||
box-sizing: border-box; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* 小程序配置文件 | ||
*/ | ||
|
||
// 此处主机域名修改成腾讯云解决方案分配的域名 | ||
var host = 'https://www.sinx2018.cn' //开发环境 | ||
|
||
var appId ='你的appid' | ||
|
||
var config = { | ||
|
||
// 下面的地址配合云端 Demo 工作 | ||
service: { | ||
appId, | ||
|
||
host, | ||
|
||
// 登录地址,用于建立会话 | ||
loginUrl: `${host}/weapp/login`, | ||
|
||
// 测试的请求地址,用于测试会话 | ||
requestUrl: `${host}/weapp/user`, | ||
|
||
// 测试的信道服务地址 | ||
tunnelUrl: `${host}/weapp/tunnel`, | ||
|
||
// 上传图片接口 | ||
uploadUrl: `${host}/weapp/upload` | ||
} | ||
} | ||
|
||
module.exports = config |
Oops, something went wrong.