四端上传
This commit is contained in:
1 parent
25bbb5f9c8
commit
c6e2cb4d5b
276 files changed
+17812
-3
No files matched your search
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Eslint config file
|
||||
* Documentation: https://eslint.org/docs/user-guide/configuring/
|
||||
* Install the Eslint extension before using this feature.
|
||||
*/
|
||||
module.exports = {
|
||||
env: {
|
||||
es6: true,
|
||||
browser: true,
|
||||
node: true,
|
||||
},
|
||||
ecmaFeatures: {
|
||||
modules: true,
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
sourceType: 'module',
|
||||
},
|
||||
globals: {
|
||||
wx: true,
|
||||
App: true,
|
||||
Page: true,
|
||||
getCurrentPages: true,
|
||||
getApp: true,
|
||||
Component: true,
|
||||
requirePlugin: true,
|
||||
requireMiniProgram: true,
|
||||
},
|
||||
// extends: 'eslint:recommended',
|
||||
rules: {},
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
//CssTokenizer.js
|
||||
function CssTokenizer(style = '', tagStyle = {}) {
|
||||
this.res = tagStyle;
|
||||
this._state = "SPACE";
|
||||
this._buffer = style;
|
||||
this._sectionStart = 0;
|
||||
this._index = 0;
|
||||
this._name = '';
|
||||
this._content = '';
|
||||
this._list = [];
|
||||
this._comma = false;
|
||||
}
|
||||
CssTokenizer.prototype.SPACE = function(c) {
|
||||
if (/[a-zA-Z.#]/.test(c)) {
|
||||
this._sectionStart = this._index;
|
||||
this._state = "InName";
|
||||
} else if (c == '@') this._state = "Ignore1";
|
||||
else if (c == '/') this._state = "BeforeComment";
|
||||
};
|
||||
CssTokenizer.prototype.BeforeComment = function(c) {
|
||||
if (c == '*') this._state = "InComment";
|
||||
else {
|
||||
this._index--;
|
||||
this._state = "SPACE";
|
||||
}
|
||||
};
|
||||
CssTokenizer.prototype.InComment = function(c) {
|
||||
if (c == '*') this._state = "AfterComment";
|
||||
};
|
||||
CssTokenizer.prototype.AfterComment = function(c) {
|
||||
if (c == '/') this._state = "SPACE";
|
||||
else {
|
||||
this._index--;
|
||||
this._state = "InComment"
|
||||
}
|
||||
};
|
||||
CssTokenizer.prototype.InName = function(c) {
|
||||
if (c == '{') {
|
||||
this._list.push(this._buffer.substring(this._sectionStart, this._index))
|
||||
this._sectionStart = this._index + 1;
|
||||
this._state = "InContent";
|
||||
} else if (c == ',') {
|
||||
this._list.push(this._buffer.substring(this._sectionStart, this._index));
|
||||
this._sectionStart = this._index + 1;
|
||||
this._comma = true;
|
||||
} else if ((c == '.' || c == '#') && !this._comma) {
|
||||
this._buffer = this._buffer.splice(this._index, 1, ' ');
|
||||
} else if (/\s/.test(c)) {
|
||||
this._name = this._buffer.substring(this._sectionStart, this._index);
|
||||
this._state = "NameSpace";
|
||||
} else if (/[>:\[]/.test(c)) {
|
||||
if (this._list.length) this._state = "IgnoreName";
|
||||
else this._state = "Ignore1";
|
||||
} else this._comma = false;
|
||||
};
|
||||
CssTokenizer.prototype.NameSpace = function(c) {
|
||||
if (c == '{') {
|
||||
this._list.push(this._name);
|
||||
this._sectionStart = this._index + 1;
|
||||
this._state = "InContent";
|
||||
} else if (c == ',') {
|
||||
this._comma = true;
|
||||
this._list.push(this._name);
|
||||
this._sectionStart = this._index + 1;
|
||||
this._state = "InName"
|
||||
} else if (/\S/.test(c)) {
|
||||
if (this._comma) {
|
||||
this._sectionStart = this._index;
|
||||
this._index--;
|
||||
this._state = "InName";
|
||||
} else if (this._list.length) this._state = "IgnoreName";
|
||||
else this._state = "Ignore1"
|
||||
}
|
||||
};
|
||||
CssTokenizer.prototype.InContent = function(c) {
|
||||
if (c == '}') {
|
||||
this._content = this._buffer.substring(this._sectionStart, this._index);
|
||||
for (let item of this._list)
|
||||
this.res[item] = (this.res[item] || '') + this._content;
|
||||
this._list = [];
|
||||
this._comma = false;
|
||||
this._state = "SPACE";
|
||||
}
|
||||
};
|
||||
CssTokenizer.prototype.IgnoreName = function(c) {
|
||||
if (c == ',') {
|
||||
this._sectionStart = this._index + 1;
|
||||
this._state = "InName";
|
||||
} else if (c == '{') {
|
||||
this._sectionStart = this._index + 1;
|
||||
this._state = "InContent";
|
||||
}
|
||||
}
|
||||
CssTokenizer.prototype.Ignore1 = function(c) {
|
||||
if (c == ';') {
|
||||
this._state = "SPACE";
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (c == '{') this._state = "Ignore2";
|
||||
};
|
||||
CssTokenizer.prototype.Ignore2 = function(c) {
|
||||
if (c == '}') {
|
||||
this._state = "SPACE";
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (c == '{') this._state = "Ignore3";
|
||||
};
|
||||
CssTokenizer.prototype.Ignore3 = function(c) {
|
||||
if (c == '}') this._state = "Ignore2";
|
||||
};
|
||||
CssTokenizer.prototype.parse = function() {
|
||||
for (; this._index < this._buffer.length; this._index++)
|
||||
this[this._state](this._buffer[this._index]);
|
||||
return this.res;
|
||||
};
|
||||
module.exports = CssTokenizer;
|
||||
@@ -0,0 +1,325 @@
|
||||
//DomHandler.js
|
||||
const CssTokenizer = require('./CssTokenizer.js');
|
||||
const CanIUse = require('./api.js').versionHigherThan('2.7.1');
|
||||
const Common = 1,
|
||||
Rich = 2;
|
||||
const trustTag = {
|
||||
a: Rich,
|
||||
abbr: Common,
|
||||
audio: Rich,
|
||||
b: Common,
|
||||
blockquote: Common,
|
||||
br: Rich,
|
||||
code: Common,
|
||||
col: Rich,
|
||||
colgroup: Rich,
|
||||
dd: Common,
|
||||
del: Common,
|
||||
dl: Common,
|
||||
dt: Common,
|
||||
div: Common,
|
||||
em: Common,
|
||||
fieldset: Rich,
|
||||
font: Common,
|
||||
h1: Rich,
|
||||
h2: Rich,
|
||||
h3: Rich,
|
||||
h4: Rich,
|
||||
h5: Rich,
|
||||
h6: Rich,
|
||||
hr: Rich,
|
||||
i: Common,
|
||||
img: Common,
|
||||
ins: Common,
|
||||
label: Common,
|
||||
legend: Rich,
|
||||
li: Rich,
|
||||
ol: Rich,
|
||||
p: Common,
|
||||
q: Common,
|
||||
source: Rich,
|
||||
span: Common,
|
||||
strong: Common,
|
||||
sub: Rich,
|
||||
sup: Rich,
|
||||
table: Rich,
|
||||
tbody: Rich,
|
||||
td: Rich,
|
||||
tfoot: Rich,
|
||||
th: Rich,
|
||||
thead: Rich,
|
||||
tr: Rich,
|
||||
u: Common,
|
||||
ul: Rich,
|
||||
video: Common
|
||||
};
|
||||
const blockTag = {
|
||||
address: true,
|
||||
article: true,
|
||||
aside: true,
|
||||
body: true,
|
||||
center: true,
|
||||
cite: true,
|
||||
footer: true,
|
||||
header: true,
|
||||
html: true,
|
||||
nav: true,
|
||||
pre: true,
|
||||
section: true
|
||||
}
|
||||
const textTag = {
|
||||
a: true,
|
||||
abbr: true,
|
||||
b: true,
|
||||
big: true,
|
||||
code: true,
|
||||
del: true,
|
||||
em: true,
|
||||
font: true,
|
||||
i: true,
|
||||
ins: true,
|
||||
label: true,
|
||||
mark: true,
|
||||
q: true,
|
||||
s: true,
|
||||
small: true,
|
||||
span: true,
|
||||
strong: true,
|
||||
u: true
|
||||
};
|
||||
const ignoreTag = {
|
||||
area: true,
|
||||
base: true,
|
||||
basefont: true,
|
||||
canvas: true,
|
||||
circle: true,
|
||||
command: true,
|
||||
ellipse: true,
|
||||
embed: true,
|
||||
frame: true,
|
||||
head: true,
|
||||
iframe: true,
|
||||
input: true,
|
||||
isindex: true,
|
||||
keygen: true,
|
||||
line: true,
|
||||
link: true,
|
||||
map: true,
|
||||
meta: true,
|
||||
param: true,
|
||||
path: true,
|
||||
polygon: true,
|
||||
polyline: true,
|
||||
rect: true,
|
||||
script: true,
|
||||
stop: true,
|
||||
textarea: true,
|
||||
title: true,
|
||||
track: true,
|
||||
use: true,
|
||||
wbr: true
|
||||
};
|
||||
if (CanIUse) {
|
||||
trustTag.bdi = Rich;
|
||||
trustTag.bdo = Rich;
|
||||
trustTag.caption = Rich;
|
||||
trustTag.rt = Rich;
|
||||
trustTag.ruby = Rich;
|
||||
ignoreTag.rp = true;
|
||||
trustTag.big = Common;
|
||||
trustTag.small = Common;
|
||||
trustTag.pre = Rich;
|
||||
delete blockTag.pre;
|
||||
}
|
||||
//添加默认值
|
||||
function initStyle(tagStyle) {
|
||||
tagStyle.a = "display:inline;color:#366092;word-break:break-all;" + (tagStyle.a || "");
|
||||
tagStyle.address = "font-style:italic;" + (tagStyle.address || "");
|
||||
tagStyle.blockquote = tagStyle.blockquote || 'background-color:#f6f6f6;border-left:3px solid #dbdbdb;color:#6c6c6c;padding:5px 0 5px 10px';
|
||||
tagStyle.center = 'text-align:center;' + (tagStyle.center || "");
|
||||
tagStyle.cite = "font-style:italic;" + (tagStyle.cite || "");
|
||||
tagStyle.code = tagStyle.code || 'padding:0 1px 0 1px;margin-left:2px;margin-right:2px;background-color:#f8f8f8;border:1px solid #cccccc;border-radius:3px';
|
||||
tagStyle.dd = "margin-left:40px;" + (tagStyle.dd || "");
|
||||
tagStyle.img = "max-width:100%;" + (tagStyle.img || "");
|
||||
tagStyle.mark = "display:inline;background-color:yellow;" + (tagStyle.mark || "");
|
||||
tagStyle.pre = "overflow:scroll;" + (tagStyle.pre || 'background-color:#f6f8fa;padding:5px;border-radius:5px;');
|
||||
tagStyle.s = "display:inline;text-decoration:line-through;" + (tagStyle.s || "");
|
||||
tagStyle.u = "display:inline;text-decoration:underline;" + (tagStyle.u || "");
|
||||
//低版本兼容
|
||||
if (!CanIUse) {
|
||||
blockTag.caption = true;
|
||||
tagStyle.big = "display:inline;font-size:1.2em;" + (tagStyle.big || "");
|
||||
tagStyle.small = "display:inline;font-size:0.8em;" + (tagStyle.small || "");
|
||||
tagStyle.pre = "font-family:monospace;white-space:pre;" + tagStyle.pre;
|
||||
}
|
||||
return tagStyle;
|
||||
}
|
||||
|
||||
function DomHandler(style, tagStyle = {}) {
|
||||
this.imgList = [];
|
||||
this.nodes = [];
|
||||
this.title = "";
|
||||
this._videoNum = 0;
|
||||
this._audioNum = 0;
|
||||
this._style = new CssTokenizer(style, initStyle(tagStyle)).parse();
|
||||
this._tagStack = [];
|
||||
}
|
||||
DomHandler.prototype._addDomElement = function(element) {
|
||||
let parent = this._tagStack[this._tagStack.length - 1];
|
||||
let siblings = parent ? parent.children : this.nodes;
|
||||
siblings.push(element);
|
||||
};
|
||||
DomHandler.prototype._bubbling = function() {
|
||||
for (let i = this._tagStack.length - 1; i >= 0; i--) {
|
||||
if (trustTag[this._tagStack[i].name] == Common) this._tagStack[i].continue = true;
|
||||
else return this._tagStack[i].name;
|
||||
}
|
||||
}
|
||||
DomHandler.prototype.onopentag = function(name, attrs) {
|
||||
let element = {
|
||||
children: []
|
||||
};
|
||||
//匹配样式
|
||||
let matched = this._style[name] ? (this._style[name] + ';') : '';
|
||||
if (attrs.id) {
|
||||
matched += (this._style['#' + attrs.id] ? (this._style['#' + attrs.id] + ';') : '');
|
||||
delete attrs.id;
|
||||
}
|
||||
if (attrs.class) {
|
||||
for (var Class of attrs.class.split(' ')) {
|
||||
matched += (this._style['.' + Class] ? (this._style['.' + Class] + ';') : '');
|
||||
}
|
||||
delete attrs.class;
|
||||
}
|
||||
//处理属性
|
||||
switch (name) {
|
||||
case 'div':
|
||||
case 'p':
|
||||
if (attrs.align) {
|
||||
attrs.style += (';text-align:' + attrs.align);
|
||||
delete attrs.align;
|
||||
}
|
||||
break;
|
||||
case 'img':
|
||||
if (attrs.width) {
|
||||
attrs.style = 'width:' + attrs.width + (/[0-9]/.test(attrs.width[attrs.width.length - 1]) ? 'px' : '') + ';' + attrs.style;
|
||||
delete attrs.width;
|
||||
}
|
||||
if (attrs['data-src']) {
|
||||
attrs.src = attrs.src || attrs['data-src'];
|
||||
delete attrs['data-src'];
|
||||
}
|
||||
if (!attrs.hasOwnProperty('ignore') && attrs.src) {
|
||||
this.imgList.push(attrs.src);
|
||||
if (this._bubbling() == 'a') attrs.ignore = "";
|
||||
};
|
||||
break;
|
||||
case 'font':
|
||||
name = 'span';
|
||||
if (attrs.color) {
|
||||
attrs.style += (';color:' + attrs.color);
|
||||
delete attrs.color;
|
||||
}
|
||||
if (attrs.face) {
|
||||
attrs.style += (";font-family:" + attrs.face);
|
||||
delete attrs.face;
|
||||
}
|
||||
if (attrs.size) {
|
||||
var size = parseInt(attrs.size);
|
||||
if (size < 1) size = 1;
|
||||
else if (size > 7) size = 7;
|
||||
switch (size) {
|
||||
case 1:
|
||||
size = 10;
|
||||
break;
|
||||
case 2:
|
||||
size = 13;
|
||||
break;
|
||||
case 3:
|
||||
size = 16;
|
||||
break;
|
||||
case 4:
|
||||
size = 18;
|
||||
break;
|
||||
case 5:
|
||||
size = 24;
|
||||
break;
|
||||
case 6:
|
||||
size = 32;
|
||||
break;
|
||||
case 7:
|
||||
size = 48;
|
||||
break;
|
||||
}
|
||||
attrs.style += (";font-size:" + size + "px");
|
||||
delete attrs.size;
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
this._bubbling();
|
||||
break;
|
||||
case 'video':
|
||||
case 'audio':
|
||||
attrs.loop = attrs.hasOwnProperty('loop');
|
||||
attrs.controls = attrs.hasOwnProperty('controls');
|
||||
attrs.autoplay = attrs.hasOwnProperty('autoplay');
|
||||
if (name == 'video') {
|
||||
attrs.muted = attrs.hasOwnProperty('muted');
|
||||
if (attrs.width) {
|
||||
attrs.style = 'width:' + parseFloat(attrs.width) + 'px;' + attrs.style;
|
||||
delete attrs.width;
|
||||
}
|
||||
if (attrs.height) {
|
||||
attrs.style = 'height:' + parseFloat(attrs.height) + 'px;' + attrs.style;
|
||||
delete attrs.height;
|
||||
}
|
||||
}
|
||||
attrs.id = (name + (++this['_' + name + 'Num']));
|
||||
attrs.source = [];
|
||||
if (attrs.src) attrs.source.push(attrs.src);
|
||||
if (!attrs.controls && !attrs.autoplay)
|
||||
console.warn('存在没有controls属性的' + name + '标签,可能导致无法播放', attrs);
|
||||
this._bubbling();
|
||||
break;
|
||||
case 'source':
|
||||
let parent = this._tagStack[this._tagStack.length - 1];
|
||||
if (parent && (parent.name == 'video' || parent.name == 'audio')) {
|
||||
parent.attrs.source.push(attrs.src);
|
||||
if (!parent.attrs.src) parent.attrs.src = attrs.src;
|
||||
}
|
||||
this._tagStack.push(element);
|
||||
return;
|
||||
}
|
||||
attrs.style = matched + attrs.style;
|
||||
if (textTag[name]) element.continue = true;
|
||||
else if (blockTag[name]) name = 'div';
|
||||
else if (!trustTag[name]) name = 'span';
|
||||
element.name = name;
|
||||
element.attrs = attrs;
|
||||
this._addDomElement(element);
|
||||
this._tagStack.push(element);
|
||||
};
|
||||
DomHandler.prototype.ontext = function(data) {
|
||||
if (/\S/.test(data)) {
|
||||
let element = {
|
||||
text: data.replace(/ /g, '\u00A0'),
|
||||
type: 'text'
|
||||
};
|
||||
if (/&#*((?!sp|lt|gt).){2,5};/.test(data)) element.decode = true;
|
||||
this._addDomElement(element);
|
||||
}
|
||||
};
|
||||
DomHandler.prototype.onclosetag = function(name) {
|
||||
let element = this._tagStack.pop();
|
||||
if (ignoreTag[name]) {
|
||||
if (name == 'title') {
|
||||
try {
|
||||
this.title = element.children[0].text;
|
||||
} catch (e) {}
|
||||
}
|
||||
let parent = this._tagStack[this._tagStack.length - 1];
|
||||
let siblings = parent ? parent.children : this.nodes;
|
||||
siblings.pop();
|
||||
}
|
||||
};
|
||||
module.exports = DomHandler;
|
||||
@@ -0,0 +1,156 @@
|
||||
//Parser.js
|
||||
const Tokenizer = require("./Tokenizer.js");
|
||||
const DomHandler = require("./DomHandler.js");
|
||||
const trustAttrs = {
|
||||
align: true,
|
||||
alt: true,
|
||||
author: true,
|
||||
autoplay: true,
|
||||
class: true,
|
||||
color: true,
|
||||
colspan: true,
|
||||
controls: true,
|
||||
"data-src": true,
|
||||
dir: true,
|
||||
face: true,
|
||||
height: true,
|
||||
href: true,
|
||||
id: true,
|
||||
ignore: true,
|
||||
loop: true,
|
||||
muted: true,
|
||||
name: true,
|
||||
poster: true,
|
||||
rowspan: true,
|
||||
size: true,
|
||||
span: true,
|
||||
src: true,
|
||||
start: true,
|
||||
style: true,
|
||||
type: true,
|
||||
width: true,
|
||||
};
|
||||
const voidTag = {
|
||||
area: true,
|
||||
base: true,
|
||||
basefont: true,
|
||||
br: true,
|
||||
col: true,
|
||||
circle: true,
|
||||
command: true,
|
||||
ellipse: true,
|
||||
embed: true,
|
||||
frame: true,
|
||||
hr: true,
|
||||
img: true,
|
||||
input: true,
|
||||
isindex: true,
|
||||
keygen: true,
|
||||
line: true,
|
||||
link: true,
|
||||
meta: true,
|
||||
param: true,
|
||||
path: true,
|
||||
polygon: true,
|
||||
polyline: true,
|
||||
rect: true,
|
||||
source: true,
|
||||
stop: true,
|
||||
track: true,
|
||||
use: true,
|
||||
wbr: true
|
||||
};
|
||||
|
||||
function Parser(cbs, callback) {
|
||||
this._cbs = cbs;
|
||||
this._callback = callback;
|
||||
this._tagname = "";
|
||||
this._attribname = "";
|
||||
this._attribvalue = "";
|
||||
this._attribs = null;
|
||||
this._stack = [];
|
||||
this._tokenizer = new Tokenizer(this);
|
||||
}
|
||||
Parser.prototype.ontext = function(data) {
|
||||
this._cbs.ontext(data);
|
||||
};
|
||||
Parser.prototype.onopentagname = function(name) {
|
||||
name = name.toLowerCase();
|
||||
this._tagname = name;
|
||||
this._attribs = {
|
||||
style: ''
|
||||
};
|
||||
if (!voidTag[name]) this._stack.push(name);
|
||||
};
|
||||
Parser.prototype.onopentagend = function() {
|
||||
if (this._attribs) {
|
||||
this._cbs.onopentag(this._tagname, this._attribs);
|
||||
this._attribs = null;
|
||||
}
|
||||
if (voidTag[this._tagname]) this._cbs.onclosetag(this._tagname);
|
||||
this._tagname = "";
|
||||
};
|
||||
Parser.prototype.onclosetag = function(name) {
|
||||
name = name.toLowerCase();
|
||||
if (this._stack.length && !voidTag[name]) {
|
||||
var pos = this._stack.lastIndexOf(name);
|
||||
if (pos !== -1) {
|
||||
pos = this._stack.length - pos;
|
||||
while (pos--) this._cbs.onclosetag(this._stack.pop());
|
||||
} else if (name === "p") {
|
||||
this.onopentagname(name);
|
||||
this._closeCurrentTag();
|
||||
}
|
||||
} else if (name === "br" || name === "hr" || name === "p") {
|
||||
this.onopentagname(name);
|
||||
this._closeCurrentTag();
|
||||
}
|
||||
};
|
||||
Parser.prototype._closeCurrentTag = function() {
|
||||
let name = this._tagname;
|
||||
this.onopentagend();
|
||||
if (this._stack[this._stack.length - 1] === name) {
|
||||
this._cbs.onclosetag(name);
|
||||
this._stack.pop();
|
||||
}
|
||||
};
|
||||
Parser.prototype.onattribend = function() {
|
||||
this._attribvalue = this._attribvalue.replace(/"/g, '"');
|
||||
if (this._attribs && trustAttrs[this._attribname]) {
|
||||
this._attribs[this._attribname] = this._attribvalue;
|
||||
}
|
||||
this._attribname = "";
|
||||
this._attribvalue = "";
|
||||
};
|
||||
Parser.prototype.onend = function() {
|
||||
for (
|
||||
var i = this._stack.length; i > 0; this._cbs.onclosetag(this._stack[--i])
|
||||
);
|
||||
this._callback({
|
||||
'nodes': this._cbs.nodes,
|
||||
'title': this._cbs.title,
|
||||
'imgList': this._cbs.imgList
|
||||
});
|
||||
};
|
||||
Parser.prototype.write = function(chunk) {
|
||||
this._tokenizer.parse(chunk);
|
||||
};
|
||||
|
||||
function html2nodes(data, tagStyle) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
let style = '';
|
||||
data = data.replace(/<style.*?>([\s\S]*?)<\/style>/gi, function() {
|
||||
style += arguments[1];
|
||||
return '';
|
||||
});
|
||||
let handler = new DomHandler(style, tagStyle);
|
||||
new Parser(handler, (res) => {
|
||||
return resolve(res);
|
||||
}).write(data);
|
||||
} catch (err) {
|
||||
return reject(err);
|
||||
}
|
||||
})
|
||||
}
|
||||
module.exports = html2nodes;
|
||||
@@ -0,0 +1,218 @@
|
||||
//Tokenizer.js
|
||||
function Tokenizer(cbs) {
|
||||
this._state = "TEXT";
|
||||
this._buffer = "";
|
||||
this._sectionStart = 0;
|
||||
this._index = 0;
|
||||
this._cbs = cbs;
|
||||
}
|
||||
Tokenizer.prototype.TEXT = function(c) {
|
||||
var index = this._buffer.indexOf("<", this._index);
|
||||
if (index != -1) {
|
||||
this._index = index;
|
||||
this._cbs.ontext(this._getSection());
|
||||
this._state = "BeforeTag";
|
||||
this._sectionStart = this._index;
|
||||
} else this._index = this._buffer.length;
|
||||
};
|
||||
Tokenizer.prototype.BeforeTag = function(c) {
|
||||
switch (c) {
|
||||
case "/":
|
||||
this._state = "BeforeCloseTag";
|
||||
break;
|
||||
case "!":
|
||||
this._state = "BeforeDeclaration";
|
||||
break;
|
||||
case "?":
|
||||
let index = this._buffer.indexOf(">", this._index);
|
||||
if (index != -1) {
|
||||
this._index = index;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else this._sectionStart = this._index = this._buffer.length;
|
||||
this._state = "TEXT";
|
||||
break;
|
||||
case ">":
|
||||
this._state = "TEXT";
|
||||
break;
|
||||
case "<":
|
||||
this._cbs.ontext(this._getSection());
|
||||
this._sectionStart = this._index;
|
||||
break;
|
||||
default:
|
||||
if (/\s/.test(c)) this._state = "TEXT";
|
||||
else {
|
||||
this._state = "InTag";
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InTag = function(c) {
|
||||
if (c === "/" || c === ">" || /\s/.test(c)) {
|
||||
this._cbs.onopentagname(this._getSection());
|
||||
this._state = "BeforeAttrsName";
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.BeforeAttrsName = function(c) {
|
||||
if (c === ">") {
|
||||
this._cbs.onopentagend();
|
||||
this._state = "TEXT";
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (c === "/") {
|
||||
this._state = "InSelfCloseTag";
|
||||
} else if (!(/\s/.test(c))) {
|
||||
this._state = "InAttrsName";
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InAttrsName = function(c) {
|
||||
if (c === "=" || c === "/" || c === ">" || /\s/.test(c)) {
|
||||
this._cbs._attribname = this._getSection().toLowerCase();
|
||||
this._sectionStart = -1;
|
||||
this._state = "AfterAttrsName";
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.AfterAttrsName = function(c) {
|
||||
if (c === "=") {
|
||||
this._state = "BeforeAttrsValue";
|
||||
} else if (c === "/" || c === ">") {
|
||||
this._cbs.onattribend();
|
||||
this._state = "BeforeAttrsName";
|
||||
this._index--;
|
||||
} else if (!(/\s/.test(c))) {
|
||||
this._cbs.onattribend();
|
||||
this._state = "InAttrsName";
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.BeforeAttrsValue = function(c) {
|
||||
if (c === '"') {
|
||||
this._state = "InAttrsValueDQ";
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (c === "'") {
|
||||
this._state = "InAttrsValueSQ";
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (!(/\s/.test(c))) {
|
||||
this._state = "InAttrsValueNQ";
|
||||
this._sectionStart = this._index;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InAttrsValueDQ = function(c) {
|
||||
if (c === '"') {
|
||||
this._cbs._attribvalue += this._getSection();
|
||||
this._cbs.onattribend();
|
||||
this._state = "BeforeAttrsName";
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InAttrsValueSQ = function(c) {
|
||||
if (c === "'") {
|
||||
this._cbs._attribvalue += this._getSection();
|
||||
this._cbs.onattribend();
|
||||
this._state = "BeforeAttrsName";
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InAttrsValueNQ = function(c) {
|
||||
if (/\s/.test(c) || c === ">") {
|
||||
this._cbs._attribvalue += this._getSection();
|
||||
this._cbs.onattribend();
|
||||
this._state = "BeforeAttrsName";
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.BeforeCloseTag = function(c) {
|
||||
if (/\s/.test(c));
|
||||
else if (c === ">") {
|
||||
this._state = "TEXT";
|
||||
} else {
|
||||
this._state = "InCloseTag";
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InCloseTag = function(c) {
|
||||
if (c === ">" || /\s/.test(c)) {
|
||||
this._cbs.onclosetag(this._getSection());
|
||||
this._state = "AfterCloseTag";
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.InSelfCloseTag = function(c) {
|
||||
if (c === ">") {
|
||||
this._cbs.onopentagend();
|
||||
this._state = "TEXT";
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (!(/\s/.test(c))) {
|
||||
this._state = "BeforeAttrsName";
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.AfterCloseTag = function(c) {
|
||||
if (c === ">") {
|
||||
this._state = "TEXT";
|
||||
this._sectionStart = this._index + 1;
|
||||
}
|
||||
};
|
||||
Tokenizer.prototype.BeforeDeclaration = function(c) {
|
||||
if (c == '-') this._state = "InComment";
|
||||
else if (c == '[') this._state = "BeforeCDATA1";
|
||||
else this._state = "InDeclaration";
|
||||
};
|
||||
Tokenizer.prototype.InDeclaration = function(c) {
|
||||
var index = this._buffer.indexOf(">", this._index);
|
||||
if (index != -1) {
|
||||
this._index = index;
|
||||
this._sectionStart = index + 1;
|
||||
} else this._sectionStart = this._index = this._buffer.length;
|
||||
this._state = "TEXT";
|
||||
};
|
||||
Tokenizer.prototype.InComment = function(c) {
|
||||
let key = (c == '-' ? '-->' : '>');
|
||||
let index = this._buffer.indexOf(key, this._index);
|
||||
if (index != -1) {
|
||||
this._index = index + key.length - 1;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else this._sectionStart = this._index = this._buffer.length;
|
||||
this._state = "TEXT";
|
||||
};
|
||||
Tokenizer.prototype.BeforeCDATA1 = function(c) {
|
||||
if (c == 'C') this._state = "BeforeCDATA2";
|
||||
else this._state = "InDeclaration";
|
||||
};
|
||||
Tokenizer.prototype.BeforeCDATA2 = function(c) {
|
||||
if (c == 'D') this._state = "BeforeCDATA3";
|
||||
else this._state = "InDeclaration";
|
||||
};
|
||||
Tokenizer.prototype.BeforeCDATA3 = function(c) {
|
||||
if (c == 'A') this._state = "BeforeCDATA4";
|
||||
else this._state = "InDeclaration";
|
||||
};
|
||||
Tokenizer.prototype.BeforeCDATA4 = function(c) {
|
||||
if (c == 'T') this._state = "BeforeCDATA5";
|
||||
else this._state = "InDeclaration";
|
||||
};
|
||||
Tokenizer.prototype.BeforeCDATA5 = function(c) {
|
||||
if (c == 'A') this._state = "InCDATA";
|
||||
else this._state = "InDeclaration";
|
||||
};
|
||||
Tokenizer.prototype.InCDATA = function(c) {
|
||||
let key = (c == '[' ? ']]>' : '>');
|
||||
let index = this._buffer.indexOf(key, this._index);
|
||||
if (index != -1) {
|
||||
this._index = index + key.length - 1;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else this._sectionStart = this._index = this._buffer.length;
|
||||
this._state = "TEXT";
|
||||
};
|
||||
Tokenizer.prototype.parse = function(chunk) {
|
||||
this._buffer += chunk;
|
||||
for (; this._index < this._buffer.length; this._index++)
|
||||
this[this._state](this._buffer[this._index]);
|
||||
if (this._state === "TEXT" && this._sectionStart !== this._index)
|
||||
this._cbs.ontext(this._buffer.substr(this._sectionStart));
|
||||
this._cbs.onend();
|
||||
};
|
||||
Tokenizer.prototype._getSection = function() {
|
||||
return this._buffer.substring(this._sectionStart, this._index);
|
||||
};
|
||||
module.exports = Tokenizer;
|
||||
@@ -0,0 +1,37 @@
|
||||
String.prototype.splice = function(start = 0, deleteCount = 0, addStr = '') {
|
||||
if (start < 0) start = this.length + start;
|
||||
if (deleteCount < 0) deleteCount = 0;
|
||||
return this.substring(0, start) + addStr + this.substring(start + deleteCount);
|
||||
}
|
||||
module.exports = {
|
||||
versionHigherThan(version = '') {
|
||||
//旧版 var v1 = wx.getSystemInfoSync().SDKVersion.split('.');
|
||||
var v1 = wx.getAppBaseInfo().SDKVersion.split('.');
|
||||
var v2 = version.split('.');
|
||||
const len = Math.max(v1.length, v2.length);
|
||||
while (v1.length < len) {
|
||||
v1.push('0');
|
||||
}
|
||||
while (v2.length < len) {
|
||||
v2.push('0');
|
||||
}
|
||||
for (let i = 0; i < len; i++) {
|
||||
const num1 = parseInt(v1[i]);
|
||||
const num2 = parseInt(v2[i]);
|
||||
if (num1 > num2) {
|
||||
return true;
|
||||
} else if (num1 < num2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
html2nodes(html, tagStyle) {
|
||||
const Parser = require('./Parser.js');
|
||||
return Parser(html, tagStyle);
|
||||
},
|
||||
css2object(style, tagStyle) {
|
||||
const CssTokenizer = require('./CssTokenizer.js');
|
||||
return new CssTokenizer(style, tagStyle).parse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
//Parser组件
|
||||
const html2nodes = require('./Parser.js');
|
||||
const initData = function(Component) {
|
||||
setTimeout(() => {
|
||||
Component.createSelectorQuery().select('#contain').boundingClientRect(res => {
|
||||
Component.triggerEvent('ready', res);
|
||||
}).exec();
|
||||
Component.videoContext = [];
|
||||
let nodes = [Component.selectComponent('#contain')];
|
||||
nodes = nodes.concat(Component.selectAllComponents('#contain>>>#node'));
|
||||
for (let node of nodes) {
|
||||
for (let item of node.data.nodes) {
|
||||
if (item.name == 'video') {
|
||||
Component.videoContext.push({
|
||||
id: item.attrs.id,
|
||||
context: wx.createVideoContext(item.attrs.id, node)
|
||||
});
|
||||
} else if (item.name == 'audio' && item.attrs.autoplay)
|
||||
wx.createAudioContext(item.attrs.id, node).play();
|
||||
}
|
||||
}
|
||||
}, 10)
|
||||
}
|
||||
Component({
|
||||
properties: {
|
||||
'html': {
|
||||
type: String,
|
||||
value: '',
|
||||
observer: function(html) {
|
||||
let hideAnimation = {},
|
||||
showAnimation = {};
|
||||
if (this.data.showWithAnimation) {
|
||||
hideAnimation = wx.createAnimation({
|
||||
duration: this.data.animationDuration,
|
||||
timingFunction: "ease"
|
||||
}).opacity(0).step().export();
|
||||
showAnimation = wx.createAnimation({
|
||||
duration: this.data.animationDuration,
|
||||
timingFunction: "ease"
|
||||
}).opacity(1).step().export();
|
||||
}
|
||||
if (!html) {
|
||||
this.setData({
|
||||
nodes: []
|
||||
})
|
||||
} else if (typeof html == 'string') {
|
||||
html2nodes(html, this.data.tagStyle).then(res => {
|
||||
this.setData({
|
||||
nodes: res.nodes,
|
||||
controls: {
|
||||
imgMode: this.data.imgMode
|
||||
},
|
||||
showAnimation,
|
||||
hideAnimation
|
||||
}, initData(this))
|
||||
if (res.title && this.data.autosetTitle) {
|
||||
wx.setNavigationBarTitle({
|
||||
title: res.title
|
||||
})
|
||||
}
|
||||
this.imgList = res.imgList;
|
||||
this.triggerEvent('parse', res);
|
||||
}).catch(err => {
|
||||
this.triggerEvent('error', err);
|
||||
})
|
||||
} else if (html.constructor == Array) {
|
||||
this.setData({
|
||||
controls: {
|
||||
imgMode: this.data.imgMode
|
||||
},
|
||||
showAnimation,
|
||||
hideAnimation
|
||||
}, initData(this))
|
||||
this.imgList = [];
|
||||
} else if (typeof html == 'object') {
|
||||
if (!html.nodes || html.nodes.constructor != Array) {
|
||||
this.triggerEvent('error', {
|
||||
message: "传入的nodes数组格式不正确!应该传入的类型是array,实际传入的类型是:" + typeof html.nodes
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
controls: {
|
||||
imgMode: this.data.imgMode
|
||||
},
|
||||
showAnimation,
|
||||
hideAnimation
|
||||
}, initData(this))
|
||||
if (html.title && this.data.autosetTitle) {
|
||||
wx.setNavigationBarTitle({
|
||||
title: html.title
|
||||
})
|
||||
}
|
||||
this.imgList = html.imgList || [];
|
||||
} else {
|
||||
this.triggerEvent('error', {
|
||||
message: "错误的html类型:" + typeof html
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
'autocopy': {
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
'autopause': {
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
'autosetTitle':{
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
'imgMode': {
|
||||
type: String,
|
||||
value: "default"
|
||||
},
|
||||
'selectable': {
|
||||
type: Boolean,
|
||||
value: true
|
||||
},
|
||||
'tagStyle': {
|
||||
type: Object,
|
||||
value: { video:"width:100%" }
|
||||
},
|
||||
'showWithAnimation': {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
'animationDuration': {
|
||||
type: Number,
|
||||
value: 400
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
//事件
|
||||
tapEvent(e) {
|
||||
if (this.data.autocopy && e.detail && /^http/.test(e.detail)) {
|
||||
wx.setClipboardData({
|
||||
data: e.detail,
|
||||
success() {
|
||||
wx.showToast({
|
||||
title: '链接已复制',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
this.triggerEvent('linkpress', e.detail);
|
||||
},
|
||||
errorEvent(e) {
|
||||
this.triggerEvent('error', e.detail);
|
||||
},
|
||||
//内部方法
|
||||
_previewImg(e) {
|
||||
wx.previewImage({
|
||||
current: e.detail,
|
||||
urls: this.imgList.length ? this.imgList : [e.detail],
|
||||
})
|
||||
},
|
||||
_playVideo(e) {
|
||||
if (this.videoContext.length > 1 && this.data.autopause) {
|
||||
for (let video of this.videoContext) {
|
||||
if (video.id == e.detail) continue;
|
||||
video.context.pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"trees": "./trees/trees"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<!--Parser-->
|
||||
<slot wx:if="{{!(html.nodes||((html[0].name||html[0].type)?1:nodes.length))}}" animation="{{hideAnimation}}"></slot>
|
||||
<trees id="contain" style="{{(showWithAnimation?'opacity:0;':'')+(selectable?'user-select:text;-webkit-user-select:text':'')}}" animation="{{showAnimation}}" nodes="{{html.nodes||((html[0].name||html[0].type)?html:nodes)}}" controls="{{controls}}" catchpreview="_previewImg"
|
||||
catchplay="_playVideo" catchlinkpress="tapEvent" catcherror="errorEvent" />
|
||||
@@ -0,0 +1,5 @@
|
||||
:host {
|
||||
display: block;
|
||||
overflow: scroll;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Parser/trees/cssHandler.wxs
|
||||
module.exports = {
|
||||
getStyle: function(style, display) {
|
||||
var res = "";
|
||||
var reg = getRegExp("float\s*:\s*[^;]*", "i");
|
||||
if (reg.test(style)) res += reg.exec(style)[0];
|
||||
reg = getRegExp("margin[^;]*auto", "i");
|
||||
if (reg.test(style)) res += (";" + reg.exec(style)[0]);
|
||||
reg = getRegExp("display\s*:\s*([^;]*)", "i");
|
||||
if (reg.test(style) && reg.exec(style)[1]!="flex") res += (';' + reg.exec(style)[0]);
|
||||
else res += (';display:' + display);
|
||||
reg = getRegExp("[^;\s]*width\s*:\s*[^;]*", "ig");
|
||||
var width = reg.exec(style);
|
||||
while (width) {
|
||||
res += (';' + width[0]);
|
||||
width = reg.exec(style);
|
||||
}
|
||||
return res;
|
||||
},
|
||||
setImgStyle: function(item, imgMode) {
|
||||
if (getRegExp("[^-]width\s*:\s*[^;]*", "i").test(';' + item.attrs.style))
|
||||
item.attrs.style += ';width:100%';
|
||||
if (imgMode == "widthFix")
|
||||
item.attrs.style += ";height:auto !important";
|
||||
return [item];
|
||||
},
|
||||
setStyle: function(item) {
|
||||
if (getRegExp("[^-]width\s*:\s*[^;]*", "i").test(';' + item.attrs.style))
|
||||
item.attrs.style += ';width:100%';
|
||||
return [item];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Parser/trees/trees.js
|
||||
Component({
|
||||
properties: {
|
||||
nodes: {
|
||||
type: Array,
|
||||
value: []
|
||||
},
|
||||
controls: {
|
||||
type: Object,
|
||||
value: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
//冒泡事件
|
||||
playEvent(e) {
|
||||
this.triggerEvent('play', e.currentTarget.dataset.id, {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
});
|
||||
},
|
||||
previewEvent(e) {
|
||||
if (!e.target.dataset.hasOwnProperty('ignore')) {
|
||||
this.triggerEvent('preview', e.currentTarget.dataset.src, {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
});
|
||||
}
|
||||
},
|
||||
tapEvent(e) {
|
||||
this.triggerEvent('linkpress', e.currentTarget.dataset.href, {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
});
|
||||
},
|
||||
errorEvent(e) {
|
||||
//尝试加载其他源
|
||||
if (!this.data.controls[e.currentTarget.dataset.id] && e.currentTarget.dataset.source.length > 1) {
|
||||
this.data.controls[e.currentTarget.dataset.id] = {
|
||||
play: false,
|
||||
index: 1
|
||||
}
|
||||
} else if (this.data.controls[e.currentTarget.dataset.id] && e.currentTarget.dataset.source.length > (this.data.controls[e.currentTarget.dataset.id].index + 1)) {
|
||||
this.data.controls[e.currentTarget.dataset.id].index++;
|
||||
}
|
||||
this.setData({
|
||||
controls: this.data.controls
|
||||
})
|
||||
this.triggerEvent('error', {
|
||||
target: e.currentTarget,
|
||||
message: e.detail.errMsg
|
||||
}, {
|
||||
bubbles: true,
|
||||
composed: true
|
||||
});
|
||||
},
|
||||
//内部方法:加载视频
|
||||
_loadVideo(e) {
|
||||
this.data.controls[e.currentTarget.dataset.id] = {
|
||||
play: true,
|
||||
index: 0
|
||||
}
|
||||
this.setData({
|
||||
controls: this.data.controls
|
||||
})
|
||||
},
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"trees":"./trees"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<!--Parser/trees/trees.wxml-->
|
||||
<wxs module="cssHandler" src="./cssHandler.wxs" />
|
||||
<block wx:for='{{nodes}}' wx:key="index">
|
||||
<block wx:if="{{!item.continue}}">
|
||||
<!--图片-->
|
||||
<rich-text wx:if="{{item.name=='img'}}" style="{{cssHandler.getStyle(item.attrs.style,'inline-block')}}" nodes='{{cssHandler.setImgStyle(item,controls.imgMode)}}' data-ignore='{{item.attrs.ignore}}' data-src='{{item.attrs.src}}' bindtap='previewEvent' />
|
||||
<!--文本-->
|
||||
<block wx:elif="{{item.type=='text'}}">
|
||||
<text wx:if="{{!item.decode}}" decode>{{item.text}}</text>
|
||||
<rich-text wx:else style="display:inline-block" nodes="{{[item]}}"></rich-text>
|
||||
</block>
|
||||
<text wx:elif="{{item.name=='br'}}">\n</text>
|
||||
<!--视频-->
|
||||
<block wx:elif="{{item.name=='video'}}">
|
||||
<view wx:if="{{item.attrs.id>'video3'&&!controls[item.attrs.id].play}}" class="video" style="{{item.attrs.style+(item.attrs.width?(';width:'+item.attrs.width):'')+(item.attrs.height?('height:'+item.attrs.height):'')}}" data-id="{{item.attrs.id}}" bindtap="_loadVideo">
|
||||
<view class="video-triangle" />
|
||||
</view>
|
||||
<video wx:else src='{{controls[item.attrs.id]?item.attrs.source[controls[item.attrs.id].index]:item.attrs.src}}' id="{{item.attrs.id}}" loop='{{item.attrs.loop}}' controls='{{item.attrs.controls}}' autoplay="{{item.attrs.autoplay||controls[item.attrs.id].play}}"
|
||||
class="v" muted="{{item.attrs.muted}}" style="{{item.attrs.style+(item.attrs.width?(';width:'+item.attrs.width):'')+(item.attrs.height?('height:'+item.attrs.height):'')}}" data-id="{{item.attrs.id}}" data-source="{{item.attrs.source}}" bindplay='playEvent'
|
||||
binderror="errorEvent" />
|
||||
</block>
|
||||
<!--音频-->
|
||||
<audio wx:elif="{{item.name=='audio'}}" src='{{controls[item.attrs.id]?item.attrs.source[controls[item.attrs.id].index]:item.attrs.src}}' id="{{item.attrs.id}}" loop='{{item.attrs.loop}}' controls='{{item.attrs.controls}}' poster='{{item.attrs.poster}}'
|
||||
name='{{item.attrs.name}}' author='{{item.attrs.author}}' style="{{item.attrs.style}}" data-id="{{item.attrs.id}}" data-source="{{item.attrs.source}}" binderror="errorEvent" />
|
||||
<!--富文本-->
|
||||
<rich-text wx:else class="{{item.name}}" style="{{cssHandler.getStyle(item.attrs.style,'block')}}" nodes="{{cssHandler.setStyle(item)}}" />
|
||||
</block>
|
||||
<!--链接-->
|
||||
<navigator wx:elif="{{item.name=='a'}}" url="{{item.attrs.href}}" style="{{item.attrs.style}}" data-href='{{item.attrs.href}}' hover-class="navigator-hover" hover-start-time="25" hover-stay-time="300" bindtap="tapEvent">
|
||||
<trees id="node" nodes="{{item.children}}" controls="{{controls}}" />
|
||||
</navigator>
|
||||
<!--继续递归-->
|
||||
<trees wx:else id="node" class="{{item.name}}" style="{{item.attrs.style}}" nodes="{{item.children}}" controls="{{controls}}" />
|
||||
</block>
|
||||
@@ -0,0 +1,69 @@
|
||||
/* 链接受到点击的hover-class,可自定义修改 */
|
||||
.navigator-hover {
|
||||
opacity: 0.7;
|
||||
text-decoration: underline;
|
||||
}
|
||||
/* 以下内容不建议修改 */
|
||||
:host {
|
||||
display: inherit;
|
||||
float: inherit;
|
||||
}
|
||||
.sub, .sup, .bdo, .bdi, .ruby, .rt {
|
||||
display: inline-block !important;
|
||||
}
|
||||
.div, .blockquote, .p{
|
||||
display:block;
|
||||
}
|
||||
.b, .strong {
|
||||
display: inline;
|
||||
font-weight: bold;
|
||||
}
|
||||
.em, .i {
|
||||
display: inline;
|
||||
font-style: italic;
|
||||
}
|
||||
.del {
|
||||
display: inline;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
.ins {
|
||||
display: inline;
|
||||
text-decoration: underline;
|
||||
}
|
||||
.code {
|
||||
display: inline;
|
||||
font-family: monospace;
|
||||
}
|
||||
.big {
|
||||
font-size:1.2em;
|
||||
display:inline;
|
||||
}
|
||||
.small {
|
||||
font-size:0.8em;
|
||||
display:inline;
|
||||
}
|
||||
.q, .span, .label, .abbr {
|
||||
display: inline;
|
||||
}
|
||||
.q::before {
|
||||
content: '"';
|
||||
}
|
||||
.q::after {
|
||||
content: '"';
|
||||
}
|
||||
.video {
|
||||
background-color: rgb(0, 0, 0);
|
||||
width: 100%;
|
||||
height: auto;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
}
|
||||
.video-triangle {
|
||||
border-width: 15px 0 15px 30px;
|
||||
border-style: solid;
|
||||
border-color: transparent transparent transparent white;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
margin: -15px 0 0 -15px;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// app.js
|
||||
const api = require('./utils/api');
|
||||
const store = require('./utils/store');
|
||||
|
||||
App({
|
||||
globalData: {
|
||||
/** 初始化完成的 Promise,页面 onLoad 里等它即可,避免首屏读不到数据 */
|
||||
ready: null,
|
||||
},
|
||||
|
||||
onLaunch() {
|
||||
this.globalData.ready = this.bootstrap();
|
||||
},
|
||||
|
||||
/**
|
||||
* 启动流程:配置再静默登录,最后拉已购课程。
|
||||
*
|
||||
* 每一步失败都不阻断启动:配置缺失时用兜底文案,登录失败时按未登录渲染。
|
||||
* 旧版本在页面 data 里同步读缓存、而缓存由异步写入,首次安装必然报错,这里不再重蹈。
|
||||
*/
|
||||
bootstrap() {
|
||||
const tasks = [
|
||||
api
|
||||
.getConfig()
|
||||
.then((cfg) => store.setSiteConfig(cfg))
|
||||
.catch((err) => console.warn('[app] 配置加载失败', err)),
|
||||
|
||||
api
|
||||
.login()
|
||||
.then(() => api.getEntitlements())
|
||||
.then((list) => store.setEntitlements(list))
|
||||
.catch((err) => console.warn('[app] 登录或权益加载失败', err)),
|
||||
];
|
||||
return Promise.all(tasks);
|
||||
},
|
||||
|
||||
/** 页面调用它确保初始化完成。 */
|
||||
ready() {
|
||||
return this.globalData.ready || Promise.resolve();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/wode/wode",
|
||||
"pages/kecheng/kecheng",
|
||||
"pages/LoginOrOutDetails/LoginOrOutDetails",
|
||||
"pages/WebPageDetails/WebPageDetails",
|
||||
"pages/VideoDetails/VideoDetails",
|
||||
"pages/VideoDetailsPage/VideoDetailsPage",
|
||||
"pages/IndexNewCourseDetails/IndexNewCourseDetails",
|
||||
"pages/IndexFreeCourseDetails/IndexFreeCourseDetails",
|
||||
"pages/ChangeUserInfo/ChangeUserInfo"
|
||||
],
|
||||
"window": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "叶雷讲数学",
|
||||
"navigationBarBackgroundColor": "#fff",
|
||||
"backgroundColor": "#fff"
|
||||
},
|
||||
"tabBar": {
|
||||
"color":"#000",
|
||||
"selectedColor":"#00aa00",
|
||||
"borderStyle": "black",
|
||||
"list": [{
|
||||
"text": "首页",
|
||||
"pagePath": "pages/index/index",
|
||||
"iconPath": "static/image/shouye.png",
|
||||
"selectedIconPath": "static/image/shouye-selected.png"
|
||||
},
|
||||
{
|
||||
"text": "知识",
|
||||
"pagePath": "pages/kecheng/kecheng",
|
||||
"iconPath": "static/image/kecheng.png",
|
||||
"selectedIconPath": "static/image/kecheng-selected.png"
|
||||
},{
|
||||
"text": "我的",
|
||||
"pagePath": "pages/wode/wode",
|
||||
"iconPath": "static/image/wode.png",
|
||||
"selectedIconPath": "static/image/wode-selected.png"
|
||||
}]
|
||||
},
|
||||
"componentFramework": "glass-easel",
|
||||
"sitemapLocation": "sitemap.json",
|
||||
"lazyCodeLoading": "requiredComponents"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/**app.wxss**/
|
||||
.container {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 200rpx 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 全局配置。
|
||||
*
|
||||
* 部署时只需修改本文件即可切换环境——所有域名与路径都收口在这里。
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* 服务端 API。
|
||||
* 这个域名同时要加到微信后台的「request 合法域名」白名单。
|
||||
*/
|
||||
API_BASE_URL: 'https://yelaymaths-api.yeomai.site',
|
||||
|
||||
/**
|
||||
* 课程数据端(图片 / 视频)。
|
||||
* 已存库的正文 HTML 里的地址与此无关——那部分在数据迁移时按服务端的 STATIC_BASE_URL 改写。
|
||||
*/
|
||||
STATIC_BASE_URL: 'https://yelaymaths-data.yeomai.site',
|
||||
|
||||
/** 本地缓存 key */
|
||||
STORAGE: {
|
||||
TOKEN: 'accessToken',
|
||||
REFRESH_TOKEN: 'refreshToken',
|
||||
USER: 'userInfo',
|
||||
CONFIG: 'siteConfig',
|
||||
ENTITLEMENTS: 'entitlements',
|
||||
},
|
||||
|
||||
/** 占位图(走网络,不占用小程序包体积) */
|
||||
PLACEHOLDER: {
|
||||
AVATAR: '/Images/Placeholder/defaultAvatar.png',
|
||||
WECHAT: '/Images/Placeholder/weixin.png',
|
||||
USER: '/Images/Placeholder/user.png',
|
||||
},
|
||||
|
||||
/** 请求超时(毫秒) */
|
||||
TIMEOUT: 15000,
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "yelaymaths",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "叶雷讲数学 — 微信小程序",
|
||||
"dependencies": {
|
||||
"@vant/weapp": "^1.11.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
// pages/ChangeUserInfo/ChangeUserInfo.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const config = require('../../config/index');
|
||||
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
// wxml 里直接用它拼头像路径,保持不变
|
||||
BaseURL: config.STATIC_BASE_URL,
|
||||
activeNames: [],
|
||||
username: '',
|
||||
HeadiconID: 0,
|
||||
list: 50,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
app.ready().then(() => this.applyUser());
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.applyUser();
|
||||
},
|
||||
|
||||
applyUser() {
|
||||
const user = store.getUser() || {};
|
||||
this.setData({
|
||||
username: user.nickname || '',
|
||||
HeadiconID: user.headiconId || 0,
|
||||
list: parseInt(store.cfg('profile.headicon_count', '50'), 10) || 50,
|
||||
});
|
||||
},
|
||||
|
||||
onChange(event) {
|
||||
let inputVal = event.detail;
|
||||
// 只保留中英文与数字
|
||||
inputVal = inputVal.replace(/[^\u4e00-\u9fa5a-zA-Z0-9]/g, '');
|
||||
// 去掉开头的数字
|
||||
inputVal = inputVal.replace(/^[0-9]+/, '');
|
||||
inputVal = inputVal.substring(0, 8);
|
||||
this.setData({ username: inputVal });
|
||||
},
|
||||
|
||||
selectHeadicon(event) {
|
||||
this.setData({ HeadiconID: event.currentTarget.dataset.index });
|
||||
},
|
||||
|
||||
onChange2(event) {
|
||||
this.setData({ activeNames: event.detail });
|
||||
},
|
||||
|
||||
onConfirm() {
|
||||
const nickname = (this.data.username || '').trim();
|
||||
if (!nickname) {
|
||||
wx.showToast({ title: '请输入用户名', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确定修改个人资料吗?',
|
||||
confirmColor: '#ff0000',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
wx.showLoading({ title: '提交中', mask: true });
|
||||
|
||||
api
|
||||
.updateMe({ nickname: nickname, headiconId: this.data.HeadiconID })
|
||||
.then((user) => {
|
||||
store.setUser(user);
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: '成功', icon: 'success', mask: true, duration: 1500 });
|
||||
setTimeout(() => wx.switchTab({ url: '/pages/wode/wode' }), 1500);
|
||||
})
|
||||
.catch((err) => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: err.message || '修改失败', icon: 'none', mask: true });
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-field": "@vant/weapp/field/index",
|
||||
"van-collapse": "@vant/weapp/collapse/index",
|
||||
"van-collapse-item": "@vant/weapp/collapse-item/index",
|
||||
"van-grid": "@vant/weapp/grid/index",
|
||||
"van-grid-item": "@vant/weapp/grid-item/index",
|
||||
"van-image": "@vant/weapp/image/index",
|
||||
"van-button": "@vant/weapp/button/index"
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<van-cell-group>
|
||||
<van-field
|
||||
label="用户名"
|
||||
value="{{username}}"
|
||||
placeholder="请输入用户名"
|
||||
border="true"
|
||||
bind:change="onChange"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-collapse value="{{ activeNames }}" bind:change="onChange2">
|
||||
<van-collapse-item title="头像" name="1">
|
||||
<view style="display: flex; justify-content: center; padding: 20rpx 0;">
|
||||
<van-image width="120rpx" height="120rpx" src="{{BaseURL}}/Images/Headicons/Headicon{{HeadiconID}}.png" />
|
||||
</view>
|
||||
<van-grid icon-size="80rpx">
|
||||
<scroll-view scroll-y style="min-height: 200rpx;max-height: 620rpx;" class="scroll-area">
|
||||
<van-grid-item wx:for="{{ list }}" wx:key="index" icon="{{BaseURL}}/Images/Headicons/Headicon{{index + 1}}.png" text="{{index + 1}}" bind:click="selectHeadicon" data-index="{{index + 1}}"/>
|
||||
</scroll-view>
|
||||
</van-grid>
|
||||
</van-collapse-item>
|
||||
</van-collapse>
|
||||
|
||||
<view class="button-container" style="text-align: center;padding: 20rpx;">
|
||||
<van-button type="primary" bind:click="onConfirm">确认修改</van-button>
|
||||
</view>
|
||||
@@ -0,0 +1 @@
|
||||
/* pages/ChangeUserInfo/ChangeUserInfo.wxss */
|
||||
@@ -0,0 +1,56 @@
|
||||
// pages/IndexFreeCourseDetails/IndexFreeCourseDetails.js
|
||||
const api = require('../../utils/api');
|
||||
const format = require('../../utils/format');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
VideoTitle: '',
|
||||
playdata: [],
|
||||
VideoPlayerSrc: '',
|
||||
HiddenVideoControl: true,
|
||||
top: 0,
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const seriesNo = options.seriesNo;
|
||||
if (!seriesNo) {
|
||||
wx.switchTab({ url: '/pages/index/index' });
|
||||
return;
|
||||
}
|
||||
|
||||
api
|
||||
.getFreeLessons(Number(seriesNo))
|
||||
.then((list) => {
|
||||
const rows = (list || []).map((item) => ({
|
||||
coverUrl: item.coverUrl,
|
||||
videoTitle: item.videoTitle,
|
||||
intro: item.intro,
|
||||
publishedAt: format.toDateString(item.publishedAt),
|
||||
duration: item.duration,
|
||||
videoUrl: item.videoUrl,
|
||||
}));
|
||||
this.setData({
|
||||
playdata: rows,
|
||||
VideoTitle: rows.length ? rows[0].videoTitle || '' : '',
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('[IndexFreeCourseDetails] 加载失败', err);
|
||||
this.setData({ playdata: [] });
|
||||
});
|
||||
},
|
||||
|
||||
onTapLesson(e) {
|
||||
const item = this.data.playdata[e.currentTarget.dataset.index];
|
||||
if (!item || !item.videoUrl) {
|
||||
wx.showToast({ title: '该课时暂无视频', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.setData({ VideoPlayerSrc: item.videoUrl, HiddenVideoControl: false, top: 420 });
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<video hidden="{{HiddenVideoControl}}" class="videoplayer" src="{{VideoPlayerSrc}}" />
|
||||
<scroll-view class="scrollarea" scroll-y type="list" style="top:{{top}}rpx;">
|
||||
<view class="jieshao">
|
||||
<text decode class="video_biaoti"> {{VideoTitle}}</text>
|
||||
<text decode class="video_info"> 已更新{{playdata.length}}期</text>
|
||||
</view>
|
||||
|
||||
<view class="videolistcontainer" bind:tap="onTapLesson"
|
||||
wx:for="{{playdata}}" wx:for-item="item" wx:for-index="index" wx:key="index" data-index="{{index}}">
|
||||
<view class="videoimage">
|
||||
<image class="coverimage" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="videoinfo">
|
||||
<text class="videotitle">{{item.videoTitle}}</text>
|
||||
<text class="videodetails">{{item.intro}}</text>
|
||||
<view class="videoinfo2">
|
||||
<text class="videodata">{{item.publishedAt}}</text>
|
||||
<text class="videotime">{{item.duration}}min</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
.videoplayer {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 420rpx;
|
||||
width: 750rpx;
|
||||
z-index: 999;
|
||||
}
|
||||
.scrollarea {
|
||||
position: relative;
|
||||
top: 420rpx;
|
||||
flex: 1;
|
||||
overflow-y: hidden;
|
||||
|
||||
}
|
||||
|
||||
.jieshao {
|
||||
margin-bottom: 10rpx;
|
||||
/* box-shadow: 0 4rpx 4rpx rgba(150, 150, 150, 0.5); */
|
||||
position: relative;
|
||||
/* height: 100rpx; */
|
||||
display: block;
|
||||
}
|
||||
.video_biaoti {
|
||||
text-align: center;
|
||||
display: block;
|
||||
font-size: 40rpx;
|
||||
}
|
||||
|
||||
.video_miaoshu {
|
||||
text-align: center;
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.video_info {
|
||||
position: absolute;
|
||||
bottom: 10rpx;
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
right: 30rpx;
|
||||
}
|
||||
.video_list_content {
|
||||
margin: 10rpx 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
.videolistcontainer {
|
||||
border-radius: 20rpx;
|
||||
margin: 10rpx 10rpx;
|
||||
box-shadow: 0 0 4rpx rgba(0, 0, 0, 0.5);
|
||||
width: 730rpx;
|
||||
height: 200rpx;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.videoimage {
|
||||
width: 320rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 10rpx;
|
||||
margin-left: 10rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 5rpx 10rpx rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.videoinfo{
|
||||
position: relative;
|
||||
width: 390rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 10rpx;
|
||||
margin-left: 20rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
.videotitle {
|
||||
text-align: left;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.videodetails {
|
||||
display: block;
|
||||
margin: 10rpx 0rpx;
|
||||
font-size: 25rpx;
|
||||
line-height: 30rpx;
|
||||
}
|
||||
|
||||
.videoinfo2 {
|
||||
position:absolute;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
justify-content:left;
|
||||
}
|
||||
.videodata {
|
||||
font-size: 20rpx;
|
||||
}
|
||||
|
||||
.videotime {
|
||||
font-size: 20rpx;
|
||||
margin-left: 40rpx;
|
||||
}
|
||||
.coverimage {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// pages/IndexNewCourseDetails/IndexNewCourseDetails.js
|
||||
const api = require('../../utils/api');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
html: ' ',
|
||||
courseCode: '',
|
||||
courseTitle: '',
|
||||
priceYuan: '',
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options.id;
|
||||
if (!id) return;
|
||||
|
||||
api
|
||||
.getHomeCourses()
|
||||
.then((list) => {
|
||||
const item = (list || []).filter((c) => String(c.id) === String(id))[0];
|
||||
if (!item) return;
|
||||
this.setData({
|
||||
html: item.content || ' ',
|
||||
courseCode: item.courseCode || '',
|
||||
courseTitle: item.courseTitle || '',
|
||||
});
|
||||
})
|
||||
.catch((err) => console.error('[IndexNewCourseDetails] 加载失败', err));
|
||||
},
|
||||
|
||||
/** 复用付费课页面完成购买:未拥有时那里会展示价格与购买按钮。 */
|
||||
toBuy() {
|
||||
if (!this.data.courseCode) return;
|
||||
wx.navigateTo({ url: '/pages/VideoDetails/VideoDetails?code=' + this.data.courseCode });
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"Parser":"/Parser/index"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<!--pages/IndexNewCourseDetails/IndexNewCourseDetails.wxml-->
|
||||
<Parser html="{{html}}">加载中...</Parser>
|
||||
|
||||
<view class="fixed-btn-wrapper">
|
||||
<view class="btn-group">
|
||||
<button wx:if="{{courseCode}}" class="DianJiXiangQing1" bind:tap="toBuy">
|
||||
<text class="DianJiXiangQing2">立即购买</text>
|
||||
</button>
|
||||
<button class="DianJiXiangQing1" open-type="contact" bindcontact="handleContact">
|
||||
<text class="DianJiXiangQing2">咨询客服</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,46 @@
|
||||
/* pages/IndexNewCourseDetails/IndexNewCourseDetails.wxss */
|
||||
@keyframes breathe {
|
||||
0%, 100% {
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
}
|
||||
|
||||
.fixed-btn-wrapper {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 60rpx;
|
||||
padding: 0 20rpx; /* 调整为左右边距 */
|
||||
display: flex;
|
||||
justify-content: center; /* 水平居中 */
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
max-width: 700rpx;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.DianJiXiangQing1 {
|
||||
flex: 1;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
margin: 0 10rpx;
|
||||
border-radius: 45rpx;
|
||||
height: 90rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
animation: breathe 1s linear infinite;
|
||||
}
|
||||
|
||||
.DianJiXiangQing2 {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// pages/LoginOrOutDetails/LoginOrOutDetails.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const config = require('../../config/index');
|
||||
|
||||
const app = getApp();
|
||||
|
||||
/** 未填昵称时自动生成,与旧版行为一致:用户 + 8 位小写字母数字 */
|
||||
function randomNickname() {
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let s = '';
|
||||
for (let i = 0; i < 8; i++) s += chars[Math.floor(Math.random() * chars.length)];
|
||||
return '用户' + s;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: { avatarUrl: '', nickName: '' },
|
||||
loginStatue: false,
|
||||
LoginTag: '一键登录',
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
app.ready().then(() => this.refresh());
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
refresh() {
|
||||
const user = store.getUser();
|
||||
const registered = !!(user && user.nickname);
|
||||
this.setData({
|
||||
loginStatue: registered,
|
||||
LoginTag: registered ? '退出登录' : '一键登录',
|
||||
userInfo: {
|
||||
avatarUrl: config.STATIC_BASE_URL + config.PLACEHOLDER.WECHAT,
|
||||
nickName: registered ? user.nickname : '',
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
onLoginBtnClick() {
|
||||
const nickname = this.data.userInfo.nickName || randomNickname();
|
||||
wx.showLoading({ title: '请稍候', mask: true });
|
||||
|
||||
api
|
||||
.updateMe({ nickname: nickname })
|
||||
.then((user) => {
|
||||
store.setUser(user);
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: '成功', icon: 'success', mask: true, duration: 1500 });
|
||||
setTimeout(() => wx.switchTab({ url: '/pages/wode/wode' }), 1500);
|
||||
})
|
||||
.catch((err) => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: err.message || '登录失败', icon: 'none', mask: true });
|
||||
});
|
||||
},
|
||||
|
||||
onlogout() {
|
||||
if (!this.data.loginStatue) return;
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '确定退出登录吗?',
|
||||
confirmColor: '#ff0000',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return;
|
||||
wx.showLoading({ title: '请稍候', mask: true });
|
||||
api.logout().then(() => {
|
||||
wx.hideLoading();
|
||||
wx.switchTab({ url: '/pages/wode/wode' });
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "个人信息"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<scroll-view class="scrollarea" scroll-y type="list">
|
||||
|
||||
<view class="imgview">
|
||||
<image class="touxiang_img" src="{{userInfo.avatarUrl}}" mode="" />
|
||||
</view>
|
||||
<view class="imgview2">
|
||||
<text class="imgtext2">叶雷讲数学</text>
|
||||
</view>
|
||||
<view class="imgview3">
|
||||
<text class="imgtext3">让数学不再难学</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!loginStatue}}" class="btn_wrapper">
|
||||
<button plain class="btn1" bind:tap="onLoginBtnClick">
|
||||
<text class="btn_text">{{LoginTag}}</text>
|
||||
</button>
|
||||
</view>
|
||||
<view wx:else="{{loginStatue}}" class="btn_wrapper">
|
||||
<button plain class="btn2" bind:tap="onlogout">
|
||||
<text class="btn_text">退出登录</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
|
||||
</scroll-view>
|
||||
@@ -0,0 +1,117 @@
|
||||
/* pages/LoginOrOutDetails/LoginOrOutDetails.wxss */
|
||||
page {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.scrollarea {
|
||||
flex: 1;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.warp {
|
||||
|
||||
/* border: 1px solid #353535; */
|
||||
padding: 10rpx 0;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
margin: 50rpx 100rpx;
|
||||
border-radius: 30rpx;
|
||||
}
|
||||
.userinfo1 {
|
||||
margin-top: 100rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.userinfo2 {
|
||||
margin-top: 80rpx;
|
||||
margin-bottom: 100rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
}
|
||||
|
||||
.touxiang_btn[plain] {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
padding: 0;
|
||||
margin-left: 50rpx;
|
||||
margin-right: 50rpx;
|
||||
border-radius: 8px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.touxiang_text {
|
||||
margin-right: 50rpx;
|
||||
font-size: 34rpx;
|
||||
}
|
||||
.imgview {
|
||||
margin-top: 300rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.imgview2 {
|
||||
margin-top: 10rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.imgview3 {
|
||||
color: rgb(95, 95, 95);
|
||||
font-size: 25rpx;
|
||||
margin-top: 15rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.imgtext {
|
||||
display: block;
|
||||
|
||||
}
|
||||
|
||||
.touxiang_img {
|
||||
display: block;
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
}
|
||||
|
||||
.nickname_label {
|
||||
margin-right: 50rpx;
|
||||
font-size: 34rpx;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.nickname_input {
|
||||
width: 160rpx;
|
||||
padding-left: 40rpx;
|
||||
}
|
||||
|
||||
.btn1 {
|
||||
width: 546rpx;
|
||||
margin-top: 30rpx;
|
||||
border-radius: 15rpx;
|
||||
}
|
||||
.btn1[plain] {
|
||||
border: 0px solid #d10000;
|
||||
background-color: #d10000;
|
||||
/* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); */
|
||||
}
|
||||
.btn2 {
|
||||
width: 546rpx;
|
||||
margin-top: 30rpx;
|
||||
margin-bottom: 100rpx;
|
||||
border-radius: 15rpx;
|
||||
}
|
||||
.btn2[plain] {
|
||||
border: 0px solid #d10000;
|
||||
background-color: #d10000;
|
||||
/* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); */
|
||||
}
|
||||
.btn_text {
|
||||
|
||||
color: rgb(255, 255, 255);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// pages/VideoDetails/VideoDetails.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const format = require('../../utils/format');
|
||||
|
||||
const POLL_INTERVAL = 1500;
|
||||
const POLL_MAX = 8;
|
||||
|
||||
Page({
|
||||
data: {
|
||||
code: '',
|
||||
owned: false,
|
||||
loading: true,
|
||||
buying: false,
|
||||
VideoTitle: '',
|
||||
VideoDetails: '',
|
||||
coverUrl: '',
|
||||
priceYuan: '',
|
||||
playdata: [],
|
||||
VideoPlayerSrc: '',
|
||||
HiddenVideoControl: true,
|
||||
top: 0,
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const code = options.code;
|
||||
if (!code) {
|
||||
wx.switchTab({ url: '/pages/kecheng/kecheng' });
|
||||
return;
|
||||
}
|
||||
this.setData({ code: code });
|
||||
this.load(code);
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (this.data.code && this.data.owned) this.load(this.data.code);
|
||||
},
|
||||
|
||||
load(code) {
|
||||
api
|
||||
.getCourse(code)
|
||||
.then((course) => {
|
||||
this.setData({
|
||||
loading: false,
|
||||
owned: course.owned,
|
||||
VideoTitle: course.title || '',
|
||||
VideoDetails: course.intro || '',
|
||||
coverUrl: course.coverUrl || '',
|
||||
priceYuan: format.fenToYuan(course.priceFen),
|
||||
});
|
||||
if (course.owned) this.loadLessons(code);
|
||||
})
|
||||
.catch((err) => {
|
||||
this.setData({ loading: false });
|
||||
wx.showToast({ title: err.message || '课程加载失败', icon: 'none' });
|
||||
setTimeout(() => wx.switchTab({ url: '/pages/kecheng/kecheng' }), 1500);
|
||||
});
|
||||
},
|
||||
|
||||
loadLessons(code) {
|
||||
api
|
||||
.getLessons(code)
|
||||
.then((list) => {
|
||||
const rows = (list || []).map((item) => ({
|
||||
chapterId: item.chapterId,
|
||||
playId: item.playId,
|
||||
chapterTitle: item.chapterTitle,
|
||||
lessonTitle: item.lessonTitle,
|
||||
duration: item.duration,
|
||||
publishedAt: format.toDateString(item.publishedAt),
|
||||
coverUrl: item.coverUrl,
|
||||
}));
|
||||
this.setData({ playdata: rows });
|
||||
})
|
||||
.catch((err) => {
|
||||
this.setData({ playdata: [] });
|
||||
console.warn('[VideoDetails] 课时加载失败', err);
|
||||
});
|
||||
},
|
||||
|
||||
/** 点课时:向后端换一次性播放地址,视频本身不直接暴露。 */
|
||||
onTapLesson(e) {
|
||||
const item = this.data.playdata[e.currentTarget.dataset.index];
|
||||
if (!item) return;
|
||||
|
||||
wx.showLoading({ title: '加载中', mask: true });
|
||||
api
|
||||
.getPlayUrl(this.data.code, item.chapterId, item.playId)
|
||||
.then((res) => {
|
||||
wx.hideLoading();
|
||||
this.setData({ VideoPlayerSrc: res.url, HiddenVideoControl: false, top: 420 });
|
||||
})
|
||||
.catch((err) => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: err.message || '无法播放', icon: 'none' });
|
||||
});
|
||||
},
|
||||
|
||||
/** 购买:下单 → 拉起支付 → 轮询订单状态确认发货。 */
|
||||
buyNow() {
|
||||
if (this.data.buying) return;
|
||||
if (typeof wx.requestVirtualPayment !== 'function') {
|
||||
wx.showToast({ title: '当前微信版本不支持支付,请升级微信', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({ buying: true });
|
||||
wx.showLoading({ title: '发起支付', mask: true });
|
||||
|
||||
api
|
||||
.createOrder(this.data.code)
|
||||
.then((order) => {
|
||||
wx.hideLoading();
|
||||
return api.requestVirtualPayment(order.payData).then(() => order.outTradeNo);
|
||||
})
|
||||
.then((outTradeNo) => this.waitForDelivery(outTradeNo))
|
||||
.catch((err) => {
|
||||
wx.hideLoading();
|
||||
this.setData({ buying: false });
|
||||
// 用户主动取消不算错误
|
||||
if (err && err.errMsg && err.errMsg.indexOf('cancel') >= 0) return;
|
||||
wx.showToast({ title: (err && err.message) || '支付失败', icon: 'none' });
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 支付成功后权益由服务端发货推送发放,存在秒级延迟,这里轮询确认。
|
||||
* 即便轮询全部超时也不会丢单:服务端有定时查单兜底。
|
||||
*/
|
||||
waitForDelivery(outTradeNo) {
|
||||
let attempts = 0;
|
||||
const poll = () => {
|
||||
attempts += 1;
|
||||
return api.getOrder(outTradeNo).then((order) => {
|
||||
if (order.status === 2) {
|
||||
this.setData({ buying: false, owned: true });
|
||||
wx.showToast({ title: '购买成功', icon: 'success', mask: true });
|
||||
this.load(this.data.code);
|
||||
return;
|
||||
}
|
||||
if (attempts >= POLL_MAX || order.status === 3 || order.status === 4) {
|
||||
this.setData({ buying: false });
|
||||
wx.showToast({ title: '支付已提交,开通可能稍有延迟', icon: 'none', duration: 3000 });
|
||||
return;
|
||||
}
|
||||
return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL)).then(poll);
|
||||
});
|
||||
};
|
||||
return poll();
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<!--pages/VideoDetails/VideoDetails.wxml-->
|
||||
|
||||
<!-- 已拥有:正常播放 -->
|
||||
<block wx:if="{{owned}}">
|
||||
<video hidden="{{HiddenVideoControl}}" class="videoplayer" src="{{VideoPlayerSrc}}" />
|
||||
<scroll-view class="scrollarea" scroll-y type="list" style="top:{{top}}rpx;">
|
||||
<view class="jieshao">
|
||||
<text decode class="video_biaoti"> {{VideoTitle}}</text>
|
||||
<text decode class="video_miaoshu"> {{VideoDetails}}</text>
|
||||
<text decode class="video_info"> 已更新{{playdata.length}}期</text>
|
||||
</view>
|
||||
|
||||
<view class="videolistcontainer" bind:tap="onTapLesson"
|
||||
wx:for="{{playdata}}" wx:for-item="item" wx:for-index="index" wx:key="index" data-index="{{index}}">
|
||||
<view class="videoimage">
|
||||
<image class="coverimage" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="videoinfo">
|
||||
<text class="videotitle">{{item.chapterTitle}}</text>
|
||||
<text class="videodetails">{{item.lessonTitle}}</text>
|
||||
<view class="videoinfo2">
|
||||
<text class="videodata">{{item.publishedAt}}</text>
|
||||
<text class="videotime">{{item.duration}}min</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</block>
|
||||
|
||||
<!-- 未拥有:展示介绍与购买入口 -->
|
||||
<block wx:else>
|
||||
<scroll-view class="scrollarea" scroll-y type="list">
|
||||
<view class="jieshao">
|
||||
<text decode class="video_biaoti"> {{VideoTitle}}</text>
|
||||
<text decode class="video_miaoshu"> {{VideoDetails}}</text>
|
||||
</view>
|
||||
|
||||
<view style="padding: 0 40rpx;">
|
||||
<image style="width: 100%; border-radius: 16rpx;" src="{{coverUrl}}" mode="widthFix" />
|
||||
</view>
|
||||
|
||||
<view class="fixed-btn-wrapper">
|
||||
<view class="btn-group">
|
||||
<button class="DianJiXiangQing1" bind:tap="buyNow" disabled="{{buying}}">
|
||||
<text class="DianJiXiangQing2">{{buying ? '处理中…' : '立即购买 ¥' + priceYuan}}</text>
|
||||
</button>
|
||||
<button class="DianJiXiangQing1" open-type="contact">
|
||||
<text class="DianJiXiangQing2">咨询客服</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</block>
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
.videoplayer {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 420rpx;
|
||||
width: 750rpx;
|
||||
z-index: 999;
|
||||
}
|
||||
.scrollarea {
|
||||
position: relative;
|
||||
top: 420rpx;
|
||||
flex: 1;
|
||||
overflow-y: hidden;
|
||||
|
||||
}
|
||||
|
||||
.jieshao {
|
||||
margin-bottom: 10rpx;
|
||||
/* box-shadow: 0 4rpx 4rpx rgba(150, 150, 150, 0.5); */
|
||||
position: relative;
|
||||
height: 200rpx;
|
||||
}
|
||||
.video_biaoti {
|
||||
text-align: center;
|
||||
display: block;
|
||||
font-size: 40rpx;
|
||||
}
|
||||
|
||||
.video_miaoshu {
|
||||
text-align: center;
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.video_info {
|
||||
position:absolute;
|
||||
bottom: 10rpx;
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
right: 30rpx;
|
||||
}
|
||||
.video_list_content {
|
||||
margin: 10rpx 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
.videolistcontainer {
|
||||
border-radius: 20rpx;
|
||||
margin: 10rpx 10rpx;
|
||||
box-shadow: 0 0 4rpx rgba(0, 0, 0, 0.5);
|
||||
width: 730rpx;
|
||||
height: 200rpx;
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
||||
.videoimage {
|
||||
width: 320rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 10rpx;
|
||||
margin-left: 10rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 5rpx 10rpx rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.videoinfo{
|
||||
position: relative;
|
||||
width: 390rpx;
|
||||
height: 180rpx;
|
||||
border-radius: 10rpx;
|
||||
margin-left: 20rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
.videotitle {
|
||||
text-align: left;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.videodetails {
|
||||
display: block;
|
||||
margin: 10rpx 0rpx;
|
||||
font-size: 25rpx;
|
||||
line-height: 30rpx;
|
||||
}
|
||||
|
||||
.videoinfo2 {
|
||||
position:absolute;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
justify-content:left;
|
||||
}
|
||||
.videodata {
|
||||
font-size: 20rpx;
|
||||
}
|
||||
|
||||
.videotime {
|
||||
font-size: 20rpx;
|
||||
margin-left: 40rpx;
|
||||
}
|
||||
.coverimage {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// pages/VideoDetailsPage/VideoDetailsPage.js
|
||||
const htmlSnip =
|
||||
`<p>
|
||||
在初中数学的考试当中,解所有题型都需要用到公式,公式的重要性不言而喻!为了更好的帮助孩子们记住初中数学常用的公式、定理,在此老师给大家总结了初中三年所有的公式及定理!这份资料十分珍贵,每次考试都能用的上!
|
||||
</p>
|
||||
<p>
|
||||
<img src="https://api.yeomai.site/WebPages/2/1.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/2.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/3.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/4.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/5.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/6.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/7.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/8.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/9.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/10.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/11.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/12.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/13.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/14.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/15.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/16.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/17.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/18.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/19.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/20.jpg"/><br/><img src="https://api.yeomai.site/WebPages/2/21.jpg"/>
|
||||
</p>
|
||||
<p>
|
||||
<br/>
|
||||
</p>
|
||||
`
|
||||
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
htmlSnip,
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
},
|
||||
//允许分享到朋友圈
|
||||
onShareTimeline(){
|
||||
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"Parser":"/Parser/index"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<text>VideoDetailsPage</text>
|
||||
<text>富文本测试</text>
|
||||
<Parser html="{{htmlSnip}}" />
|
||||
@@ -0,0 +1,7 @@
|
||||
/* pages/VideoDetailsPage/VideoDetailsPage.wxss */
|
||||
text {
|
||||
/* display:inherit; */
|
||||
left: 400rpx;
|
||||
top: 100 px;
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// pages/WebPageDetails/WebPageDetails.js
|
||||
const api = require('../../utils/api');
|
||||
const format = require('../../utils/format');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
htmlcontent: ' ',
|
||||
author: '',
|
||||
title: '',
|
||||
date: '',
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const id = options.id;
|
||||
if (!id) return;
|
||||
|
||||
api
|
||||
.getArticle(id)
|
||||
.then((article) => {
|
||||
if (!article) return;
|
||||
this.setData({
|
||||
htmlcontent: article.content || ' ',
|
||||
author: article.publisher || '',
|
||||
title: article.title || '',
|
||||
date: format.toDateString(article.publishedAt),
|
||||
});
|
||||
})
|
||||
.catch((err) => console.error('[WebPageDetails] 加载失败', err));
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
||||
},
|
||||
|
||||
onShareTimeline() {
|
||||
return { title: '叶雷讲数学' };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"Parser":"/Parser/index"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<scroll-view class="scrollarea" scroll-y type="list">
|
||||
<text class="pagetitle">{{title}}</text>
|
||||
|
||||
<view class="pageauthoranddate">
|
||||
<text class="pageauthor">{{author}}</text>
|
||||
<text class="pagedate">{{date}}</text>
|
||||
</view>
|
||||
|
||||
<Parser html="{{htmlcontent}}" />
|
||||
|
||||
|
||||
</scroll-view>
|
||||
@@ -0,0 +1,63 @@
|
||||
/**index.wxss**/
|
||||
page {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.scrollarea {
|
||||
flex: 1;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
.pagetitle {
|
||||
display: block;
|
||||
font-size: 40rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.pagecontent {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
text-align: left;
|
||||
text-indent: 0rem;
|
||||
margin-bottom: 30rpx;
|
||||
padding: 0 10rpx;
|
||||
}
|
||||
.pagecontent:first-child {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
.pageimg {
|
||||
width: 100%;
|
||||
}
|
||||
.pagevideo {
|
||||
width: 750rpx;
|
||||
height: 421rpx;
|
||||
}
|
||||
.pageauthor {
|
||||
color: rgb(165, 165, 165);
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.pagedate {
|
||||
color: rgb(151, 151, 151);
|
||||
padding-left: 60rpx;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
.pageauthoranddate {
|
||||
height: 80rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.sharebtn[plain] {
|
||||
display: inline;
|
||||
color: cadetblue;
|
||||
border:none;
|
||||
font-size: 30rpx;
|
||||
margin:0 rpx;
|
||||
margin-left: 20rpx;
|
||||
margin-right: 0rpx;
|
||||
padding:0 ;
|
||||
width: 120rpx;
|
||||
}
|
||||
.content123 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
// pages/index/index.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const config = require('../../config/index');
|
||||
|
||||
const app = getApp();
|
||||
const updateManager = wx.getUpdateManager();
|
||||
|
||||
const PAGE_SIZE = 10;
|
||||
|
||||
Page({
|
||||
data: {
|
||||
staticBase: config.STATIC_BASE_URL,
|
||||
banners: [],
|
||||
courseList: [],
|
||||
freeCourseList: [],
|
||||
articles: [],
|
||||
page: 1,
|
||||
articleTotal: 0,
|
||||
loadingMore: false,
|
||||
noMore: false,
|
||||
title1: '',
|
||||
title2: '',
|
||||
title3: '',
|
||||
footerText: '',
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 等应用初始化完成再取配置,避免首屏读到空缓存
|
||||
app.ready().then(() => this.applyConfig());
|
||||
this.loadAll();
|
||||
},
|
||||
|
||||
applyConfig() {
|
||||
this.setData({
|
||||
title1: store.cfg('home.title.paid', '付费课程'),
|
||||
title2: store.cfg('home.title.trial', '试听课程'),
|
||||
title3: store.cfg('home.title.public', '公开课程'),
|
||||
footerText: store.cfg('home.footer_text', '我是有底线的!'),
|
||||
});
|
||||
},
|
||||
|
||||
loadAll() {
|
||||
this.setData({ page: 1, noMore: false });
|
||||
|
||||
api
|
||||
.getBanners()
|
||||
.then((list) => this.setData({ banners: list || [] }))
|
||||
.catch((err) => console.error('[index] 轮播加载失败', err));
|
||||
|
||||
api
|
||||
.getHomeCourses()
|
||||
.then((list) => this.setData({ courseList: list || [] }))
|
||||
.catch((err) => console.error('[index] 新课加载失败', err));
|
||||
|
||||
api
|
||||
.getHomeFreeCourses()
|
||||
.then((list) => this.setData({ freeCourseList: list || [] }))
|
||||
.catch((err) => console.error('[index] 试听列表加载失败', err));
|
||||
|
||||
api
|
||||
.getArticles(1, PAGE_SIZE)
|
||||
.then((res) => this.setData({ articles: res.items || [], articleTotal: res.total || 0, page: 1 }))
|
||||
.catch((err) => console.error('[index] 文章加载失败', err));
|
||||
},
|
||||
|
||||
onShow() {
|
||||
updateManager.onCheckForUpdate(() => {});
|
||||
updateManager.onUpdateReady(() => {
|
||||
wx.showModal({
|
||||
title: '更新提示',
|
||||
showCancel: false,
|
||||
content: '新版本已准备好,即将重启应用',
|
||||
success: (res) => {
|
||||
if (res.confirm) updateManager.applyUpdate();
|
||||
},
|
||||
});
|
||||
});
|
||||
updateManager.onUpdateFailed(() => {});
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
Promise.all([this.reload()]).then(() => wx.stopPullDownRefresh());
|
||||
},
|
||||
|
||||
async reload() {
|
||||
try {
|
||||
const cfg = await api.getConfig();
|
||||
store.setSiteConfig(cfg);
|
||||
this.applyConfig();
|
||||
} catch (err) {
|
||||
console.warn('[index] 配置刷新失败', err);
|
||||
}
|
||||
this.loadAll();
|
||||
},
|
||||
|
||||
onReachBottom() {
|
||||
if (this.data.loadingMore || this.data.noMore) return;
|
||||
const next = this.data.page + 1;
|
||||
this.setData({ loadingMore: true });
|
||||
|
||||
api
|
||||
.getArticles(next, PAGE_SIZE)
|
||||
.then((res) => {
|
||||
const merged = this.data.articles.concat(res.items || []);
|
||||
this.setData({
|
||||
articles: merged,
|
||||
page: next,
|
||||
loadingMore: false,
|
||||
noMore: merged.length >= (res.total || 0),
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('[index] 加载更多失败', err);
|
||||
this.setData({ loadingMore: false });
|
||||
});
|
||||
},
|
||||
|
||||
toArticle(e) {
|
||||
wx.navigateTo({ url: '/pages/WebPageDetails/WebPageDetails?id=' + e.currentTarget.dataset.id });
|
||||
},
|
||||
|
||||
toNewCourse(e) {
|
||||
wx.navigateTo({ url: '/pages/IndexNewCourseDetails/IndexNewCourseDetails?id=' + e.currentTarget.dataset.id });
|
||||
},
|
||||
|
||||
toFreeCourse(e) {
|
||||
wx.navigateTo({
|
||||
url: '/pages/IndexFreeCourseDetails/IndexFreeCourseDetails?seriesNo=' + e.currentTarget.dataset.series,
|
||||
});
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
||||
},
|
||||
|
||||
onShareTimeline() {
|
||||
return { title: '叶雷讲数学' };
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-loading": "@vant/weapp/loading/index"
|
||||
},
|
||||
"onReachBottomDistance":50,
|
||||
"enablePullDownRefresh":true
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<!--index.wxml-->
|
||||
|
||||
<scroll-view class="container" scroll-y enable-flex type="custom">
|
||||
<view class="banner">
|
||||
<swiper class="bannerswiper" autoplay interval="20000" circular indicator-dots indicator-color="rgba(255, 255, 255, .3)" indicator-active-color="rgba(255, 255, 255, 1.0)" indicator-type="normal" duration="1000" easing-function="easeOutCubic">
|
||||
<swiper-item wx:for="{{banners}}" wx:for-item="item" wx:key="id" class="bannerswiperitem">
|
||||
<image class="indeximage" src="{{item.imageUrl}}" mode="aspectFill" />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
</view>
|
||||
|
||||
<!-- 新课上线 -->
|
||||
<view class="shouyetupianlist">
|
||||
<view wx:if="{{courseList.length > 0}}" class="biaoti01">
|
||||
<image class="biaoti01img" src="{{staticBase}}/Images/Icon/xinke.png" mode="aspectFill" />
|
||||
<text decode> {{title1}}</text>
|
||||
</view>
|
||||
<view class="shouyetupianlistcontent" wx:for="{{courseList}}" wx:for-item="item" wx:for-index="index" wx:key="id" data-id="{{item.id}}" bind:tap="toNewCourse">
|
||||
<view class="hengxianglist">
|
||||
<image class="indeximagelist" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 自我学习 -->
|
||||
<view class="shouyetupianlist">
|
||||
<view wx:if="{{freeCourseList.length > 0}}" class="biaoti01">
|
||||
<image class="biaoti01img" src="{{staticBase}}/Images/Icon/ziwoxuexi.png" mode="aspectFill" />
|
||||
<text decode> {{title2}}</text>
|
||||
</view>
|
||||
<view class="shouyetupianlistcontent" wx:for="{{freeCourseList}}" wx:for-item="item" wx:for-index="index" wx:key="id" data-series="{{item.seriesNo}}" bind:tap="toFreeCourse">
|
||||
<view class="hengxianglist">
|
||||
<image class="indeximagelist" src="{{item.coverUrl}}" mode="aspectFill" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 知识速通 -->
|
||||
<view class="shouyetupianlist">
|
||||
<view wx:if="{{articles.length > 0}}" class="biaoti01">
|
||||
<image class="biaoti01img" src="{{staticBase}}/Images/Icon/sutong.png" mode="aspectFill" />
|
||||
<text decode> {{title3}}</text>
|
||||
</view>
|
||||
|
||||
<view class="shouyetupianlistcontent01" wx:for="{{articles}}" wx:for-item="item" wx:for-index="index" wx:key="id" bind:tap="toArticle" data-id="{{item.id}}">
|
||||
<view class="hengxianglist01">
|
||||
<image class="indeximagelist01" src="{{item.thumbUrl}}" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="indeximagelistmiaosu">{{item.title}}</view>
|
||||
<view class="indeximagelistmiaosu01">
|
||||
<text class="indeximagelistmiaosu0102">{{item.intro}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view style="width: auto; margin: 0px auto; margin-bottom: 10px;">
|
||||
<text wx:if="{{noMore}}">{{footerText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</scroll-view>
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/**index.wxss**/
|
||||
/* 暂时未用到
|
||||
page {
|
||||
|
||||
} */
|
||||
|
||||
|
||||
.container {
|
||||
padding:0;
|
||||
align-items:center;
|
||||
flex-direction:column;
|
||||
justify-content:space-between;
|
||||
}
|
||||
.mulucontainer {
|
||||
width: 710rpx;
|
||||
height: 150rpx;
|
||||
white-space: nowrap; /*强制子元素为一行 */
|
||||
margin-left: 25rpx;
|
||||
}
|
||||
.navpage001 {
|
||||
display: inline-block;
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
margin-right: 25rpx;
|
||||
text-align: center;
|
||||
font-size: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
.navpage001img {
|
||||
margin:0 auto;
|
||||
width: 60%;
|
||||
height: 60%;
|
||||
}
|
||||
.mulucontainer .navpage001:last-child{
|
||||
margin-right: 0;
|
||||
}
|
||||
.banner{
|
||||
width: 100%;
|
||||
height: 400rpx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.shouyetupianlist {
|
||||
display: flex;
|
||||
flex-wrap: wrap;/* 允许内容换行 */
|
||||
justify-content:space-between;/* 水平方向上两端对齐 */
|
||||
}
|
||||
.shouyetupianlistcontent {
|
||||
/* display: inline; */
|
||||
padding: 0;
|
||||
margin: 20rpx;
|
||||
height: 204rpx;
|
||||
width: 334rpx; /* 每行两个图片,设置宽度为 48% 可以有一定的间距 */
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.shouyetupianlistcontent01 {
|
||||
position: relative;
|
||||
padding: 0;
|
||||
margin: 20rpx;
|
||||
height: 260rpx;
|
||||
width: 730rpx;
|
||||
overflow: hidden;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.indeximagelist {
|
||||
width: 100%;
|
||||
height: 204rpx;
|
||||
}
|
||||
.indeximagelist01 {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.tupianwenzi {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.biaoti01 {
|
||||
display: flex;
|
||||
width: 750rpx;
|
||||
height: 60rpx;
|
||||
align-items: center;
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
.biaoti01img {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
}
|
||||
.hengxianglist01 {
|
||||
display: flex;
|
||||
width: 300rpx;
|
||||
height: inherit; /* 推荐尺寸在300*250rpx 即150*125px */
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.indeximage{
|
||||
border-radius: 20rpx;
|
||||
height: 350rpx;
|
||||
width: 710rpx;
|
||||
transform: translate(20rpx, 30rpx);
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.bannerswiper {
|
||||
height: 390rpx;
|
||||
}
|
||||
.indeximagelistmiaosu {
|
||||
font-size: 28rpx;
|
||||
display:flex;
|
||||
position: absolute;
|
||||
top: 10rpx;
|
||||
left: 300rpx;
|
||||
height: 70rpx;
|
||||
align-items: center;
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
.indeximagelistmiaosu01 {
|
||||
display: inline;
|
||||
position: absolute;
|
||||
left: 300rpx;
|
||||
top: 35px;
|
||||
align-items: center;
|
||||
padding-left: 20rpx;
|
||||
}
|
||||
.indeximagelistmiaosu0102 {
|
||||
font-size: 20rpx;
|
||||
position: relative;
|
||||
top: -15px;
|
||||
width: 370rpx;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// pages/kecheng/kecheng.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const config = require('../../config/index');
|
||||
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
staticBase: config.STATIC_BASE_URL,
|
||||
hasCourse: false,
|
||||
ownedCourses: [],
|
||||
otherCourses: [],
|
||||
tipsHtml: '',
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 旧版本用 10ms 轮询最多 5 秒等登录数据,这里改为等初始化完成
|
||||
app.ready().then(() => this.refresh());
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (store.isLoggedIn()) this.refresh();
|
||||
},
|
||||
|
||||
refresh() {
|
||||
this.loadTips();
|
||||
|
||||
api
|
||||
.getEntitlements()
|
||||
.then((list) => {
|
||||
store.setEntitlements(list);
|
||||
this.setData({ ownedCourses: list || [], hasCourse: (list || []).length > 0 });
|
||||
})
|
||||
.catch((err) => console.warn('[kecheng] 已购课程加载失败', err));
|
||||
|
||||
api
|
||||
.getCourses()
|
||||
.then((list) => {
|
||||
this.setData({ otherCourses: (list || []).filter((c) => !c.owned) });
|
||||
})
|
||||
.catch((err) => console.warn('[kecheng] 课程列表加载失败', err));
|
||||
},
|
||||
|
||||
loadTips() {
|
||||
if (this.data.tipsHtml) return;
|
||||
api
|
||||
.getTips()
|
||||
.then((tip) => this.setData({ tipsHtml: (tip && tip.content) || ' ' }))
|
||||
.catch((err) => console.warn('[kecheng] 文案加载失败', err));
|
||||
},
|
||||
|
||||
toMyCourse(e) {
|
||||
wx.navigateTo({
|
||||
url: '/pages/VideoDetails/VideoDetails?code=' + e.currentTarget.dataset.code,
|
||||
});
|
||||
},
|
||||
|
||||
toStoreCourse(e) {
|
||||
wx.navigateTo({
|
||||
url: '/pages/VideoDetails/VideoDetails?code=' + e.currentTarget.dataset.code,
|
||||
});
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"Parser":"/Parser/index"
|
||||
},
|
||||
"navigationBarTitleText": "知识"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<scroll-view class="container" scroll-y enable-flex type="custom">
|
||||
<block wx:if="{{!hasCourse}}">
|
||||
<view style="width: 100%;height: 400rpx;">
|
||||
<image style="margin-top: 30rpx; margin-left: 20rpx; height: 350rpx; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); width: 710rpx; border-radius: 20rpx; background-color: rgb(0, 255, 255);"
|
||||
src="{{staticBase}}/Images/Banner/BGbanner.png" mode="aspectFill" />
|
||||
</view>
|
||||
<Parser html="{{tipsHtml}}" />
|
||||
</block>
|
||||
|
||||
<block wx:if="{{hasCourse}}">
|
||||
<view wx:for="{{ownedCourses}}" wx:for-item="item" wx:for-index="index" wx:key="courseId"
|
||||
class="kecheng" bind:tap="toMyCourse" data-code="{{item.code}}">
|
||||
<view class="kecheng_video_up">
|
||||
<image class="kecheng_img" src="{{item.coverUrl}}" mode="aspectFit" />
|
||||
</view>
|
||||
<view class="kecheng_video_right">
|
||||
<text class="kecheng_title">{{item.title}}</text>
|
||||
<text class="kecheng_details">{{item.intro}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<block wx:if="{{otherCourses.length > 0}}">
|
||||
<view wx:for="{{otherCourses}}" wx:for-item="item" wx:for-index="index" wx:key="code"
|
||||
class="kecheng" bind:tap="toStoreCourse" data-code="{{item.code}}">
|
||||
<view class="kecheng_video_up">
|
||||
<image class="kecheng_img" src="{{item.coverUrl}}" mode="aspectFit" />
|
||||
</view>
|
||||
<view class="kecheng_video_right">
|
||||
<text class="kecheng_title">{{item.title}}</text>
|
||||
<text class="kecheng_details">{{item.intro}}</text>
|
||||
</view>
|
||||
<text style="position: absolute; right: 24rpx; bottom: 24rpx; font-size: 24rpx; color: #ff6b00;">未开通</text>
|
||||
</view>
|
||||
</block>
|
||||
</scroll-view>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/* pages/kecheng/kecheng.wxss */
|
||||
.container {
|
||||
padding:0;
|
||||
align-items:center;
|
||||
flex-direction:column;
|
||||
justify-content:space-between;
|
||||
}
|
||||
.kecheng {
|
||||
width: 710rpx;
|
||||
height: 275rpx;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
justify-content: left;
|
||||
align-items: center;
|
||||
margin: 6px 0;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
|
||||
.kecheng_video_up {
|
||||
width: 400rpx;
|
||||
height: 225rpx;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
.kecheng_video_right {
|
||||
margin-left: 5rpx;
|
||||
width: 290rpx;
|
||||
height: 225rpx;
|
||||
overflow: hidden;
|
||||
|
||||
}
|
||||
.kecheng_img {
|
||||
background-color: #15457b;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 15rpx;
|
||||
}
|
||||
.kecheng_title {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.kecheng_details {
|
||||
display: block;
|
||||
font-size: 25rpx;
|
||||
margin-top: 15rpx;
|
||||
margin-left: 15rpx;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// pages/wode/wode.js
|
||||
const api = require('../../utils/api');
|
||||
const store = require('../../utils/store');
|
||||
const config = require('../../config/index');
|
||||
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
showCode: false,
|
||||
headiconUrl: '',
|
||||
isLoggedIn: false,
|
||||
userNameText: '未登录',
|
||||
loginBtnText: '登录注册',
|
||||
version: '',
|
||||
qrcodeUrl: '',
|
||||
text2: '',
|
||||
text3: '',
|
||||
text4: '',
|
||||
text5: '',
|
||||
text6: '',
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
app.ready().then(() => {
|
||||
this.applyConfig();
|
||||
this.applyUser();
|
||||
});
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (store.getSiteConfig() && Object.keys(store.getSiteConfig()).length) this.applyConfig();
|
||||
this.applyUser();
|
||||
},
|
||||
|
||||
applyConfig() {
|
||||
const qrcodeName = store.cfg('profile.qrcode_image', '');
|
||||
this.setData({
|
||||
version: store.cfg('site.version', 'V0.0.9'),
|
||||
text2: store.cfg('profile.menu.change_info', '修改资料'),
|
||||
text3: store.cfg('profile.menu.share', '好友分享'),
|
||||
text4: store.cfg('profile.menu.contact', '在线沟通'),
|
||||
text5: store.cfg('profile.menu.wechat', '添加微信:叶雷讲数学'),
|
||||
text6: store.cfg('profile.qrcode_caption', '长按识别二维码'),
|
||||
qrcodeUrl: qrcodeName ? config.STATIC_BASE_URL + '/Images/WXCode/' + qrcodeName + '.png' : '',
|
||||
});
|
||||
},
|
||||
|
||||
applyUser() {
|
||||
const user = store.getUser();
|
||||
// 已登录 = 有 token 且设置过昵称;未设置昵称的仍是游客,与旧版语义一致
|
||||
const registered = !!(user && user.nickname);
|
||||
this.setData({
|
||||
isLoggedIn: registered,
|
||||
userNameText: registered ? user.nickname : '未登录',
|
||||
loginBtnText: registered ? '退出登录' : '登录注册',
|
||||
headiconUrl: user && user.headiconUrl ? user.headiconUrl : config.STATIC_BASE_URL + config.PLACEHOLDER.USER,
|
||||
});
|
||||
},
|
||||
|
||||
toLoginOrOut() {
|
||||
wx.navigateTo({ url: '/pages/LoginOrOutDetails/LoginOrOutDetails' });
|
||||
},
|
||||
|
||||
toChangeUserInfo() {
|
||||
if (!this.data.isLoggedIn) {
|
||||
wx.showToast({ mask: true, icon: 'error', title: '请先登录' });
|
||||
return;
|
||||
}
|
||||
wx.navigateTo({ url: '/pages/ChangeUserInfo/ChangeUserInfo' });
|
||||
},
|
||||
|
||||
showQrcode() {
|
||||
this.setData({ showCode: true });
|
||||
},
|
||||
|
||||
onCodeClose() {
|
||||
this.setData({ showCode: false });
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return { title: '叶雷讲数学', path: '/pages/index/index' };
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"van-dialog": "@vant/weapp/dialog/index",
|
||||
"van-field": "@vant/weapp/field/index",
|
||||
"van-button": "@vant/weapp/button/index",
|
||||
"van-popup": "@vant/weapp/popup/index",
|
||||
"van-image": "@vant/weapp/image/index"
|
||||
},
|
||||
"navigationBarTitleText": "个人中心"
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<!--pages/wode/wode.wxml-->
|
||||
<van-popup show="{{ showCode }}" bind:close="onCodeClose">
|
||||
<view class="code-container">
|
||||
<text class="tip-text">{{text6}}</text>
|
||||
<van-image
|
||||
show-menu-by-longpress="true"
|
||||
use-loading-slot
|
||||
use-error-slot
|
||||
width="600rpx"
|
||||
height="816rpx"
|
||||
src="{{qrcodeUrl}}"
|
||||
/>
|
||||
<van-loading slot="loading" type="spinner" size="20" vertical />
|
||||
</view>
|
||||
</van-popup>
|
||||
|
||||
<scroll-view class="container" scroll-y enable-flex type="custom">
|
||||
<view class="login">
|
||||
<view class="touxiangimg">
|
||||
<image class="loginuserimg" src="{{headiconUrl}}" mode="aspectFill" />
|
||||
</view>
|
||||
|
||||
<view class="userinfo_name">
|
||||
<text>{{userNameText}}</text>
|
||||
<button class="loginbtn" bindtap="toLoginOrOut" plain>{{loginBtnText}}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button wx:if="{{isLoggedIn}}" class="functions2" bind:tap="toChangeUserInfo">
|
||||
<text class="zuobianwenzi">{{text2}}</text>
|
||||
<text class="jiantou"> > </text>
|
||||
</button>
|
||||
|
||||
<button class="functions2" open-type="share">
|
||||
<text class="zuobianwenzi">{{text3}}</text>
|
||||
<text class="jiantou"> > </text>
|
||||
</button>
|
||||
|
||||
<button class="functions2" open-type="contact">
|
||||
<text class="zuobianwenzi">{{text4}}</text>
|
||||
<text class="jiantou"> > </text>
|
||||
</button>
|
||||
|
||||
<button class="functions2" bind:tap="showQrcode">
|
||||
<text class="zuobianwenzi">{{text5}}</text>
|
||||
<text class="jiantou"> > </text>
|
||||
</button>
|
||||
|
||||
<view class="version">
|
||||
<text style="display: block;">Version {{version}}</text>
|
||||
<text style="font-size: 20rpx;display: block;">Copyright<text style="font-size: 15rpx;position: relative;top: -10rpx;right: 0rpx;">©</text> 2026 YelayMaths. All Rights Reserved.</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/* pages/wode/wode.wxss */
|
||||
.container {
|
||||
padding:0;
|
||||
align-items:center;
|
||||
flex-direction:column;
|
||||
justify-content:space-between;
|
||||
}
|
||||
.code-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center; /* 水平居中 */
|
||||
padding: 20rpx;
|
||||
box-sizing: border-box;
|
||||
background-color: rgb(0, 201, 77);
|
||||
}
|
||||
|
||||
/* 文字样式:可选加粗、颜色、间距等 */
|
||||
.tip-text {
|
||||
font-size: 34rpx;
|
||||
color: #ffffff;
|
||||
margin-bottom: 20rpx; /* 与图片保持间距 */
|
||||
text-align: center; /* 冗余保险,虽然 flex 已居中 */
|
||||
}
|
||||
|
||||
.login {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/* border: 3rpx solid rgb(110, 110, 110); */
|
||||
width: 710rpx;
|
||||
height: 150rpx;
|
||||
border-radius: 20rpx;
|
||||
margin: 20rpx;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.touxiangimg {
|
||||
display: flex;
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 50rpx;
|
||||
}
|
||||
.userinfo_name {
|
||||
width: 500rpx;
|
||||
height: 150rpx;
|
||||
margin-left: 30rpx;
|
||||
border-radius: 75rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.loginbtn {
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
.loginbtn[plain] {
|
||||
color: #353535;
|
||||
background-color: transparent;
|
||||
border: 0px solid #353535;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
padding: 0rpx 20rpx;
|
||||
}
|
||||
.loginuserimg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
.functions1 {
|
||||
border: 3rpx solid rgb(110, 110, 110);
|
||||
width: 670rpx;
|
||||
border-radius: 20rpx;
|
||||
margin: 20rpx;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
|
||||
padding: 20rpx;
|
||||
}
|
||||
.functions2 {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
/* border: 3rpx solid rgb(110, 110, 110); */
|
||||
background-color: white;
|
||||
width: 710rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 20rpx;
|
||||
margin: 8rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
.jiantou {
|
||||
font-size: 40rpx;
|
||||
}
|
||||
.zuobianwenzi {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.function001 {
|
||||
height: 150rpx;
|
||||
width: 75rpx;
|
||||
|
||||
padding: 10rpx 47rpx;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
}
|
||||
.functionimg001 {
|
||||
width: 75rpx;
|
||||
height: 75rpx;
|
||||
}
|
||||
|
||||
.functionimg002 {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
}
|
||||
.functiontext001 {
|
||||
font-size: 25rpx;
|
||||
}
|
||||
.functionstools {
|
||||
position: relative;
|
||||
top: 20rpx;
|
||||
padding-bottom: 20rpx;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
.version {
|
||||
position: fixed;
|
||||
bottom: 10rpx;
|
||||
color: rgb(197, 197, 197);
|
||||
font-size: 25rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"compileType": "miniprogram",
|
||||
"libVersion": "3.7.12",
|
||||
"packOptions": {
|
||||
"ignore": [],
|
||||
"include": []
|
||||
},
|
||||
"setting": {
|
||||
"coverView": true,
|
||||
"es6": true,
|
||||
"postcss": true,
|
||||
"minified": true,
|
||||
"enhance": true,
|
||||
"showShadowRootInWxmlPanel": true,
|
||||
"packNpmManually": true,
|
||||
"packNpmRelationList": [
|
||||
{
|
||||
"packageJsonPath": "./package.json",
|
||||
"miniprogramNpmDistDir": "./"
|
||||
}
|
||||
],
|
||||
"babelSetting": {
|
||||
"ignore": [],
|
||||
"disablePlugins": [],
|
||||
"outputPath": ""
|
||||
},
|
||||
"compileWorklet": false,
|
||||
"uglifyFileName": false,
|
||||
"uploadWithSourceMap": true,
|
||||
"minifyWXSS": true,
|
||||
"minifyWXML": true,
|
||||
"localPlugins": false,
|
||||
"disableUseStrict": false,
|
||||
"useCompilerPlugins": false,
|
||||
"condition": false,
|
||||
"swc": false,
|
||||
"disableSWC": true
|
||||
},
|
||||
"condition": {},
|
||||
"editorSetting": {
|
||||
"tabIndent": "auto",
|
||||
"tabSize": 2
|
||||
},
|
||||
"appid": "wx3fbaf897825bf04f",
|
||||
"simulatorPluginLibVersion": {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
|
||||
"rules": [{
|
||||
"action": "allow",
|
||||
"page": "*"
|
||||
}]
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* 统一请求层与接口封装。
|
||||
*
|
||||
* 替代旧版本「每个接口手写一遍 wx.request + Promise」的写法。
|
||||
* 职责:
|
||||
* - 自动附带 Authorization
|
||||
* - 统一解包 { code, message, data, requestId }
|
||||
* - token 失效自动刷新,刷新失败自动重新登录
|
||||
*/
|
||||
|
||||
const config = require('../config/index');
|
||||
const store = require('./store');
|
||||
|
||||
/** 进行中的刷新,避免并发 401 触发多次刷新 */
|
||||
let refreshing = null;
|
||||
|
||||
function staticUrl(path) {
|
||||
if (!path) return '';
|
||||
if (/^https?:\/\//i.test(path)) return path;
|
||||
return config.STATIC_BASE_URL.replace(/\/+$/, '') + '/' + String(path).replace(/^\/+/, '');
|
||||
}
|
||||
|
||||
function normalizeError(body, statusCode) {
|
||||
if (body && typeof body.code === 'number') {
|
||||
return { code: body.code, message: body.message || '请求失败', requestId: body.requestId };
|
||||
}
|
||||
return { code: -1, message: '服务异常(' + statusCode + ')' };
|
||||
}
|
||||
|
||||
/** 底层请求。不做鉴权重试,返回完整响应体。 */
|
||||
function rawRequest(options) {
|
||||
const header = { 'content-type': 'application/json' };
|
||||
if (options.auth !== false) {
|
||||
const token = store.getToken();
|
||||
if (token) header.Authorization = 'Bearer ' + token;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
url: config.API_BASE_URL.replace(/\/+$/, '') + options.url,
|
||||
method: options.method || 'GET',
|
||||
data: options.data,
|
||||
header,
|
||||
timeout: config.TIMEOUT,
|
||||
success(res) {
|
||||
resolve({ statusCode: res.statusCode, body: res.data || {} });
|
||||
},
|
||||
fail() {
|
||||
reject({ code: -1, message: '网络异常,请检查网络后重试' });
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** 带鉴权的请求。token 失效时刷新一次并重试。 */
|
||||
function request(options) {
|
||||
return rawRequest(options).then(({ statusCode, body }) => {
|
||||
if (body.code === 0) return body.data;
|
||||
|
||||
const needLogin = statusCode === 401 || body.code === 2000 || body.code === 2001;
|
||||
if (needLogin && options.auth !== false && options.retried !== true) {
|
||||
return refreshAccessToken()
|
||||
.then(() => request(Object.assign({}, options, { retried: true })))
|
||||
.catch(() => {
|
||||
store.reset();
|
||||
throw { code: 2000, message: '登录已过期,请重新进入小程序' };
|
||||
});
|
||||
}
|
||||
|
||||
throw normalizeError(body, statusCode);
|
||||
});
|
||||
}
|
||||
|
||||
function refreshAccessToken() {
|
||||
if (refreshing) return refreshing;
|
||||
const refreshToken = store.getRefreshToken();
|
||||
if (!refreshToken) return Promise.reject({ code: 2000, message: '未登录' });
|
||||
|
||||
refreshing = rawRequest({
|
||||
url: '/v1/auth/refresh',
|
||||
method: 'POST',
|
||||
data: { refreshToken },
|
||||
auth: false,
|
||||
})
|
||||
.then(({ body }) => {
|
||||
if (body.code !== 0) throw { code: 2000, message: '登录已过期' };
|
||||
store.setTokens(body.data.accessToken);
|
||||
return body.data.accessToken;
|
||||
})
|
||||
.finally(() => {
|
||||
refreshing = null;
|
||||
});
|
||||
|
||||
return refreshing;
|
||||
}
|
||||
|
||||
// ── 登录 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/** wx.login 换 code,再用 code 换服务端 token。 */
|
||||
function login() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success(res) {
|
||||
if (!res.code) {
|
||||
reject({ code: 3002, message: '微信登录失败,请重试' });
|
||||
return;
|
||||
}
|
||||
request({
|
||||
url: '/v1/auth/wx-login',
|
||||
method: 'POST',
|
||||
data: { code: res.code },
|
||||
auth: false,
|
||||
})
|
||||
.then((data) => {
|
||||
store.setTokens(data.accessToken, data.refreshToken);
|
||||
store.setUser(data.user);
|
||||
resolve(data);
|
||||
})
|
||||
.catch(reject);
|
||||
},
|
||||
fail() {
|
||||
reject({ code: 3002, message: '微信登录失败,请重试' });
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function logout() {
|
||||
return request({ url: '/v1/auth/logout', method: 'POST' }).catch(() => null).then(() => {
|
||||
store.reset();
|
||||
});
|
||||
}
|
||||
|
||||
// ── 首页内容 ──────────────────────────────────────────────────────────────
|
||||
|
||||
const api = {
|
||||
staticUrl,
|
||||
login,
|
||||
logout,
|
||||
|
||||
getConfig: () => request({ url: '/v1/config', auth: false }),
|
||||
getBanners: () => request({ url: '/v1/banners', auth: false }),
|
||||
getHomeCourses: () => request({ url: '/v1/home/courses', auth: false }),
|
||||
getHomeFreeCourses: () => request({ url: '/v1/home/free-courses', auth: false }),
|
||||
getArticles: (page, pageSize) =>
|
||||
request({ url: '/v1/articles?page=' + (page || 1) + '&pageSize=' + (pageSize || 10), auth: false }),
|
||||
getArticle: (id) => request({ url: '/v1/articles/' + id, auth: false }),
|
||||
getTips: () => request({ url: '/v1/tips', auth: false }),
|
||||
|
||||
// ── 课程 ────────────────────────────────────────────────────────────
|
||||
getCourses: () => request({ url: '/v1/courses' }),
|
||||
getCourse: (code) => request({ url: '/v1/courses/' + code }),
|
||||
getLessons: (code) => request({ url: '/v1/courses/' + code + '/lessons' }),
|
||||
getPlayUrl: (code, chapterId, playId) =>
|
||||
request({
|
||||
url:
|
||||
'/v1/courses/' +
|
||||
code +
|
||||
'/play?chapterId=' +
|
||||
encodeURIComponent(chapterId) +
|
||||
'&playId=' +
|
||||
encodeURIComponent(playId),
|
||||
}),
|
||||
getFreeLessons: (seriesNo) =>
|
||||
request({ url: '/v1/free-lessons' + (seriesNo === undefined ? '' : '?seriesNo=' + seriesNo), auth: false }),
|
||||
|
||||
// ── 用户 ────────────────────────────────────────────────────────────
|
||||
getMe: () => request({ url: '/v1/me' }),
|
||||
updateMe: (payload) => request({ url: '/v1/me', method: 'PATCH', data: payload }),
|
||||
getEntitlements: () => request({ url: '/v1/me/entitlements' }),
|
||||
|
||||
// ── 订单与支付 ──────────────────────────────────────────────────────
|
||||
createOrder: (courseCode) =>
|
||||
request({ url: '/v1/orders', method: 'POST', data: { courseCode: courseCode } }),
|
||||
getOrder: (outTradeNo) => request({ url: '/v1/orders/' + outTradeNo }),
|
||||
};
|
||||
|
||||
/**
|
||||
* 拉起虚拟支付。
|
||||
*
|
||||
* 支付成功只代表「钱付了」,权益由服务端收到发货推送后发放,
|
||||
* 因此这里不直接开通课程,而是让调用方轮询订单状态。
|
||||
*/
|
||||
function requestVirtualPayment(payData) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.requestVirtualPayment({
|
||||
signData: payData.signData,
|
||||
mode: payData.mode,
|
||||
paySig: payData.paySig,
|
||||
signature: payData.signature,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Object.assign(api, { requestVirtualPayment });
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/** 展示用格式化。 */
|
||||
|
||||
function pad(n) {
|
||||
return n < 10 ? '0' + n : String(n);
|
||||
}
|
||||
|
||||
/** ISO 字符串 → YYYY-MM-DD */
|
||||
function toDateString(value) {
|
||||
if (!value) return '';
|
||||
const d = new Date(value);
|
||||
if (isNaN(d.getTime())) return '';
|
||||
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
|
||||
}
|
||||
|
||||
/** 分 → 元(保留两位,去掉多余的 .00) */
|
||||
function fenToYuan(fen) {
|
||||
const n = Number(fen);
|
||||
if (!isFinite(n)) return '0';
|
||||
const yuan = n / 100;
|
||||
return yuan % 1 === 0 ? String(yuan) : yuan.toFixed(2);
|
||||
}
|
||||
|
||||
module.exports = { toDateString, fenToYuan };
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* 极简全局状态。
|
||||
*
|
||||
* 替代旧版本在各页面直接读写 wx.getStorageSync 的做法:
|
||||
* 统一从内存读、同步落盘,页面只与这里交互。
|
||||
*/
|
||||
|
||||
const config = require('../config/index');
|
||||
|
||||
const memory = {
|
||||
user: null,
|
||||
siteConfig: null,
|
||||
entitlements: [],
|
||||
};
|
||||
|
||||
const listeners = new Set();
|
||||
|
||||
function notify() {
|
||||
listeners.forEach((fn) => {
|
||||
try {
|
||||
fn();
|
||||
} catch (e) {
|
||||
console.error('[store] 监听器执行失败', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function read(key, fallback) {
|
||||
try {
|
||||
const v = wx.getStorageSync(key);
|
||||
return v === '' || v === undefined || v === null ? fallback : v;
|
||||
} catch (e) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
const store = {
|
||||
// ── token ────────────────────────────────────────────────────────────
|
||||
getToken: () => read(config.STORAGE.TOKEN, ''),
|
||||
getRefreshToken: () => read(config.STORAGE.REFRESH_TOKEN, ''),
|
||||
|
||||
setTokens(accessToken, refreshToken) {
|
||||
wx.setStorageSync(config.STORAGE.TOKEN, accessToken);
|
||||
if (refreshToken) wx.setStorageSync(config.STORAGE.REFRESH_TOKEN, refreshToken);
|
||||
},
|
||||
|
||||
clearTokens() {
|
||||
wx.removeStorageSync(config.STORAGE.TOKEN);
|
||||
wx.removeStorageSync(config.STORAGE.REFRESH_TOKEN);
|
||||
},
|
||||
|
||||
isLoggedIn: () => !!read(config.STORAGE.TOKEN, ''),
|
||||
|
||||
// ── 用户 ─────────────────────────────────────────────────────────────
|
||||
getUser() {
|
||||
if (memory.user) return memory.user;
|
||||
memory.user = read(config.STORAGE.USER, null);
|
||||
return memory.user;
|
||||
},
|
||||
|
||||
setUser(user) {
|
||||
memory.user = user;
|
||||
wx.setStorageSync(config.STORAGE.USER, user);
|
||||
notify();
|
||||
},
|
||||
|
||||
// ── 站点配置 ─────────────────────────────────────────────────────────
|
||||
getSiteConfig() {
|
||||
if (memory.siteConfig) return memory.siteConfig;
|
||||
memory.siteConfig = read(config.STORAGE.CONFIG, {});
|
||||
return memory.siteConfig;
|
||||
},
|
||||
|
||||
setSiteConfig(cfg) {
|
||||
memory.siteConfig = cfg || {};
|
||||
wx.setStorageSync(config.STORAGE.CONFIG, memory.siteConfig);
|
||||
notify();
|
||||
},
|
||||
|
||||
/** 取配置项,带兜底值,避免配置缺失时页面直接崩掉。 */
|
||||
cfg(key, fallback) {
|
||||
const value = store.getSiteConfig()[key];
|
||||
return value === undefined || value === '' ? (fallback === undefined ? '' : fallback) : value;
|
||||
},
|
||||
|
||||
// ── 已购课程 ─────────────────────────────────────────────────────────
|
||||
getEntitlements() {
|
||||
if (memory.entitlements && memory.entitlements.length) return memory.entitlements;
|
||||
memory.entitlements = read(config.STORAGE.ENTITLEMENTS, []) || [];
|
||||
return memory.entitlements;
|
||||
},
|
||||
|
||||
setEntitlements(list) {
|
||||
memory.entitlements = list || [];
|
||||
wx.setStorageSync(config.STORAGE.ENTITLEMENTS, memory.entitlements);
|
||||
notify();
|
||||
},
|
||||
|
||||
hasCourse(code) {
|
||||
return store.getEntitlements().some((item) => item.code === code);
|
||||
},
|
||||
|
||||
// ── 订阅与清理 ───────────────────────────────────────────────────────
|
||||
subscribe(fn) {
|
||||
listeners.add(fn);
|
||||
return () => listeners.delete(fn);
|
||||
},
|
||||
|
||||
reset() {
|
||||
memory.user = null;
|
||||
memory.siteConfig = null;
|
||||
memory.entitlements = [];
|
||||
store.clearTokens();
|
||||
wx.removeStorageSync(config.STORAGE.USER);
|
||||
wx.removeStorageSync(config.STORAGE.ENTITLEMENTS);
|
||||
notify();
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = store;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
const formatTime = timestamp => {
|
||||
const date = new Date(timestamp);
|
||||
const year = date.getFullYear()
|
||||
const month = date.getMonth() + 1
|
||||
const day = date.getDate()
|
||||
const hour = date.getHours()
|
||||
const minute = date.getMinutes()
|
||||
const second = date.getSeconds()
|
||||
|
||||
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
|
||||
}
|
||||
|
||||
const formatNumber = n => {
|
||||
n = n.toString()
|
||||
return n[1] ? n : `0${n}`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime
|
||||
}
|
||||
Reference in new issue
Block a user