提交 72facb1d authored 作者: haodaking's avatar haodaking 提交者: 王鹏飞

feat:分享海报

上级 c26e822d
......@@ -15,3 +15,18 @@ export function getUser() {
export function logout() {
return httpRequest.get('/api/passport/rest/logout')
}
// 获取营销数据
export function getShare(data) {
return httpRequest.get(`/api/lms/v3/activities/share/${data.semester_id}/${data.course_id}/${data.chapter_id}`)
}
// 获取二维码
export function getQrcode(data) {
return httpRequest.get('/api/lms/util/pcode', data)
}
// 获取二维码
export function imageTransfer(data) {
return httpRequest.get('/api/usercenter/tool/transfer-image', data)
}
import * as api from './api/base.js'
import './utils/mtj-wx-sdk'
App({
store: {
pageshow: false,
user: {} // 用户信息
},
onLaunch: function () {},
onLaunch: function () {
// 加载自定义字体
// wx.loadFontFace({
// global: true,
// family: 'my',
// source: 'https://webapp-pub.ezijing.com/weapp/share/my.ttf',
// scopes: ['webview', 'native']
// })
},
onPageNotFound() {
wx.redirectTo({ url: 'pages/login/index' })
},
......
......@@ -16,7 +16,9 @@
"pages/learnSystem/myScore/myScore",
"pages/learnSystem/myDiscuss/myDiscuss",
"pages/learnSystem/discussDetail/discussDetail",
"pages/course/player"
"pages/course/player",
"pages/share/index",
"pages/web/index"
],
"window": {
"navigationBarBackgroundColor": "#fff",
......@@ -60,7 +62,7 @@
},
"plugins": {
"tencentvideo": {
"version": "2.0.5",
"version": "2.0.10",
"provider": "wxa75efa648b60994b"
}
},
......
import { getShare, getQrcode, imageTransfer } from '../../api/base.js'
import { wxml, style } from './share.js'
const app = getApp()
Component({
options: {
styleIsolation: 'shared'
},
/**
* 组件的属性列表
*/
properties: {
semesterId: { type: String, value: '' },
courseId: { type: String, value: '' },
chapterId: { type: String, value: '' },
isNeed: { type: Boolean, value: false }
},
/**
* 组件的初始数据
*/
data: {
show: false,
hasControls: false,
isPreivew: false,
user: {},
share: { lecturer: {} },
qrcode: '',
bgList: [
'https://webapp-pub.ezijing.com/weapp/share/marywood/bg/01.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/02.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/03.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/04.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/05.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/06.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/07.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/08.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/09.jpg',
'https://webapp-pub.ezijing.com/weapp/share/bg/01.jpg'
],
textList: [],
avatarList: [],
colorList: [
'#1D5434',
'#0E386B',
'#d78c4a',
'#f44336',
'#e91e63',
'#673ab7',
'#3f51b5',
'#2196f3',
'#00bcd4',
'#009688',
'#4caf50',
'#8bc34a',
'#cddc39',
'#ffeb3b',
'#ffc107',
'#ff9800',
'#ff5722',
'#795548',
'#9e9e9e',
'#607d8b'
],
controls: {
active: '0',
bg: 'https://webapp-pub.ezijing.com/weapp/share/marywood/bg/01.jpg',
text: '',
avatar: '',
color: '#1D5434'
},
controlsTabs: [
{ index: '0', text: '背景' },
{ index: '1', text: '金句' },
{ index: '3', text: '颜色' }
// { index: '2', text: '头像' }
],
wxUserProfile: {},
numLength: 1,
customText: '',
customTextVisible: false,
keyboardHeight: 0,
reportData: {} // 上报数据
},
lifetimes: {
attached() {
this.setData({
reportData: {
user_id: wx.getStorageSync('uid'),
course_id: this.data.courseId,
chapter_id: this.data.chapterId,
semester_id: this.data.semesterId
}
})
// 加载自定义字体
// wx.loadFontFace({ family: 'my', source: 'https://webapp-pub.ezijing.com/weapp/share/my.ttf' })
}
},
/**
* 组件的方法列表
*/
methods: {
init() {
// 触发分享海报上报
app.mtj.trackEvent('poster_trigger', this.data.reportData)
wx.reportEvent('poster_trigger', this.data.reportData)
this.getShare().then(res => {
if (!this.data.isNeed && !res.data.need_share) {
return
}
app.getUser().then(res => {
res.realname = res.realname || res.nickname
// 系统头像
const avatarList = []
avatarList.push({ name: '系统', url: res.avatar || 'https://webapp-pub.ezijing.com/weapp/share/default.jpg' })
// 微信头像
const localUserInfo = wx.getStorageSync('userInfo')
let wxUserProfile = localUserInfo ? JSON.parse(localUserInfo) : {}
if (wxUserProfile.avatarUrl) {
avatarList.push({ name: '微信', url: wxUserProfile.avatarUrl })
}
const [firstAvatar = {}] = avatarList
this.setData({ user: res, wxUserProfile, avatarList, show: true, 'controls.avatar': firstAvatar.url })
this.getQrcode()
})
// 显示分享海报上报
app.mtj.trackEvent('poster_show', this.data.reportData)
wx.reportEvent('poster_show', this.data.reportData)
})
},
// 获取营销数据
getShare() {
const params = {
semester_id: this.data.semesterId,
course_id: this.data.courseId,
chapter_id: this.data.chapterId
}
return getShare(params).then(res => {
const data = res.data
// data.sentences = ['If you think education is expensive, try ignorance.']
// data.course_name = '设计思维与管理创新'
// data.english_course_name = 'Organizational Behavior and Leadership'
// data.current_percent = '90'
// data.all_percent = '25'
const [lecturer = { lecturer_name: '' }] = data.lecturers
lecturer.lecturer_name = lecturer.lecturer_name ? lecturer.lecturer_name.replace(/(\(|()(.+)(\)|))/, '') : ''
data.course_name = data.course_name ? data.course_name.replace(/(\(|()(.+)(\)|))/, '') : ''
data.course_name = `《${data.course_name}》`
data.chapter_name = data.chapter_name ? data.chapter_name.replace(/(\(|()(.+)(\)|))/, '') : ''
data.chapter_name = data.chapter_name ? data.chapter_name.replace(/^.*\s/, '') : ''
data.chapter_name = data.chapter_name ? `“${data.chapter_name}”专题` : ''
const numLength = data.used_day.toString().length
// 金句设置
const textList = data.sentences.map(item => {
return { text: item }
})
if (textList.length) {
this.setData({ textList, 'controls.text': textList[0].text })
}
this.setData({ share: Object.assign(data, { lecturer }), numLength })
return res
})
},
// 生成二维码
getQrcode() {
const user = this.data.user
const params = {
url: `https://pages.ezijing.com/marywood/m204001490515.html?channel_num=96169&user_id=${user.id}&user_name=${user.realname}`
}
getQrcode(params).then(res => {
this.setData({ qrcode: res.url })
})
},
getUserProfile() {
// 获取微信头像
wx.getUserProfile({ desc: '使用头像生成海报' })
.then(res => {
const userInfo = res.userInfo
imageTransfer({ source: userInfo.avatarUrl }).then(res => {
userInfo.avatarUrl = res
this.data.avatarList.push({ name: '微信', url: userInfo.avatarUrl })
this.setData({ wxUserProfile: userInfo, avatarList: this.data.avatarList })
wx.setStorageSync('userInfo', JSON.stringify(userInfo))
})
})
.catch(() => {
wx.showToast({ title: '获取微信头像失败', icon: 'none' })
})
},
renderToCanvas() {
wx.showLoading({ title: '海报生成中' })
this.setData({ isPreivew: true }, () => {
this.widget = this.selectComponent('.widget')
setTimeout(() => {
this.widget
.renderToCanvas({ wxml: wxml(this.data), style: style(this.data) })
.then(res => {
wx.hideLoading()
})
.catch(error => {
console.log(error)
wx.hideLoading()
wx.showToast({ title: '海报生成失败', icon: 'none' })
})
}, 500)
})
// 生成分享海报上报
app.mtj.trackEvent('poster_generate', this.data.reportData)
wx.reportEvent('poster_generate', this.data.reportData)
},
// 导出图片
extraImage() {
this.widget.canvasToTempFilePath().then(res => {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath
})
.then(res => {
wx.showToast({ title: '保存成功', icon: 'none' })
})
.catch(error => {
wx.showToast({ title: '保存失败,请检查相册权限', icon: 'none' })
})
})
// 保存分享海报上报
app.mtj.trackEvent('poster_share', this.data.reportData)
wx.reportEvent('poster_share', this.data.reportData)
},
// 关闭分享
onClose() {
this.setData({ show: false })
},
// 背景|金句选项卡切换
onTabChange(e) {
const { index } = e.currentTarget.dataset
this.setData({ 'controls.active': index })
},
// 选择背景
onSelectImage(e) {
const { item } = e.currentTarget.dataset
this.setData({ 'controls.bg': item })
},
// 选择金句
onSelectText(e) {
const { item } = e.currentTarget.dataset
this.setData({ 'controls.text': item.text })
},
// 选择头像
onSelectAvatar(e) {
const { item } = e.currentTarget.dataset
this.setData({ 'controls.avatar': item.url })
},
// 选择颜色
onSelectColor(e) {
const { item } = e.currentTarget.dataset
this.setData({ 'controls.color': item })
},
// 控制栏显示隐藏
toggleControls() {
this.setData({ hasControls: !this.data.hasControls })
},
// 关闭预览
onClosePreview() {
this.setData({ isPreivew: false })
},
// 显示自定义金句
showCustomText() {
this.setData({ customTextVisible: true })
},
// 使用自定义金句
onCustomTextConfirm() {
if (this.data.customText) {
this.data.textList.unshift({ text: this.data.customText, isCustom: true })
this.setData({
'controls.text': this.data.customText,
textList: this.data.textList,
customTextVisible: false,
customText: ''
})
}
},
// 失去焦点
onCustomTextBlur() {
this.setData({ customTextVisible: false })
},
// 计算键盘高度
onKeyboardheightchange(e) {
this.setData({ keyboardHeight: e.detail.height })
},
// 删除自定义金句
onRemoveCustomText(e) {
const { index } = e.currentTarget.dataset
this.data.textList.splice(index, 1)
const found = this.data.textList.find(item => item.text === this.data.controls.text)
this.setData({
textList: this.data.textList,
'controls.text': found ? this.data.controls.text : this.data.textList[0].text
})
}
}
})
{
"component": true,
"usingComponents": {
"wxml-to-canvas": "wxml-to-canvas",
"van-icon": "@vant/weapp/icon/index"
}
}
<view class="share-page" wx:if="{{ show }}">
<view class="close" bindtap="onClose"></view>
<!-- 分享配置页面 -->
<view class="share-page-body">
<view class="share">
<image
src="{{ controls.bg }}?x-oss-process=image/resize,m_fill,h_1064,w_600"
mode="aspectFill"
class="bg"
></image>
<image
src="https://webapp-pub.ezijing.com/weapp/share/marywood/cover.png?x-oss-process=image/resize,m_fill,h_898,w_507"
mode="aspectFill"
class="cover"
></image>
<view class="main" style="color:{{ controls.color }};">
<view class="title">Zijing-Marywood University</view>
<view class="title">Master of Business Administration (MBA)</view>
<view class="day">
<text class="day-num">{{ share.used_day }}</text>
<text class="day-tips">Learning Days</text>
</view>
<view class="text">{{ controls.text }}</view>
<view class="box">
<view class="course">
<view class="course-en-name">{{ share.english_course_name }}</view>
<view class="course-name">{{ share.course_name }}</view>
</view>
<view class="progress">
<view class="progress-box">
<text class="progress-num">{{ share.current_percent }}</text>
<text class="progress-unit">%</text>
</view>
<text class="progress-completed">completed</text>
</view>
</view>
<view class="box">
<view class="progress">
<view class="progress-box">
<text class="progress-num">{{ share.all_percent }}</text>
<text class="progress-unit">%</text>
</view>
<text class="progress-completed">completed</text>
</view>
<view class="course-mba">MBA Learning Achievement</view>
</view>
<view class="footer">
<image src="{{ qrcode }}" class="qrcode"></image>
<view class="qrcode-tips">Scan to learn with me</view>
</view>
</view>
</view>
</view>
<!-- 控制栏 -->
<view class="controls {{ hasControls ? 'is-show' : '' }}">
<view class="buttons">
<image
src="https://webapp-pub.ezijing.com/weapp/share/controls_up.png"
mode="aspectFill"
class="wx-image"
hidden="{{ hasControls }}"
bindtap="toggleControls"
></image>
<image
src="https://webapp-pub.ezijing.com/weapp/share/controls_down.png"
mode="aspectFill"
class="wx-image"
hidden="{{ !hasControls }}"
bindtap="toggleControls"
></image>
<view class="button">
<text>生成</text><text>海报</text>
<button class="wx-button" open-type="getUserInfo" bindtap="renderToCanvas"></button>
</view>
</view>
<view class="controls-main">
<view class="controls-tabs">
<block wx:for="{{ controlsTabs }}" wx:key="index">
<view
class="controls-tab {{ controls.active === item.index ? 'is-active' : '' }}"
data-index="{{ item.index }}"
bindtap="onTabChange"
>{{ item.text }}</view
>
</block>
</view>
<scroll-view class="controls-scroll" scroll-x="{{ true }}">
<!-- 背景 -->
<view class="controls-content" hidden="{{ controls.active !== '0' }}">
<view
class="controls-bg-item {{ controls.bg === item ? 'is-active' : '' }}"
wx:for="{{ bgList }}"
wx:key="*this"
data-item="{{ item }}"
bindtap="onSelectImage"
>
<image
src="{{ item }}?x-oss-process=image/resize,m_fill,h_162,w_92"
mode="aspectFill"
class="image"
></image>
</view>
</view>
<!-- 金句 -->
<view class="controls-content" hidden="{{ controls.active !== '1' }}">
<!-- 自定义金句 -->
<view class="custom-text-button" bindtap="showCustomText">自定义金句</view>
<view
class="controls-text-item {{ controls.text === item.text ? 'is-active' : '' }}"
wx:for="{{ textList }}"
wx:key="text"
data-item="{{ item }}"
bindtap="onSelectText"
>{{ item.text }}
<view class="custom-text-remove" data-index="{{ index }}" catchtap="onRemoveCustomText">
<van-icon name="clear" size="20" color="#d78c4a" wx:if="{{ item.isCustom }}"></van-icon>
</view>
</view>
</view>
<!-- 头像 -->
<view class="controls-content" hidden="{{ controls.active !== '2' }}">
<view
class="controls-avatar-item {{ controls.avatar === item.url ? 'is-active' : '' }}"
wx:for="{{ avatarList }}"
wx:key="url"
data-item="{{ item }}"
bindtap="onSelectAvatar"
>
<image src="{{ item.url }}" mode="aspectFill" class="image"></image>
<text class="controls-avatar-item__text">{{ item.name }}</text>
</view>
<view class="controls-avatar-item" hidden="{{ wxUserProfile.avatarUrl }}">
<text>微信</text><text>头像</text>
<button class="wx-button" open-type="getUserInfo" bindtap="getUserProfile"></button>
</view>
</view>
<!-- 颜色 -->
<view class="controls-content" hidden="{{ controls.active !== '3' }}">
<view
class="controls-color-item {{ controls.color === item ? 'is-active' : '' }}"
wx:for="{{ colorList }}"
wx:key="*this"
data-item="{{ item }}"
bindtap="onSelectColor"
style="background-color:{{ item }}"
>{{ item }}</view
>
</view>
</scroll-view>
</view>
</view>
</view>
<!-- 自定义金句 -->
<view class="custom-text" wx:if="{{ customTextVisible }}" style="bottom:{{ keyboardHeight }}px;">
<textarea
class="wx-textarea"
placeholder="输入自定义金句"
model:value="{{ customText }}"
maxlength="30"
cursor-spacing="30"
confirm-type="done"
show-confirm-bar="{{ false }}"
auto-focus="{{ true }}"
fixed="{{ true }}"
adjust-position="{{ false }}"
bindconfirm="onCustomTextConfirm"
bindblur="onCustomTextBlur"
bindkeyboardheightchange="onKeyboardheightchange"
></textarea>
</view>
<!-- 预览页面 -->
<view class="share-preivew" wx:if="{{ isPreivew }}">
<view class="close" bindtap="onClosePreview"></view>
<view class="share-preivew-main">
<wxml-to-canvas class="widget" width="300" height="530"></wxml-to-canvas>
</view>
<view class="share-preview-footer">
<view class="button button-default" bindtap="extraImage">保存图片到相册</view>
<view class="tips">分享图片到朋友圈</view>
<view class="tips">最高可获得5000朵紫荆花</view>
</view>
</view>
.share-page {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 100;
display: flex;
flex-direction: column;
}
.share-page-body {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
overflow-x: hidden;
overflow-y: auto;
}
.share {
width: 300px;
height: 530px;
position: relative;
overflow: hidden;
}
.bg {
width: 300px;
height: 530px;
}
.cover {
position: absolute;
top: 42px;
left: 24px;
width: 254px;
height: 449px;
}
.main {
position: absolute;
left: 45px;
top: 95px;
width: 210px;
color: #d78c4a;
}
.title {
text-align: center;
font-size: 10px;
font-weight: bold;
line-height: 16px;
white-space: nowrap;
}
.day {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 130px;
height: 130px;
margin: 15px auto 0;
background: url(https://webapp-pub.ezijing.com/weapp/share/marywood/roud_bg.png) no-repeat;
background-size: contain;
}
.day-num {
font-size: 48px;
line-height: 48px;
color: #f1ae2c;
}
.day-tips {
font-size: 14px;
color: #fff;
}
.text {
margin-top: 18px;
margin-bottom: 10px;
font-size: 9px;
line-height: 14px;
word-break: break-word;
overflow: hidden;
border-bottom: 1px solid #f1ae2c;
padding-bottom: 6px;
}
.box {
display: flex;
align-items: center;
}
.course {
flex: 1;
}
.course-en-name {
font-size: 12px;
line-height: 12px;
}
.course-name {
font-size: 11px;
margin-left: -6px;
}
.course-mba {
flex: 1;
font-size: 12px;
text-align: right;
}
.progress {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.progress-box {
text-align: center;
height: 30px;
overflow: hidden;
}
.progress-num {
font-style: italic;
font-size: 30px;
line-height: 1;
}
.progress-unit {
font-size: 16px;
line-height: 1;
}
.progress-completed {
font-size: 11px;
line-height: 1;
}
.footer {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid #f1ae2c;
}
.qrcode {
width: 37px;
height: 37px;
border: 1px solid #1d5434;
border-radius: 2px;
}
.qrcode-tips {
margin-top: 3px;
font-size: 8px;
line-height: 10px;
text-align: center;
}
.controls {
position: relative;
padding-bottom: env(safe-area-inset-bottom);
}
.controls-main {
height: 0;
transition: height 0.3s;
overflow: hidden;
}
.controls.is-show {
background-color: #fff;
}
.controls.is-show .controls-main {
height: 130px;
}
.buttons {
position: absolute;
top: -66px;
left: 0;
right: 0;
display: flex;
justify-content: space-between;
padding: 8px 13px;
}
.button {
position: relative;
width: 50px;
height: 50px;
background: #ffffff;
box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
border-radius: 50%;
font-size: 13px;
color: #d78c4a;
line-height: 15px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.wx-image {
width: 50px;
height: 50px;
}
.wx-button {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: transparent;
border: 0;
}
button:after {
content: none;
}
button::after {
border: none;
}
.controls-tabs {
display: flex;
height: 30px;
background: #ccc;
}
.controls-tab {
width: 75px;
line-height: 30px;
text-align: center;
background-color: #e6e6e6;
}
.controls-tab.is-active {
color: #d78c4a;
background-color: #fff;
}
.controls-content {
flex: 1;
height: 100px;
padding: 0 10px;
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.controls-content .is-active {
border: 3px solid #d78c4a;
}
.controls-bg-item {
flex: 0 0 46px;
width: 46px;
height: 80px;
margin: 0 15px;
border: 3px solid #fff;
border-radius: 3px;
overflow: hidden;
}
.controls-text-item {
position: relative;
margin: 0 15px;
flex: 0 0 228px;
width: 228px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid #ccc;
border-radius: 6px;
padding: 10px;
font-size: 13px;
color: #1a1a1a;
line-height: 18px;
box-sizing: border-box;
text-overflow: ellipsis;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.controls-avatar-item {
position: relative;
margin: 0 15px;
flex: 0 0 60px;
width: 60px;
height: 60px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border: 3px solid #ccc;
border-radius: 50%;
overflow: hidden;
font-size: 13px;
color: #1a1a1a;
line-height: 18px;
box-sizing: border-box;
}
.controls-avatar-item__text {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(255, 255, 255, 0.6);
z-index: 1;
text-align: center;
font-size: 12px;
}
.controls-color-item {
margin: 0 15px;
flex: 0 0 68px;
width: 68px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid #ccc;
border-radius: 6px;
overflow: hidden;
padding: 10px;
font-size: 13px;
color: #fff;
line-height: 18px;
box-sizing: border-box;
}
.image {
width: 100%;
height: 100%;
}
.share-preivew {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 200;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 38px 0;
}
.close {
position: absolute;
right: 8px;
top: 8px;
width: 48px;
height: 48px;
background: url('https://webapp-pub.ezijing.com/weapp/share/close.png') no-repeat;
background-size: contain;
z-index: 999;
}
.share-preivew-main {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
overflow-x: hidden;
overflow-y: auto;
}
.share-preivew .button {
width: 250px;
height: 50px;
border-radius: 25px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 18px 0;
font-size: 13px;
font-weight: 400;
color: #d78c4a;
line-height: 15px;
}
.share-preivew .button-default {
color: #d78c4a;
background: #fff;
}
.share-preivew .button-primary {
color: #fff;
background: #d78c4a;
}
.share-preivew .tips {
font-size: 13px;
font-weight: 400;
color: #fff;
line-height: 15px;
text-align: center;
}
.wx-textarea {
padding: 10px;
height: 100%;
}
.custom-text-button {
margin: 0 15px;
flex: 0 0 100px;
height: 60px;
display: flex;
align-items: center;
justify-content: center;
border: 3px solid #ccc;
border-radius: 6px;
overflow: hidden;
padding: 10px;
font-size: 13px;
color: #1a1a1a;
line-height: 18px;
box-sizing: border-box;
}
.custom-text {
position: fixed;
left: 0;
right: 0;
bottom: 0;
height: 60px;
background-color: #fff;
z-index: 100;
}
.custom-text-remove {
position: absolute;
right: -20px;
top: -20px;
padding: 10px;
}
.custom-text-remove .van-icon {
background-color: #fff;
}
const wxml = function (data) {
return `
<view class="share">
<image src="${data.controls.bg}?x-oss-process=image/resize,m_fill,h_530,w_300" class="bg"></image>
<image src="https://webapp-pub.ezijing.com/weapp/share/marywood/cover.png" class="cover"></image>
<view class="main">
<text class="title">Zijing-Marywood University</text>
<text class="title">Master of Business Administration (MBA)</text>
<view class="day">
<image src="https://webapp-pub.ezijing.com/weapp/share/marywood/roud_bg.png?x-oss-process=image/resize,m_fill,h_130,w_130" class="day-bg"></image>
<view class="day-inner">
<text class="day-num">${data.share.used_day}</text>
<text class="day-tips">Learning Days</text>
</view>
</view>
<text class="text">${data.controls.text}</text>
<view class="line"></view>
<view class="box">
<view class="course">
<text class="course-en-name">${data.share.english_course_name}</text>
<text class="course-name">${data.share.course_name}</text>
</view>
<view class="progress">
<view class="progress-box">
<text class="progress-num">${data.share.current_percent}</text>
<text class="progress-unit">%</text>
</view>
<text class="progress-completed">completed</text>
</view>
</view>
<view class="box">
<view class="progress">
<view class="progress-box">
<text class="progress-num">${data.share.all_percent}</text>
<text class="progress-unit">%</text>
</view>
<text class="progress-completed">completed</text>
</view>
<text class="course-mba">MBA Learning Achievement</text>
</view>
<view class="line"></view>
<image src="${data.qrcode}" class="qrcode"></image>
<text class="qrcode-tips">Scan to learn with me</text>
</view>
</view>`
}
const style = function (data) {
const numLength = data.share.used_day.toString().length
return {
share: {
position: 'relative',
width: 300,
height: 530
},
bg: {
width: 300,
height: 530
},
cover: {
position: 'absolute',
top: 42,
left: 24,
width: 254,
height: 449
},
main: {
position: 'absolute',
left: 45,
top: 95,
width: 210,
height: 300,
alignItems: 'center',
color: data.controls.color
},
title: {
width: 210,
textAlign: 'center',
fontSize: 10,
lineHeight: 16,
fontWeight: 'bold',
height: 16
},
day: {
position: 'relative',
width: 130,
height: 130,
marginTop: 15
},
dayBg: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 0
},
dayInner: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 0,
flexDirection: 'column',
justifyContent: 'center',
textAlign: 'center'
},
dayNum: {
height: 48,
fontSize: 48,
lineHeight: 48,
color: '#f1ae2c'
},
dayTips: {
height: 20,
fontSize: 14,
color: '#fff'
},
line: {
marginTop: 8,
width: 210,
height: 1,
backgroundColor: '#F1AE2C'
},
text: {
marginTop: 18,
width: 210,
height: 14,
fontSize: 9,
lineHeight: 14,
textAlign: 'center'
},
box: {
marginTop: 8,
width: 210,
color: data.controls.color,
flexDirection: 'row',
alignItems: 'center'
},
course: {
width: 160,
height: 40
},
courseEnName: {
height: 24,
fontSize: 12,
fontWeight: 500,
lineHeight: 12
},
courseName: {
marginLeft: -5,
marginTop: 5,
height: 11,
fontSize: 11,
fontWeight: 400,
lineHeight: 11
},
courseMba: {
width: 160,
height: 12,
fontSize: 12,
fontWeight: 500,
lineHeight: 12,
textAlign: 'right'
},
progress: {
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: 50,
height: 38
},
progressBox: {
flexDirection: 'row',
alignItems: 'flex-end',
width: 50,
height: 28
},
progressNum: {
width: 36,
height: 28,
fontSize: 28,
fontStyle: 'italic',
lineHeight: 28,
textAlign: 'right'
},
progressUnit: {
width: 14,
height: 14,
fontSize: 14,
lineHeight: 14
},
progressCompleted: {
marginTop: -2,
width: 50,
height: 11,
fontSize: 10,
fontWeight: 300,
lineHeight: 10,
textAlign: 'right'
},
qrcode: {
marginTop: 8,
width: 37,
height: 37,
borderRadius: 2,
backgroundColor: data.controls.color
},
qrcodeTips: {
width: 210,
height: 15,
marginTop: 3,
fontSize: 8,
color: data.controls.color,
lineHeight: 8,
textAlign: 'center'
}
}
}
export { wxml, style }
{
"name": "learn-weapp",
"version": "1.0.0",
"lockfileVersion": 1,
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "learn-weapp",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@vant/weapp": "^1.6.5",
"miniprogram-computed": "^2.2.0",
"wxml-to-canvas": "^1.1.1"
}
},
"node_modules/@vant/weapp": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/@vant/weapp/-/weapp-1.6.5.tgz",
"integrity": "sha512-7+oNnlLIcHSqcwtzAKSM2LM+feXyfNIEOedHn5yDumPQPyGPDmsY6x5vwZ88i+sZspfj4HmzfeljJQ/rtDT0cg=="
},
"node_modules/eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmmirror.com/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"node_modules/fast-deep-equal": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",
"integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk="
},
"node_modules/miniprogram-computed": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/miniprogram-computed/-/miniprogram-computed-2.2.0.tgz",
"integrity": "sha512-UlPfPh5cvBnwb2jNXToUMxNkWAmi8a7hAjtJlwdA4XF5EbFI5Q5jI9mn1U8AAxbsUfnSf1Vmsc0LhkxGdKlRkg==",
"dependencies": {
"fast-deep-equal": "^2.0.1",
"rfdc": "^1.1.4"
}
},
"node_modules/rfdc": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.2.0.tgz",
"integrity": "sha512-ijLyszTMmUrXvjSooucVQwimGUk84eRcmCuLV8Xghe3UO85mjUtRAHRyoMM6XtyqbECaXuBWx18La3523sXINA=="
},
"node_modules/widget-ui": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/widget-ui/-/widget-ui-1.0.2.tgz",
"integrity": "sha512-gDXosr5mflJdMA1weU1A47aTsTFfMJhfA4EKgO5XFebY3eVklf80KD4GODfrjo8J2WQ+9YjL1Rd9UUmKIzhShw==",
"dependencies": {
"eventemitter3": "^4.0.0"
}
},
"node_modules/wxml-to-canvas": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/wxml-to-canvas/-/wxml-to-canvas-1.1.1.tgz",
"integrity": "sha512-3mDjHzujY/UgdCOXij/MnmwJYerVjwkyQHMBFBE8zh89DK7h7UTzoydWFqEBjIC0rfZM+AXl5kDh9hUcsNpSmg==",
"dependencies": {
"widget-ui": "^1.0.2"
}
}
},
"dependencies": {
"@vant/weapp": {
"version": "1.6.5",
"resolved": "https://registry.npmjs.org/@vant/weapp/-/weapp-1.6.5.tgz",
"integrity": "sha512-7+oNnlLIcHSqcwtzAKSM2LM+feXyfNIEOedHn5yDumPQPyGPDmsY6x5vwZ88i+sZspfj4HmzfeljJQ/rtDT0cg=="
},
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmmirror.com/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"fast-deep-equal": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz",
......@@ -27,6 +89,22 @@
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.2.0.tgz",
"integrity": "sha512-ijLyszTMmUrXvjSooucVQwimGUk84eRcmCuLV8Xghe3UO85mjUtRAHRyoMM6XtyqbECaXuBWx18La3523sXINA=="
},
"widget-ui": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/widget-ui/-/widget-ui-1.0.2.tgz",
"integrity": "sha512-gDXosr5mflJdMA1weU1A47aTsTFfMJhfA4EKgO5XFebY3eVklf80KD4GODfrjo8J2WQ+9YjL1Rd9UUmKIzhShw==",
"requires": {
"eventemitter3": "^4.0.0"
}
},
"wxml-to-canvas": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/wxml-to-canvas/-/wxml-to-canvas-1.1.1.tgz",
"integrity": "sha512-3mDjHzujY/UgdCOXij/MnmwJYerVjwkyQHMBFBE8zh89DK7h7UTzoydWFqEBjIC0rfZM+AXl5kDh9hUcsNpSmg==",
"requires": {
"widget-ui": "^1.0.2"
}
}
}
}
......@@ -5,9 +5,9 @@
"main": "app.js",
"dependencies": {
"@vant/weapp": "^1.6.5",
"miniprogram-computed": "^2.2.0"
"miniprogram-computed": "^2.2.0",
"wxml-to-canvas": "^1.1.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
......
......@@ -168,6 +168,9 @@ Page({
// 更新chapter
this.updateActiveChapter(this.data.nextChapter)
}
// 分享海报
const share = this.selectComponent('.share')
share.init()
},
// 当前播放时间更新
onTimeupdate(e) {
......
......@@ -3,6 +3,7 @@
"navigationBarTitleText": "",
"usingComponents": {
"player-video": "/components/player/video",
"player-audio": "/components/player/audio"
"player-audio": "/components/player/audio",
"share": "/components/share/index"
}
}
......@@ -71,3 +71,5 @@
</van-tabs>
</view>
</view>
<!-- 分享海报 -->
<share semesterId="{{ semesterId }}" courseId="{{ courseId }}" chapterId="{{ chapterId }}" class="share"></share>
......@@ -29,7 +29,7 @@ Page({
handleRequest(params) {
api.login(params).then(response => {
const { code, msg, data } = response
code === 0 ? this.handleSuccess(data) : wx.showToast({ title: msg, icon: 'none' })
code === 0 ? this.handleSuccess(data) : this.handleError(response)
})
},
// 登录成功
......@@ -37,6 +37,20 @@ Page({
wx.setStorage({ key: 'token', data: data.TGC })
wx.switchTab({ url: '/pages/learnSystem/home/home' })
},
handleError(response) {
if (response.msg === '账号不存在') {
wx.showModal({ title: '账号不存在', content: '是否要成为学员', showCancel: true }).then(res => {
res.confirm &&
wx.navigateTo({
url: `/pages/web/index?url=${encodeURIComponent(
'https://webapp-pub.ezijing.com/pages/marywood/marywood.html?channel_num=96169'
)}`
})
})
} else {
wx.showToast({ title: response.msg, icon: 'none' })
}
},
handlePassword() {
wx.navigateTo({ url: '/pages/login/password' })
}
......
......@@ -63,22 +63,33 @@ Page({
},
// 微信登录
wechatLogin() {
// 获取code
// 获取code
const p1 = this.getCode()
// 获取用户信息
const p2 = this.getUserInfo()
Promise.all([p1, p2]).then(([code, user]) => {
const { encryptedData, iv } = user
api.wechatLogin({ encryptedData, iv, code, identity: 'marywood-mini' }).then(response => {
if (response.code === 0) {
this.handleSuccess(response.data)
} else if (response.code === 2) {
// 绑定手机号
this.setData({ show: true, unionid: response.data.unionid })
api.wechatLogin({ encryptedData, iv, code, identity: 'marywood-mini' }).then(response => {
if (response.code === 0) {
this.handleSuccess(response.data)
} else if (response.code === 2) {
// 绑定手机号
this.setData({ show: true, unionid: response.data.unionid })
} else {
if (response.msg === '账号不存在') {
wx.showModal({ title: '账号不存在', content: '是否要成为学员', showCancel: true }).then(res => {
res.confirm &&
wx.navigateTo({
url: `/pages/web/index?url=${encodeURIComponent(
'https://webapp-pub.ezijing.com/pages/marywood/marywood.html?channel_num=96169'
)}`
})
})
} else {
wx.showToast({ title: response.msg, icon: 'none' })
}
})
}
})
})
},
// 手机号登录
......
......@@ -30,7 +30,7 @@ Page({
handleRequest(params) {
api.login(params).then(response => {
const { code, msg, data } = response
code === 0 ? this.handleSuccess(data) : wx.showToast({ title: msg, icon: 'none' })
code === 0 ? this.handleSuccess(data) : this.handleError(response)
})
},
// 登录成功
......@@ -38,6 +38,20 @@ Page({
wx.setStorage({ key: 'token', data: data.TGC })
wx.switchTab({ url: '/pages/learnSystem/home/home' })
},
handleError(response) {
if (response.msg === '账号不存在') {
wx.showModal({ title: '账号不存在', content: '是否要成为学员', showCancel: true }).then(res => {
res.confirm &&
wx.navigateTo({
url: `/pages/web/index?url=${encodeURIComponent(
'https://webapp-pub.ezijing.com/pages/marywood/marywood.html?channel_num=96169'
)}`
})
})
} else {
wx.showToast({ title: response.msg, icon: 'none' })
}
},
// 发送验证码
handleSendCode() {
if (this.data.disabled) {
......
// pages/share.js
Page({
/**
* 页面的初始数据
*/
data: {},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
// 分享海报
const share = this.selectComponent('.share')
share.init()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})
{
"usingComponents": {
"share": "/components/share/index"
}
}
<share semesterId="6741976022452797440" courseId="6778237795518382080" chapterId="6347105800455979008" class="share" isNeed="{{ true }}"></share>
/* pages/share.wxss */
\ No newline at end of file
// pages/web/index.js
Page({
/**
* 页面的初始数据
*/
data: {
url: 'https://webapp-pub.ezijing.com/pages/marywood/marywood.html?channel_num=96169'
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const { url } = options
url && this.setData({ url: decodeURIComponent(url) })
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {}
})
{
"usingComponents": {}
}
\ No newline at end of file
<web-view src="{{ url }}"></web-view>
/* pages/web/index.wxss */
\ No newline at end of file
{
"description": "项目配置文件",
"description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"setting": {
"urlCheck": true,
"es6": true,
......@@ -26,20 +26,22 @@
"disablePlugins": [],
"outputPath": ""
},
"bundle": false,
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true
"minifyWXSS": true,
"disableUseStrict": false,
"showES6CompileOption": false,
"useCompilerPlugins": false,
"ignoreUploadUnusedFiles": true,
"useStaticServer": true,
"minifyWXML": true
},
"compileType": "miniprogram",
"libVersion": "2.21.3",
"appid": "wx6ca59cfb726d4b14",
"projectname": "learnOnline",
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
......@@ -98,5 +100,13 @@
}
]
}
},
"packOptions": {
"ignore": [],
"include": []
},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
\ No newline at end of file
{
"setting": {},
"condition": {
"plugin": {
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [
{
......@@ -77,8 +68,23 @@
"pathName": "pages/learnSystem/courseContent/courseContent",
"query": "id=6437333026132197376&sid=6552021107166150656",
"scene": null
},
{
"name": "",
"pathName": "pages/course/player",
"query": "semester_id=6828559258263486464&id=6828563846890782720&chapter_id=6828563669006155776",
"launchMode": "default",
"scene": null
},
{
"name": "",
"pathName": "pages/share/index",
"query": "semester_id=6828559258263486464&id=6828563846890782720&chapter_id=6828563669006155776",
"launchMode": "default",
"scene": null
}
]
}
}
},
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html"
}
\ No newline at end of file
/**
* @file 百度移动统计配置文件
*/
module.exports = {
/**
* 从百度移动统计获取的AppKey
* @type {string}
*/
appKey: '079cfa4c62',
/**
* 是否使用了插件
* @type {boolean}
*/
hasPlugin: false,
/**
* 是否获取当前的地理位置和速度信息
* @type {boolean}
*/
getLocation: false,
/**
* 是否获取组件滚动信息
* @type {boolean}
*/
getComponentScroll: false,
};
var mtjwxsdk=function(e){"use strict";var t,n,r="1.10.13",o="https://hmma.baidu.com/mini.gif",i={app:["onShow","onHide","onError"],page:["onShow","onHide","onPageScroll"],share:["onShareAppMessage"],behavior:["tap"]},a="mtj_uuid",c="mtj_user",u="mtj_user_property",s="mtj_track_status",f="mtj_remote_config",l={},p={type:1},h={aso:{}},g={},d=function(){return"undefined"!=typeof crypto&&crypto.getRandomValues?crypto.getRandomValues(new Uint32Array(1))[0]:Math.floor(4294967295*Math.random())},y=function(e,t){return"[object "+t+"]"==={}.toString.call(e)},m=function(e,t,n){var r=(e=e.replace(new RegExp(t+"=[^&]*","g"),"").replace(/(\?|&)&/g,"$1").replace(/(\?|&)$/g,"")).indexOf("?")>0?"&":"?";return e+r+t+"="+encodeURIComponent(n)},v=function e(t){return y(t,"Object")||y(t,"Array")?(Object.keys(t).forEach((function(n){var r=t[n];y(r,"Object")||y(r,"Array")?t[n]=e(r):t[n]=""+r})),t):t},j=function(e){return y(e,"String")&&/^[a-z][a-z0-9_]{0,31}$/.test(e)},b=function(e){return y(e,"String")&&/^[a-z0-9_]{1,32}$/.test(e)},S=function(e){return y(e,"String")||y(e,"Number")},O=function(e){return y(e,"String")&&/^\d{11}$/.test(e)},k=function(e){return y(e,"String")&&28===e.length},w=0,P=function(e){return new Promise((function(n,o){return e.data=e.data||{},l.blacklist&&(l.blacklist.indexOf("all")>-1&&e.data.et||l.blacklist.indexOf("behavior")>-1&&"behavior"===e.data.et)?n():(e.data.v=r,e.data.rqc=++w,i=e.data,JSON.stringify(i).length<=204800?(e.success=function(e){return n(e)},e.fail=function(e){return o(e)},void function(e){if(!1!==l.trackStatus){var n=e.data.et?{mtj_ii:e.data.uuid||"",mtj_et:e.data.et,mtj_en:e.data.en}:{};t.request({url:e.url,data:e.data,header:Object.assign({"content-type":"application/json"},n,e.header),method:e.method||"POST",dataType:e.dataType||"json",success:function(t){e.success&&e.success(t)},fail:function(t){e.fail&&e.fail(t)}})}}(e)):(w--,o(new Error("invalid data"))));var i}))},_=function(e,t){var n=y(t,"Object")?JSON.stringify(t):""+t;P({url:o,dataType:"string",data:Object.assign({},p,{et:"error",en:e,ep:{ex:n},rid:d()})})},T=function(e){e.rid=d(),e.aso=e.aso||{};var t={url:o,dataType:"string",data:Object.assign({},p,e)};P(t),(g.circleToken||g.circleByThreeFingers)&&("page"===e.et&&"show"===e.en||"behavior"===e.et&&"tap"===e.en)&&(t.url="https://hmma.baidu.com/mini.gif?circle=1",t.data.token=g.circleToken,P(t).catch((function(e){return console.error(e)})))};function I(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==n)return;var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var E=function(e){try{return t.getStorageSync(e)}catch(e){_("getStorageSync",e)}},x=function(e,n){try{t.setStorageSync(e,n)}catch(e){_("setStorageSync",e)}},q=function(){return Promise.resolve().then((function(){var e=E(a);return y(e,"String")&&32===e.length||(e=([1e7]+1e3+4e3+8e3+1e11).replace(/[018]/g,(function(e){return(e^("undefined"!=typeof crypto&&crypto.getRandomValues?crypto.getRandomValues(new Uint8Array(1))[0]:Math.floor(255*Math.random()))&15>>e/4).toString(16)})),x(a,e)),e}))},N=function(e){return new Promise((function(n){if(!e)return n();t.getShareInfo({shareTicket:e,success:function(e){delete e.errMsg,n(e)},fail:function(){n({})}})}))},M=function(){return n||(p.sid=d(),p.rqc=0,n=Promise.all([q(),new Promise((function(e){t.getSystemInfo({success:function(t){delete t.errMsg,e(t)},fail:function(){e({})}})})),new Promise((function(e){t.getNetworkType({success:function(t){delete t.errMsg,e(t)},fail:function(){e({})}})})),Promise.resolve().then((function(){var e=E(c),n=y(e,"Object")?e:{};return new Promise((function(e){t.getSetting({success:function(r){r.authSetting&&r.authSetting["scope.userInfo"]?t.getUserInfo({success:function(t){delete t.userInfo.errMsg,e(Object.assign(n,t.userInfo))},fail:function(){e(n)}}):e(n)},fail:function(){e(n)}})}))})),new Promise((function(e){if(!l.getLocation)return e({});t.getLocation({type:"wgs84",success:function(t){delete t.errMsg,e(t)},fail:function(){e({})}})})),Promise.resolve().then((function(){var e=E(u);return y(e,"Object")?e:{}}))]).then((function(e){var t=I(e,6),n=t[0],o=t[1],i=t[2],a=t[3],c=t[4],u=t[5];p.uuid=n,h.system=v(o),h.network=v(i),Object.keys(a).length>0&&(h.user=v(a)),Object.keys(c).length>0&&(h.location=v(c)),Object.keys(u).length>0&&(h.userProperty=JSON.stringify(u)),"devtools"===h.system.platform&&l.latestVersion&&function(e,t){for(var n=e.split("."),r=t.split("."),o=0;o<3;o++){var i=+n[o]||0,a=+r[o]||0;if(i>a)return 1;if(a>i)return-1}return 0}(r,l.latestVersion)<0&&console.warn("百度移动统计微信小程序SDK已更新,为不影响您的正常使用,请到SDK下载中心 https://mtj.baidu.com/web/sdk/index 下载最新版本")})))},C={onShow:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=(h.aso.query||[]).filter((function(e){return 0===e.key.indexOf("mtj_")}));return h.aso.scene=""+(e.scene||""),e.referrerInfo&&e.referrerInfo.appId?h.aso.referrerInfo=e.referrerInfo:delete h.aso.referrerInfo,h.aso.path=e.path||"",h.aso.query=Object.keys(e.query||{}).map((function(t){return{key:t,value:e.query[t]}})),t.length>0&&!/(^|,)mtj_/.test(Object.keys(e.query||{}).join(","))&&(h.aso.query=h.aso.query.concat(t)),(e.query||{}).mtj_ctoken&&!l.disableCircling&&(g.circleToken=e.query.mtj_ctoken),M().then((function(){return N(e.shareTicket)})).then((function(e){e?h.aso.shareInfo=e:delete h.aso.shareInfo,T(Object.assign({et:"app",en:"show"},h))})).catch((function(e){_("app.onShow",e)}))},onHide:function(){T({et:"app",en:"hide"})},onError:function(e){var t=y(e,"Object")?JSON.stringify(v(e)):""+e;T({et:"app",en:"error",ep:{ex:t}})}},U=-1,J=-1,R=0,B={onShow:function(){var e=getCurrentPages(),t=e[e.length-1];return p.path=t.route,p.query=Object.keys(t.options).map((function(e){return{key:e,value:t.options[e]}})).filter((function(e){return"mtj_qrid"!==e.key&&"mtj_lkid"!==e.key&&"mtj_shuuid"!==e.key})),p.path===g.lastPagePath&&JSON.stringify(p.query)===g.lastPageQuery||(g.lastPagePath=p.path,g.lastPageQuery=JSON.stringify(p.query),g.pageScrollTop=0),M().then((function(){T(Object.assign({et:"page",en:"show"},h))})).catch((function(e){_("page.onShow",e)}))},onHide:function(){var e,n,r,o,i,a=v({scrollTop:g.pageScrollTop,height:null===(e=h.system)||void 0===e||null===(n=e.safeArea)||void 0===n?void 0:n.height,width:null===(r=h.system)||void 0===r||null===(o=r.safeArea)||void 0===o?void 0:o.width}),c=Object.keys(a).map((function(e){return{key:e,value:a[e]}}));if(T({et:"page",en:"hide",ep:{data:c}}),l.getComponentScroll)try{i=JSON.parse(JSON.stringify(p)),t.createSelectorQuery().selectAll(".mtj-scroll").fields({id:!0,size:!0,scrollOffset:!0}).exec((function(e){Object.keys(e[0]).length>0&&T(Object.assign({et:"page",en:"scroll",ep:v(e[0])},i))}))}catch(e){_("page.trackComponentScrollEvent",e)}},onPageScroll:function(e){(!g.pageScrollTop||e.scrollTop>g.pageScrollTop)&&(g.pageScrollTop=e.scrollTop)},onShareAppMessage:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n={from:e.from,path:t.path};if(!n.path){var r=p.query.map((function(e){return e.key+"="+e.value})).join("&");n.path=p.path+(r?"?"+r:"")}t.title&&(n.title=""+t.title),e.target&&(n.target=JSON.stringify(e.target)),T(Object.assign({et:"share",en:"action",ep:n},h));var o=h.aso.query.filter((function(e){return"mtj_shuuid"===e.key})),i=o[0]?o[0].value.split("_"):[];p.uuid!==i[i.length-1]&&i.push(p.uuid);var a=i.slice(Math.max(0,i.length-3)).join("_");return t.path=m(n.path,"mtj_shuuid",a),t},onAction:function(e,t){if(e&&e.type&&e.currentTarget){var n="#"+(e.currentTarget.id||t);if("tap"!==e.type){if("touchmove"===e.type&&-1===U&&e.touches instanceof Array&&3===e.touches.length){if(R+=1,clearTimeout(J),3===R)return g.circleByThreeFingers=!0,g.circleToken=void 0,void T(Object.assign({et:"page",en:"show"},h));U=setTimeout((function(){U=-1,J=setTimeout((function(){R=0}),500)}),1e3)}}else{var r=[{key:"xpath",value:n}];T(Object.assign({et:"behavior",en:"tap",ep:{data:r}},h))}}}},V={trackEvent:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!j(e))return Promise.reject(new Error("事件名称不合法"));var n=Object.keys(t).filter((function(e){return b(e)&&S(t[e])})).map((function(e){return{key:""+e,value:""+t[e],type:y(t[e],"String")?"string":"number"}}));return M().then((function(){T(Object.assign({et:"event",en:""+e,ep:{data:n}},h))})).catch((function(e){_("trackEvent",e)}))},setTrackStatus:function(e){y(e,"Boolean")&&(l.trackStatus=e,x(s,e))},setUserInfo:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.tel,n=e.openId;return M().then((function(){var e=E(c),r=y(e,"Object")?e:{};O(t)&&(r.tel=h.user.tel=t.substr(t.length-11)),k(n)&&(r.openId=h.user.openId=n),(r.tel||r.openId)&&x(c,r),y(t,"Undefined")||O(t)||console.error("手机号 ".concat(t," 不合法")),y(n,"Undefined")||k(n)||console.error("openid ".concat(n," 不合法"))})).catch((function(e){_("setUserInfo",e)}))},setUserId:function(e){return Promise.resolve().then((function(){if(!(y(e,"String")||y(e,"Number")&&Number.isFinite(e)))return Promise.reject(new Error("userId只能是字符串或数字"));var t=""+e,n=E(u),r=y(n,"Object")?n:{};if(!r.uid_||r.uid_[0]!==t){r.uid_=[t,"1"],x(u,r),h.userProperty=JSON.stringify(r);var o=[{key:"uid",value:t}];return M().then((function(){T(Object.assign({et:"api",en:"setUserId",ep:{data:o}},h))})).catch((function(e){_("setUserId",e)}))}}))},setUserProperty:function(e){return Promise.resolve().then((function(){var t=E(u),n=y(t,"Object")?t:{};if(y(e,"Null"))Object.keys(n).forEach((function(e){"_"!==e.charAt(0)&&"_"!==e.charAt(e.length-1)&&delete n[e]}));else if(!y(e,"Object"))return Promise.reject(new Error("userProperty必须是对象"));var r=Object.keys(n).filter((function(e){return"_"!==e.charAt(0)&&"_"!==e.charAt(e.length-1)})).length;Object.keys(e||{}).forEach((function(t){var o=e[t];""!==t&&"_"!==t.charAt(0)&&"_"!==t.charAt(t.length-1)&&(y(o,"Null")?n[t]&&(delete n[t],r--):!(y(o,"String")||y(o,"Number")&&Number.isFinite(o))||t.length>256||(""+o).length>256||!n[t]&&r>=100||(n[t]||r++,n[t]=[o,"1"]))})),x(u,n),h.userProperty=JSON.stringify(n)}))}},$=function(e,t,n){var r=t[e];t[e]=function(t){if(n.call(this,t,e),r)return r.apply(this,arguments)}},K=App,z=function(e){i.app.forEach((function(t){$(t,e,C[t])})),e.mtj=V,e.mtj.pageEvent=B,K(e)},D=Page,F=function(e){i.page.forEach((function(t){$(t,e,B[t])})),i.share.forEach((function(t){!function(e,t,n){var r=t[e];t[e]=function(e){var t=r&&r.apply(this,arguments);return n.call(this,e,t)}}(t,e,B[t])})),Object.keys(e).forEach((function(t){"function"==typeof e[t]&&-1===i.page.indexOf(t)&&-1===i.share.indexOf(t)&&$(t,e,B.onAction)})),D(e)},H=Behavior,L=function(e){return i.page.forEach((function(t){$(t,e.methods,B[t])})),H(e)};L.prototype.constructor=Behavior;var Q=Component,G=function(e){return i.page.forEach((function(t){$(t,e.methods,B[t])})),Q(e)},W=function(){var e,n;e=wx,t=e;try{n=require("./mtj-wx-sdk.config")}catch(e){return void console.error("请把mtj-wx-sdk.config.js文件拷贝到utils目录中")}n&&n.appKey?(p.key=n.appKey,l.getLocation=n.getLocation||!1,l.getComponentScroll=n.getComponentScroll||!1,l.disableCircling=n.disableCircling||!1,l.trackStatus=!(!1===E(s)),function(){var e=E(f);if(e){Object.keys(e).forEach((function(t){l[t]=e[t]}));var t=e.updateTimestamp||0;if(+new Date-t<864e5)return Promise.resolve()}P({url:"https://hmma.baidu.com/mini.conf",method:"POST",header:{"content-type":"application/x-www-form-urlencoded"},data:{type:"wx",key:p.key}}).then((function(e){if(e&&e.data){var t=e.data;Object.keys(t).forEach((function(e){l[e]=t[e]})),t.updateTimestamp=+new Date,x(f,t)}else _("remoteConfig",e)})).catch((function(e){_("sendRequest",e)}))}(),n.hasPlugin||(App=z,Page=F),module.exports={App:z,Page:F,Behavior:L,Component:G}):console.error("请设置mtj-wx-sdk.config.js文件中的appKey字段")};return W(),e.init=W,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
......@@ -43,11 +43,21 @@ const requestApi = obj => {
// wx.showToast({ title: JSON.stringify(res.data), icon: 'none' }) // 自己后台封装返回
// }
obj.callback(res)
} else if (res.statusCode === 403 || res.statusCode === 401) {
} else if (res.statusCode === 403) {
/* 未授权登录,跳转首页 */
wx.reLaunch({
url: '/pages/login/index'
})
} else if (res.statusCode === 401) {
wx.showModal({ title: '未授权', content: '是否要成为学员', showCancel: true }).then(res => {
res.confirm &&
wx.redirectTo({
url: `/pages/web/index?url=${encodeURIComponent(
'https://webapp-pub.ezijing.com/pages/marywood/marywood.html?channel_num=96169'
)}`
})
res.cancel && wx.reLaunch({ url: '/pages/login/index' })
})
} else {
wx.showToast({ title: res.errMsg, icon: 'none' }) // 微信封装返回
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论