// add to parents
var parent = bufArray[0] || results;
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
} else {
bufArray.unshift(node);
}
},
end: function (tag) {
//debug(tag);
// merge into parent tag
var node = bufArray.shift();
if (node.tag !== tag) console.error('invalid state: mismatch end tag');
if (bufArray.length === 0) {
results.nodes.push(node);
} else {
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
}
},
chars: function (text) {
//debug(text);
var node = {
node: 'text',
text: text,
textArray:transEmojiStr(text)
};
if (bufArray.length === 0) {
results.nodes.push(node);
} else {
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
}
},
comment: function (text) {
//debug(text);
var node = {
node: 'comment',
text: text,
};
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
parent.nodes.push(node);
},
});
return results;
};
function transEmojiStr(str){
// var eReg = new RegExp("["+__reg+' '+"]");
// str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
var emojiObjs = [];
//如果正则表达式为空
if(__emojisReg.length == 0 || !__emojis){
var emojiObj = {}
emojiObj.node = "text";
emojiObj.text = str;
array = [emojiObj];
return array;
}
//这个地方需要调整
str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
var eReg = new RegExp("[:]");
var array = str.split(eReg);
for(var i = 0; i < array.length; i++){
var ele = array[i];
var emojiObj = {};
if(__emojis[ele]){
emojiObj.node = "element";
emojiObj.tag = "emoji";
emojiObj.text = __emojis[ele];
emojiObj.baseSrc= __emojisBaseSrc;
}else{
emojiObj.node = "text";
emojiObj.text = ele;
}
emojiObjs.push(emojiObj);
}
return emojiObjs;
}
function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
__emojisReg = reg;
__emojisBaseSrc=baseSrc;
__emojis=emojis;
}
module.exports = {
html2json: html2json,
emojisInit:emojisInit
};
================================================
FILE: lib/wxParse/htmlparser.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
// Regular Expressions for parsing tags and attributes
var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
// Empty Elements - HTML 5
var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
// Block Elements - HTML 5
var block = makeMap("a,address,code,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");
// Inline Elements - HTML 5
var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");
// Elements that you can, intentionally, leave open
// (and which close themselves)
var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
// Attributes that have their values filled in disabled="disabled"
var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
// Special Elements (can contain anything)
var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
function HTMLParser(html, handler) {
var index, chars, match, stack = [], last = html;
stack.last = function () {
return this[this.length - 1];
};
while (html) {
chars = true;
// Make sure we're not in a script or style element
if (!stack.last() || !special[stack.last()]) {
// Comment
if (html.indexOf("");
if (index >= 0) {
if (handler.comment)
handler.comment(html.substring(4, index));
html = html.substring(index + 3);
chars = false;
}
// end tag
} else if (html.indexOf("") == 0) {
match = html.match(endTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(endTag, parseEndTag);
chars = false;
}
// start tag
} else if (html.indexOf("<") == 0) {
match = html.match(startTag);
if (match) {
html = html.substring(match[0].length);
match[0].replace(startTag, parseStartTag);
chars = false;
}
}
if (chars) {
index = html.indexOf("<");
var text = index < 0 ? html : html.substring(0, index);
html = index < 0 ? "" : html.substring(index);
if (handler.chars)
handler.chars(text);
}
} else {
html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
text = text.replace(/|/g, "$1$2");
if (handler.chars)
handler.chars(text);
return "";
});
parseEndTag("", stack.last());
}
if (html == last)
throw "Parse Error: " + html;
last = html;
}
// Clean up any remaining tags
parseEndTag();
function parseStartTag(tag, tagName, rest, unary) {
tagName = tagName.toLowerCase();
if (block[tagName]) {
while (stack.last() && inline[stack.last()]) {
parseEndTag("", stack.last());
}
}
if (closeSelf[tagName] && stack.last() == tagName) {
parseEndTag("", tagName);
}
unary = empty[tagName] || !!unary;
if (!unary)
stack.push(tagName);
if (handler.start) {
var attrs = [];
rest.replace(attr, function (match, name) {
var value = arguments[2] ? arguments[2] :
arguments[3] ? arguments[3] :
arguments[4] ? arguments[4] :
fillAttrs[name] ? name : "";
attrs.push({
name: name,
value: value,
escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
});
});
if (handler.start) {
handler.start(tagName, attrs, unary);
}
}
}
function parseEndTag(tag, tagName) {
// If no tag name is provided, clean shop
if (!tagName)
var pos = 0;
// Find the closest opened tag of the same type
else
for (var pos = stack.length - 1; pos >= 0; pos--)
if (stack[pos] == tagName)
break;
if (pos >= 0) {
// Close all the open elements, up the stack
for (var i = stack.length - 1; i >= pos; i--)
if (handler.end)
handler.end(stack[i]);
// Remove the open elements from the stack
stack.length = pos;
}
}
};
function makeMap(str) {
var obj = {}, items = str.split(",");
for (var i = 0; i < items.length; i++)
obj[items[i]] = true;
return obj;
}
module.exports = HTMLParser;
================================================
FILE: lib/wxParse/showdown.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
function getDefaultOpts(simple) {
'use strict';
var defaultOptions = {
omitExtraWLInCodeBlocks: {
defaultValue: false,
describe: 'Omit the default extra whiteline added to code blocks',
type: 'boolean'
},
noHeaderId: {
defaultValue: false,
describe: 'Turn on/off generated header id',
type: 'boolean'
},
prefixHeaderId: {
defaultValue: false,
describe: 'Specify a prefix to generated header ids',
type: 'string'
},
headerLevelStart: {
defaultValue: false,
describe: 'The header blocks level start',
type: 'integer'
},
parseImgDimensions: {
defaultValue: false,
describe: 'Turn on/off image dimension parsing',
type: 'boolean'
},
simplifiedAutoLink: {
defaultValue: false,
describe: 'Turn on/off GFM autolink style',
type: 'boolean'
},
literalMidWordUnderscores: {
defaultValue: false,
describe: 'Parse midword underscores as literal underscores',
type: 'boolean'
},
strikethrough: {
defaultValue: false,
describe: 'Turn on/off strikethrough support',
type: 'boolean'
},
tables: {
defaultValue: false,
describe: 'Turn on/off tables support',
type: 'boolean'
},
tablesHeaderId: {
defaultValue: false,
describe: 'Add an id to table headers',
type: 'boolean'
},
ghCodeBlocks: {
defaultValue: true,
describe: 'Turn on/off GFM fenced code blocks support',
type: 'boolean'
},
tasklists: {
defaultValue: false,
describe: 'Turn on/off GFM tasklist support',
type: 'boolean'
},
smoothLivePreview: {
defaultValue: false,
describe: 'Prevents weird effects in live previews due to incomplete input',
type: 'boolean'
},
smartIndentationFix: {
defaultValue: false,
description: 'Tries to smartly fix identation in es6 strings',
type: 'boolean'
}
};
if (simple === false) {
return JSON.parse(JSON.stringify(defaultOptions));
}
var ret = {};
for (var opt in defaultOptions) {
if (defaultOptions.hasOwnProperty(opt)) {
ret[opt] = defaultOptions[opt].defaultValue;
}
}
return ret;
}
/**
* Created by Tivie on 06-01-2015.
*/
// Private properties
var showdown = {},
parsers = {},
extensions = {},
globalOptions = getDefaultOpts(true),
flavor = {
github: {
omitExtraWLInCodeBlocks: true,
prefixHeaderId: 'user-content-',
simplifiedAutoLink: true,
literalMidWordUnderscores: true,
strikethrough: true,
tables: true,
tablesHeaderId: true,
ghCodeBlocks: true,
tasklists: true
},
vanilla: getDefaultOpts(true)
};
/**
* helper namespace
* @type {{}}
*/
showdown.helper = {};
/**
* TODO LEGACY SUPPORT CODE
* @type {{}}
*/
showdown.extensions = {};
/**
* Set a global option
* @static
* @param {string} key
* @param {*} value
* @returns {showdown}
*/
showdown.setOption = function (key, value) {
'use strict';
globalOptions[key] = value;
return this;
};
/**
* Get a global option
* @static
* @param {string} key
* @returns {*}
*/
showdown.getOption = function (key) {
'use strict';
return globalOptions[key];
};
/**
* Get the global options
* @static
* @returns {{}}
*/
showdown.getOptions = function () {
'use strict';
return globalOptions;
};
/**
* Reset global options to the default values
* @static
*/
showdown.resetOptions = function () {
'use strict';
globalOptions = getDefaultOpts(true);
};
/**
* Set the flavor showdown should use as default
* @param {string} name
*/
showdown.setFlavor = function (name) {
'use strict';
if (flavor.hasOwnProperty(name)) {
var preset = flavor[name];
for (var option in preset) {
if (preset.hasOwnProperty(option)) {
globalOptions[option] = preset[option];
}
}
}
};
/**
* Get the default options
* @static
* @param {boolean} [simple=true]
* @returns {{}}
*/
showdown.getDefaultOptions = function (simple) {
'use strict';
return getDefaultOpts(simple);
};
/**
* Get or set a subParser
*
* subParser(name) - Get a registered subParser
* subParser(name, func) - Register a subParser
* @static
* @param {string} name
* @param {function} [func]
* @returns {*}
*/
showdown.subParser = function (name, func) {
'use strict';
if (showdown.helper.isString(name)) {
if (typeof func !== 'undefined') {
parsers[name] = func;
} else {
if (parsers.hasOwnProperty(name)) {
return parsers[name];
} else {
throw Error('SubParser named ' + name + ' not registered!');
}
}
}
};
/**
* Gets or registers an extension
* @static
* @param {string} name
* @param {object|function=} ext
* @returns {*}
*/
showdown.extension = function (name, ext) {
'use strict';
if (!showdown.helper.isString(name)) {
throw Error('Extension \'name\' must be a string');
}
name = showdown.helper.stdExtName(name);
// Getter
if (showdown.helper.isUndefined(ext)) {
if (!extensions.hasOwnProperty(name)) {
throw Error('Extension named ' + name + ' is not registered!');
}
return extensions[name];
// Setter
} else {
// Expand extension if it's wrapped in a function
if (typeof ext === 'function') {
ext = ext();
}
// Ensure extension is an array
if (!showdown.helper.isArray(ext)) {
ext = [ext];
}
var validExtension = validate(ext, name);
if (validExtension.valid) {
extensions[name] = ext;
} else {
throw Error(validExtension.error);
}
}
};
/**
* Gets all extensions registered
* @returns {{}}
*/
showdown.getAllExtensions = function () {
'use strict';
return extensions;
};
/**
* Remove an extension
* @param {string} name
*/
showdown.removeExtension = function (name) {
'use strict';
delete extensions[name];
};
/**
* Removes all extensions
*/
showdown.resetExtensions = function () {
'use strict';
extensions = {};
};
/**
* Validate extension
* @param {array} extension
* @param {string} name
* @returns {{valid: boolean, error: string}}
*/
function validate(extension, name) {
'use strict';
var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
ret = {
valid: true,
error: ''
};
if (!showdown.helper.isArray(extension)) {
extension = [extension];
}
for (var i = 0; i < extension.length; ++i) {
var baseMsg = errMsg + ' sub-extension ' + i + ': ',
ext = extension[i];
if (typeof ext !== 'object') {
ret.valid = false;
ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given';
return ret;
}
if (!showdown.helper.isString(ext.type)) {
ret.valid = false;
ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given';
return ret;
}
var type = ext.type = ext.type.toLowerCase();
// normalize extension type
if (type === 'language') {
type = ext.type = 'lang';
}
if (type === 'html') {
type = ext.type = 'output';
}
if (type !== 'lang' && type !== 'output' && type !== 'listener') {
ret.valid = false;
ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang/language", "output/html" or "listener"';
return ret;
}
if (type === 'listener') {
if (showdown.helper.isUndefined(ext.listeners)) {
ret.valid = false;
ret.error = baseMsg + '. Extensions of type "listener" must have a property called "listeners"';
return ret;
}
} else {
if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) {
ret.valid = false;
ret.error = baseMsg + type + ' extensions must define either a "regex" property or a "filter" method';
return ret;
}
}
if (ext.listeners) {
if (typeof ext.listeners !== 'object') {
ret.valid = false;
ret.error = baseMsg + '"listeners" property must be an object but ' + typeof ext.listeners + ' given';
return ret;
}
for (var ln in ext.listeners) {
if (ext.listeners.hasOwnProperty(ln)) {
if (typeof ext.listeners[ln] !== 'function') {
ret.valid = false;
ret.error = baseMsg + '"listeners" property must be an hash of [event name]: [callback]. listeners.' + ln +
' must be a function but ' + typeof ext.listeners[ln] + ' given';
return ret;
}
}
}
}
if (ext.filter) {
if (typeof ext.filter !== 'function') {
ret.valid = false;
ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given';
return ret;
}
} else if (ext.regex) {
if (showdown.helper.isString(ext.regex)) {
ext.regex = new RegExp(ext.regex, 'g');
}
if (!ext.regex instanceof RegExp) {
ret.valid = false;
ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
return ret;
}
if (showdown.helper.isUndefined(ext.replace)) {
ret.valid = false;
ret.error = baseMsg + '"regex" extensions must implement a replace string or function';
return ret;
}
}
}
return ret;
}
/**
* Validate extension
* @param {object} ext
* @returns {boolean}
*/
showdown.validateExtension = function (ext) {
'use strict';
var validateExtension = validate(ext, null);
if (!validateExtension.valid) {
console.warn(validateExtension.error);
return false;
}
return true;
};
/**
* showdownjs helper functions
*/
if (!showdown.hasOwnProperty('helper')) {
showdown.helper = {};
}
/**
* Check if var is string
* @static
* @param {string} a
* @returns {boolean}
*/
showdown.helper.isString = function isString(a) {
'use strict';
return (typeof a === 'string' || a instanceof String);
};
/**
* Check if var is a function
* @static
* @param {string} a
* @returns {boolean}
*/
showdown.helper.isFunction = function isFunction(a) {
'use strict';
var getType = {};
return a && getType.toString.call(a) === '[object Function]';
};
/**
* ForEach helper function
* @static
* @param {*} obj
* @param {function} callback
*/
showdown.helper.forEach = function forEach(obj, callback) {
'use strict';
if (typeof obj.forEach === 'function') {
obj.forEach(callback);
} else {
for (var i = 0; i < obj.length; i++) {
callback(obj[i], i, obj);
}
}
};
/**
* isArray helper function
* @static
* @param {*} a
* @returns {boolean}
*/
showdown.helper.isArray = function isArray(a) {
'use strict';
return a.constructor === Array;
};
/**
* Check if value is undefined
* @static
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
*/
showdown.helper.isUndefined = function isUndefined(value) {
'use strict';
return typeof value === 'undefined';
};
/**
* Standardidize extension name
* @static
* @param {string} s extension name
* @returns {string}
*/
showdown.helper.stdExtName = function (s) {
'use strict';
return s.replace(/[_-]||\s/g, '').toLowerCase();
};
function escapeCharactersCallback(wholeMatch, m1) {
'use strict';
var charCodeToEscape = m1.charCodeAt(0);
return '~E' + charCodeToEscape + 'E';
}
/**
* Callback used to escape characters when passing through String.replace
* @static
* @param {string} wholeMatch
* @param {string} m1
* @returns {string}
*/
showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
/**
* Escape characters in a string
* @static
* @param {string} text
* @param {string} charsToEscape
* @param {boolean} afterBackslash
* @returns {XML|string|void|*}
*/
showdown.helper.escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) {
'use strict';
// First we have to escape the escape characters so that
// we can build a character class out of them
var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
if (afterBackslash) {
regexString = '\\\\' + regexString;
}
var regex = new RegExp(regexString, 'g');
text = text.replace(regex, escapeCharactersCallback);
return text;
};
var rgxFindMatchPos = function (str, left, right, flags) {
'use strict';
var f = flags || '',
g = f.indexOf('g') > -1,
x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
l = new RegExp(left, f.replace(/g/g, '')),
pos = [],
t, s, m, start, end;
do {
t = 0;
while ((m = x.exec(str))) {
if (l.test(m[0])) {
if (!(t++)) {
s = x.lastIndex;
start = s - m[0].length;
}
} else if (t) {
if (!--t) {
end = m.index + m[0].length;
var obj = {
left: {start: start, end: s},
match: {start: s, end: m.index},
right: {start: m.index, end: end},
wholeMatch: {start: start, end: end}
};
pos.push(obj);
if (!g) {
return pos;
}
}
}
}
} while (t && (x.lastIndex = s));
return pos;
};
/**
* matchRecursiveRegExp
*
* (c) 2007 Steven Levithan tags around block-level tags. text = showdown.subParser('hashHTMLBlocks')(text, options, globals); text = showdown.subParser('paragraphs')(text, options, globals); text = globals.converter._dispatch('blockGamut.after', text, options, globals); return text; }); showdown.subParser('blockQuotes', function (text, options, globals) { 'use strict'; text = globals.converter._dispatch('blockQuotes.before', text, options, globals); /* text = text.replace(/ ( // Wrap whole match in $1 ( ^[ \t]*>[ \t]? // '>' at the start of a line .+\n // rest of the first line (.+\n)* // subsequent consecutive lines \n* // blanks )+ ) /gm, function(){...}); */ text = text.replace(/((^[ \t]{0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) { var bq = m1; // attacklab: hack around Konqueror 3.5.4 bug: // "----------bug".replace(/^-/g,"") == "bug" bq = bq.replace(/^[ \t]*>[ \t]?/gm, '~0'); // trim one level of quoting // attacklab: clean up hack bq = bq.replace(/~0/g, ''); bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines bq = showdown.subParser('githubCodeBlocks')(bq, options, globals); bq = showdown.subParser('blockGamut')(bq, options, globals); // recurse bq = bq.replace(/(^|\n)/g, '$1 '); // These leading spaces screw with
content, so we need to fix that:
bq = bq.replace(/(\s*[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
var pre = m1;
// attacklab: hack around Konqueror 3.5.4 bug:
pre = pre.replace(/^ /mg, '~0');
pre = pre.replace(/~0/g, '');
return pre;
});
return showdown.subParser('hashBlock')('\n' + bq + '\n
', options, globals);
});
text = globals.converter._dispatch('blockQuotes.after', text, options, globals);
return text;
});
/**
* Process Markdown `` blocks.
*/
showdown.subParser('codeBlocks', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('codeBlocks.before', text, options, globals);
/*
text = text.replace(text,
/(?:\n\n|^)
( // $1 = the code block -- one or more lines, starting with a space/tab
(?:
(?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
.*\n+
)+
)
(\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
/g,function(){...});
*/
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '~0';
var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
text = text.replace(pattern, function (wholeMatch, m1, m2) {
var codeblock = m1,
nextChar = m2,
end = '\n';
codeblock = showdown.subParser('outdent')(codeblock);
codeblock = showdown.subParser('encodeCode')(codeblock);
codeblock = showdown.subParser('detab')(codeblock);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
if (options.omitExtraWLInCodeBlocks) {
end = '';
}
codeblock = '' + codeblock + end + '
';
return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
});
// attacklab: strip sentinel
text = text.replace(/~0/, '');
text = globals.converter._dispatch('codeBlocks.after', text, options, globals);
return text;
});
/**
*
* * Backtick quotes are used for spans.
*
* * You can use multiple backticks as the delimiters if you want to
* include literal backticks in the code span. So, this input:
*
* Just type ``foo `bar` baz`` at the prompt.
*
* Will translate to:
*
* Just type foo `bar` baz at the prompt.
*
* There's no arbitrary limit to the number of backticks you
* can use as delimters. If you need three consecutive backticks
* in your code, use four for delimiters, etc.
*
* * You can use spaces to get literal backticks at the edges:
*
* ... type `` `bar` `` ...
*
* Turns to:
*
* ... type `bar` ...
*/
showdown.subParser('codeSpans', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('codeSpans.before', text, options, globals);
/*
text = text.replace(/
(^|[^\\]) // Character before opening ` can't be a backslash
(`+) // $2 = Opening run of `
( // $3 = The code block
[^\r]*?
[^`] // attacklab: work around lack of lookbehind
)
\2 // Matching closer
(?!`)
/gm, function(){...});
*/
if (typeof(text) === 'undefined') {
text = '';
}
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
function (wholeMatch, m1, m2, m3) {
var c = m3;
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
c = showdown.subParser('encodeCode')(c);
return m1 + '' + c + '';
}
);
text = globals.converter._dispatch('codeSpans.after', text, options, globals);
return text;
});
/**
* Convert all tabs to spaces
*/
showdown.subParser('detab', function (text) {
'use strict';
// expand first n-1 tabs
text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
// replace the nth with two sentinels
text = text.replace(/\t/g, '~A~B');
// use the sentinel to anchor our regex so it doesn't explode
text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) {
var leadingText = m1,
numSpaces = 4 - leadingText.length % 4; // g_tab_width
// there *must* be a better way to do this:
for (var i = 0; i < numSpaces; i++) {
leadingText += ' ';
}
return leadingText;
});
// clean up sentinels
text = text.replace(/~A/g, ' '); // g_tab_width
text = text.replace(/~B/g, '');
return text;
});
/**
* Smart processing for ampersands and angle brackets that need to be encoded.
*/
showdown.subParser('encodeAmpsAndAngles', function (text) {
'use strict';
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
// http://bumppo.net/projects/amputator/
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&');
// Encode naked <'s
text = text.replace(/<(?![a-z\/?\$!])/gi, '<');
return text;
});
/**
* Returns the string, with after processing the following backslash escape sequences.
*
* attacklab: The polite way to do this is with the new escapeCharacters() function:
*
* text = escapeCharacters(text,"\\",true);
* text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
*
* ...but we're sidestepping its use of the (slow) RegExp constructor
* as an optimization for Firefox. This function gets called a LOT.
*/
showdown.subParser('encodeBackslashEscapes', function (text) {
'use strict';
text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, showdown.helper.escapeCharactersCallback);
return text;
});
/**
* Encode/escape certain characters inside Markdown code runs.
* The point is that in code, these characters are literals,
* and lose their special Markdown meanings.
*/
showdown.subParser('encodeCode', function (text) {
'use strict';
// Encode all ampersands; HTML entities are not
// entities within a Markdown code span.
text = text.replace(/&/g, '&');
// Do the angle bracket song and dance:
text = text.replace(//g, '>');
// Now, escape characters that are magic in Markdown:
text = showdown.helper.escapeCharacters(text, '*_{}[]\\', false);
// jj the line above breaks this:
//---
//* Item
// 1. Subitem
// special char: *
// ---
return text;
});
/**
* Input: an email address, e.g. "foo@example.com"
*
* Output: the email address as a mailto link, with each character
* of the address encoded as either a decimal or hex entity, in
* the hopes of foiling most address harvesting spam bots. E.g.:
*
* foo
* @example.com
*
* Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
* mailing list:
*
*/
showdown.subParser('encodeEmailAddress', function (addr) {
'use strict';
var encode = [
function (ch) {
return '' + ch.charCodeAt(0) + ';';
},
function (ch) {
return '' + ch.charCodeAt(0).toString(16) + ';';
},
function (ch) {
return ch;
}
];
addr = 'mailto:' + addr;
addr = addr.replace(/./g, function (ch) {
if (ch === '@') {
// this *must* be encoded. I insist.
ch = encode[Math.floor(Math.random() * 2)](ch);
} else if (ch !== ':') {
// leave ':' alone (to spot mailto: later)
var r = Math.random();
// roughly 10% raw, 45% hex, 45% dec
ch = (
r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
);
}
return ch;
});
addr = '' + addr + '';
addr = addr.replace(/">.+:/g, '">'); // strip the mailto: from the visible part
return addr;
});
/**
* Within tags -- meaning between < and > -- encode [\ ` * _] so they
* don't conflict with their use in Markdown for code, italics and strong.
*/
showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text) {
'use strict';
// Build a regex to find HTML tags and comments. See Friedl's
// "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|)/gi;
text = text.replace(regex, function (wholeMatch) {
var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, '$1`');
tag = showdown.helper.escapeCharacters(tag, '\\`*_', false);
return tag;
});
return text;
});
/**
* Handle github codeblocks prior to running HashHTML so that
* HTML contained within the codeblock gets escaped properly
* Example:
* ```ruby
* def hello_world(x)
* puts "Hello, #{x}"
* end
* ```
*/
showdown.subParser('githubCodeBlocks', function (text, options, globals) {
'use strict';
// early exit if option is not enabled
if (!options.ghCodeBlocks) {
return text;
}
text = globals.converter._dispatch('githubCodeBlocks.before', text, options, globals);
text += '~0';
text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, language, codeblock) {
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
// First parse the github code block
codeblock = showdown.subParser('encodeCode')(codeblock);
codeblock = showdown.subParser('detab')(codeblock);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
codeblock = '' + codeblock + end + '
';
codeblock = showdown.subParser('hashBlock')(codeblock, options, globals);
// Since GHCodeblocks can be false positives, we need to
// store the primitive text and the parsed text in a global var,
// and then return a token
return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
});
// attacklab: strip sentinel
text = text.replace(/~0/, '');
return globals.converter._dispatch('githubCodeBlocks.after', text, options, globals);
});
showdown.subParser('hashBlock', function (text, options, globals) {
'use strict';
text = text.replace(/(^\n+|\n+$)/g, '');
return '\n\n~K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
});
showdown.subParser('hashElement', function (text, options, globals) {
'use strict';
return function (wholeMatch, m1) {
var blockText = m1;
// Undo double lines
blockText = blockText.replace(/\n\n/g, '\n');
blockText = blockText.replace(/^\n/, '');
// strip trailing blank lines
blockText = blockText.replace(/\n+$/g, '');
// Replace the element text with a marker ("~KxK" where x is its key)
blockText = '\n\n~K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
return blockText;
};
});
showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
'use strict';
var blockTags = [
'pre',
'div',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'blockquote',
'table',
'dl',
'ol',
'ul',
'script',
'noscript',
'form',
'fieldset',
'iframe',
'math',
'style',
'section',
'header',
'footer',
'nav',
'article',
'aside',
'address',
'audio',
'canvas',
'figure',
'hgroup',
'output',
'video',
'p'
],
repFunc = function (wholeMatch, match, left, right) {
var txt = wholeMatch;
// check if this html element is marked as markdown
// if so, it's contents should be parsed as markdown
if (left.search(/\bmarkdown\b/) !== -1) {
txt = left + globals.converter.makeHtml(match) + right;
}
return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
};
for (var i = 0; i < blockTags.length; ++i) {
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}<' + blockTags[i] + '\\b[^>]*>', '' + blockTags[i] + '>', 'gim');
}
// HR SPECIAL CASE
text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
showdown.subParser('hashElement')(text, options, globals));
// Special case for standalone HTML comments:
text = text.replace(/()/g,
showdown.subParser('hashElement')(text, options, globals));
// PHP and ASP-style processor instructions (...?> and <%...%>)
text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
showdown.subParser('hashElement')(text, options, globals));
return text;
});
/**
* Hash span elements that should not be parsed as markdown
*/
showdown.subParser('hashHTMLSpans', function (text, config, globals) {
'use strict';
var matches = showdown.helper.matchRecursiveRegExp(text, ']*>', '', 'gi');
for (var i = 0; i < matches.length; ++i) {
text = text.replace(matches[i][0], '~L' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'L');
}
return text;
});
/**
* Unhash HTML spans
*/
showdown.subParser('unhashHTMLSpans', function (text, config, globals) {
'use strict';
for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
text = text.replace('~L' + i + 'L', globals.gHtmlSpans[i]);
}
return text;
});
/**
* Hash span elements that should not be parsed as markdown
*/
showdown.subParser('hashPreCodeTags', function (text, config, globals) {
'use strict';
var repFunc = function (wholeMatch, match, left, right) {
// encode html entities
var codeblock = left + showdown.subParser('encodeCode')(match) + right;
return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
};
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}]*>\\s*]*>', '^(?: |\\t){0,3}\\s*
', 'gim');
return text;
});
showdown.subParser('headers', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('headers.before', text, options, globals);
var prefixHeader = options.prefixHeaderId,
headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
// Set text-style headers:
// Header 1
// ========
//
// Header 2
// --------
//
setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
text = text.replace(setextRegexH1, function (wholeMatch, m1) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart,
hashBlock = '' + spanGamut + ' ';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});
text = text.replace(setextRegexH2, function (matchFound, m1) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart + 1,
hashBlock = '' + spanGamut + ' ';
return showdown.subParser('hashBlock')(hashBlock, options, globals);
});
// atx-style headers:
// # Header 1
// ## Header 2
// ## Header 2 with closing hashes ##
// ...
// ###### Header 6
//
text = text.replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm, function (wholeMatch, m1, m2) {
var span = showdown.subParser('spanGamut')(m2, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
hLevel = headerLevelStart - 1 + m1.length,
header = '' + span + ' ';
return showdown.subParser('hashBlock')(header, options, globals);
});
function headerId(m) {
var title, escapedId = m.replace(/[^\w]/g, '').toLowerCase();
if (globals.hashLinkCounts[escapedId]) {
title = escapedId + '-' + (globals.hashLinkCounts[escapedId]++);
} else {
title = escapedId;
globals.hashLinkCounts[escapedId] = 1;
}
// Prefix id to prevent causing inadvertent pre-existing style matches.
if (prefixHeader === true) {
prefixHeader = 'section';
}
if (showdown.helper.isString(prefixHeader)) {
return prefixHeader + title;
}
return title;
}
text = globals.converter._dispatch('headers.after', text, options, globals);
return text;
});
/**
* Turn Markdown image shortcuts into
tags.
*/
showdown.subParser('images', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('images.before', text, options, globals);
var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
var gUrls = globals.gUrls,
gTitles = globals.gTitles,
gDims = globals.gDimensions;
linkId = linkId.toLowerCase();
if (!title) {
title = '';
}
if (url === '' || url === null) {
if (linkId === '' || linkId === null) {
// lower-case and turn embedded newlines into spaces
linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
}
url = '#' + linkId;
if (!showdown.helper.isUndefined(gUrls[linkId])) {
url = gUrls[linkId];
if (!showdown.helper.isUndefined(gTitles[linkId])) {
title = gTitles[linkId];
}
if (!showdown.helper.isUndefined(gDims[linkId])) {
width = gDims[linkId].width;
height = gDims[linkId].height;
}
} else {
return wholeMatch;
}
}
altText = altText.replace(/"/g, '"');
altText = showdown.helper.escapeCharacters(altText, '*_', false);
url = showdown.helper.escapeCharacters(url, '*_', false);
var result = '
';
return result;
}
// First, handle reference-style labeled images: ![alt text][id]
text = text.replace(referenceRegExp, writeImageTag);
// Next, handle inline images: 
text = text.replace(inlineRegExp, writeImageTag);
text = globals.converter._dispatch('images.after', text, options, globals);
return text;
});
showdown.subParser('italicsAndBold', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('italicsAndBold.before', text, options, globals);
if (options.literalMidWordUnderscores) {
//underscores
// Since we are consuming a \s character, we need to add it
text = text.replace(/(^|\s|>|\b)__(?=\S)([\s\S]+?)__(?=\b|<|\s|$)/gm, '$1$2');
text = text.replace(/(^|\s|>|\b)_(?=\S)([\s\S]+?)_(?=\b|<|\s|$)/gm, '$1$2');
//asterisks
text = text.replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g, '$2');
text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '$2');
} else {
// must go first:
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '$2');
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '$2');
}
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals);
return text;
});
/**
* Form HTML ordered (numbered) and unordered (bulleted) lists.
*/
showdown.subParser('lists', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('lists.before', text, options, globals);
/**
* Process the contents of a single ordered or unordered list, splitting it
* into individual list items.
* @param {string} listStr
* @param {boolean} trimTrailing
* @returns {string}
*/
function processListItems (listStr, trimTrailing) {
// The $g_list_level global keeps track of when we're inside a list.
// Each time we enter a list, we increment it; when we leave a list,
// we decrement. If it's zero, we're not in a list anymore.
//
// We do this because when we're not inside a list, we want to treat
// something like this:
//
// I recommend upgrading to version
// 8. Oops, now this line is treated
// as a sub-list.
//
// As a single paragraph, despite the fact that the second line starts
// with a digit-period-space sequence.
//
// Whereas when we're inside a list (or sub-list), that line will be
// treated as the start of a sub-list. What a kludge, huh? This is
// an aspect of Markdown's syntax that's hard to parse perfectly
// without resorting to mind-reading. Perhaps the solution is to
// change the syntax rules such that sub-lists must start with a
// starting cardinal number; e.g. "1." or "a.".
globals.gListLevel++;
// trim trailing blank lines:
listStr = listStr.replace(/\n{2,}$/, '\n');
// attacklab: add sentinel to emulate \z
listStr += '~0';
var rgx = /(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
isParagraphed = (/\n[ \t]*\n(?!~0)/.test(listStr));
listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
checked = (checked && checked.trim() !== '');
var item = showdown.subParser('outdent')(m4, options, globals),
bulletStyle = '';
// Support for github tasklists
if (taskbtn && options.tasklists) {
bulletStyle = ' class="task-list-item" style="list-style-type: none;"';
item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
var otp = '';
return otp;
});
}
// m1 - Leading line or
// Has a double return (multi paragraph) or
// Has sublist
if (m1 || (item.search(/\n{2,}/) > -1)) {
item = showdown.subParser('githubCodeBlocks')(item, options, globals);
item = showdown.subParser('blockGamut')(item, options, globals);
} else {
// Recursion for sub-lists:
item = showdown.subParser('lists')(item, options, globals);
item = item.replace(/\n$/, ''); // chomp(item)
if (isParagraphed) {
item = showdown.subParser('paragraphs')(item, options, globals);
} else {
item = showdown.subParser('spanGamut')(item, options, globals);
}
}
item = '\n' + item + ' \n';
return item;
});
// attacklab: strip sentinel
listStr = listStr.replace(/~0/g, '');
globals.gListLevel--;
if (trimTrailing) {
listStr = listStr.replace(/\s+$/, '');
}
return listStr;
}
/**
* Check and parse consecutive lists (better fix for issue #142)
* @param {string} list
* @param {string} listType
* @param {boolean} trimTrailing
* @returns {string}
*/
function parseConsecutiveLists(list, listType, trimTrailing) {
// check if we caught 2 or more consecutive lists by mistake
// we use the counterRgx, meaning if listType is UL we look for UL and vice versa
var counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm,
subLists = [],
result = '';
if (list.search(counterRxg) !== -1) {
(function parseCL(txt) {
var pos = txt.search(counterRxg);
if (pos !== -1) {
// slice
result += '\n\n<' + listType + '>' + processListItems(txt.slice(0, pos), !!trimTrailing) + '' + listType + '>\n\n';
// invert counterType and listType
listType = (listType === 'ul') ? 'ol' : 'ul';
counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm;
//recurse
parseCL(txt.slice(pos));
} else {
result += '\n\n<' + listType + '>' + processListItems(txt, !!trimTrailing) + '' + listType + '>\n\n';
}
})(list);
for (var i = 0; i < subLists.length; ++i) {
}
} else {
result = '\n\n<' + listType + '>' + processListItems(list, !!trimTrailing) + '' + listType + '>\n\n';
}
return result;
}
// attacklab: add sentinel to hack around khtml/safari bug:
// http://bugs.webkit.org/show_bug.cgi?id=11231
text += '~0';
// Re-usable pattern to match any entire ul or ol list:
var wholeList = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
if (globals.gListLevel) {
text = text.replace(wholeList, function (wholeMatch, list, m2) {
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
return parseConsecutiveLists(list, listType, true);
});
} else {
wholeList = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
//wholeList = /(\n\n|^\n?)( {0,3}([*+-]|\d+\.)[ \t]+[\s\S]+?)(?=(~0)|(\n\n(?!\t| {2,}| {0,3}([*+-]|\d+\.)[ \t])))/g;
text = text.replace(wholeList, function (wholeMatch, m1, list, m3) {
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
return parseConsecutiveLists(list, listType);
});
}
// attacklab: strip sentinel
text = text.replace(/~0/, '');
text = globals.converter._dispatch('lists.after', text, options, globals);
return text;
});
/**
* Remove one level of line-leading tabs or spaces
*/
showdown.subParser('outdent', function (text) {
'use strict';
// attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug"
text = text.replace(/^(\t|[ ]{1,4})/gm, '~0'); // attacklab: g_tab_width
// attacklab: clean up hack
text = text.replace(/~0/g, '');
return text;
});
/**
*
*/
showdown.subParser('paragraphs', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('paragraphs.before', text, options, globals);
// Strip leading and trailing lines:
text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, '');
var grafs = text.split(/\n{2,}/g),
grafsOut = [],
end = grafs.length; // Wrap tags
for (var i = 0; i < end; i++) {
var str = grafs[i];
// if this is an HTML marker, copy it
if (str.search(/~(K|G)(\d+)\1/g) >= 0) {
grafsOut.push(str);
} else {
str = showdown.subParser('spanGamut')(str, options, globals);
str = str.replace(/^([ \t]*)/g, '
');
str += '
';
grafsOut.push(str);
}
}
/** Unhashify HTML blocks */
end = grafsOut.length;
for (i = 0; i < end; i++) {
var blockText = '',
grafsOutIt = grafsOut[i],
codeFlag = false;
// if this is a marker for an html block...
while (grafsOutIt.search(/~(K|G)(\d+)\1/) >= 0) {
var delim = RegExp.$1,
num = RegExp.$2;
if (delim === 'K') {
blockText = globals.gHtmlBlocks[num];
} else {
// we need to check if ghBlock is a false positive
if (codeFlag) {
// use encoded version of all text
blockText = showdown.subParser('encodeCode')(globals.ghCodeBlocks[num].text);
} else {
blockText = globals.ghCodeBlocks[num].codeblock;
}
}
blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
grafsOutIt = grafsOutIt.replace(/(\n\n)?~(K|G)\d+\2(\n\n)?/, blockText);
// Check if grafsOutIt is a pre->code
if (/^]*>\s*]*>/.test(grafsOutIt)) {
codeFlag = true;
}
}
grafsOut[i] = grafsOutIt;
}
text = grafsOut.join('\n\n');
// Strip leading and trailing lines:
text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, '');
return globals.converter._dispatch('paragraphs.after', text, options, globals);
});
/**
* Run extension
*/
showdown.subParser('runExtension', function (ext, text, options, globals) {
'use strict';
if (ext.filter) {
text = ext.filter(text, globals.converter, options);
} else if (ext.regex) {
// TODO remove this when old extension loading mechanism is deprecated
var re = ext.regex;
if (!re instanceof RegExp) {
re = new RegExp(re, 'g');
}
text = text.replace(re, ext.replace);
}
return text;
});
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('spanGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('spanGamut.before', text, options, globals);
text = showdown.subParser('codeSpans')(text, options, globals);
text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals);
text = showdown.subParser('encodeBackslashEscapes')(text, options, globals);
// Process anchor and image tags. Images must come first,
// because ![foo][f] looks like an anchor.
text = showdown.subParser('images')(text, options, globals);
text = showdown.subParser('anchors')(text, options, globals);
// Make links out of things like ` `
// Must come after _DoAnchors(), because you can use < and >
// delimiters in inline links like [this]().
text = showdown.subParser('autoLinks')(text, options, globals);
text = showdown.subParser('encodeAmpsAndAngles')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);
// Do hard breaks:
text = text.replace(/ +\n/g, '
\n');
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
return text;
});
showdown.subParser('strikethrough', function (text, options, globals) {
'use strict';
if (options.strikethrough) {
text = globals.converter._dispatch('strikethrough.before', text, options, globals);
text = text.replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g, '$1');
text = globals.converter._dispatch('strikethrough.after', text, options, globals);
}
return text;
});
/**
* Strip any lines consisting only of spaces and tabs.
* This makes subsequent regexs easier to write, because we can
* match consecutive blank lines with /\n+/ instead of something
* contorted like /[ \t]*\n+/
*/
showdown.subParser('stripBlankLines', function (text) {
'use strict';
return text.replace(/^[ \t]+$/mg, '');
});
/**
* Strips link definitions from text, stores the URLs and titles in
* hash references.
* Link defs are in the form: ^[id]: url "optional title"
*
* ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1
* [ \t]*
* \n? // maybe *one* newline
* [ \t]*
* (\S+?)>? // url = $2
* [ \t]*
* \n? // maybe one newline
* [ \t]*
* (?:
* (\n*) // any lines skipped = $3 attacklab: lookbehind removed
* ["(]
* (.+?) // title = $4
* [")]
* [ \t]*
* )? // title is optional
* (?:\n+|$)
* /gm,
* function(){...});
*
*/
showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
'use strict';
var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=~0))/gm;
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '~0';
text = text.replace(regex, function (wholeMatch, linkId, url, width, height, blankLines, title) {
linkId = linkId.toLowerCase();
globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url); // Link IDs are case-insensitive
if (blankLines) {
// Oops, found blank lines, so it's not a title.
// Put back the parenthetical statement we stole.
return blankLines + title;
} else {
if (title) {
globals.gTitles[linkId] = title.replace(/"|'/g, '"');
}
if (options.parseImgDimensions && width && height) {
globals.gDimensions[linkId] = {
width: width,
height: height
};
}
}
// Completely remove the definition from the text
return '';
});
// attacklab: strip sentinel
text = text.replace(/~0/, '');
return text;
});
showdown.subParser('tables', function (text, options, globals) {
'use strict';
if (!options.tables) {
return text;
}
var tableRgx = /^[ \t]{0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm;
function parseStyles(sLine) {
if (/^:[ \t]*--*$/.test(sLine)) {
return ' style="text-align:left;"';
} else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
return ' style="text-align:right;"';
} else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) {
return ' style="text-align:center;"';
} else {
return '';
}
}
function parseHeaders(header, style) {
var id = '';
header = header.trim();
if (options.tableHeaderId) {
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
}
header = showdown.subParser('spanGamut')(header, options, globals);
return '' + header + ' \n';
}
function parseCells(cell, style) {
var subText = showdown.subParser('spanGamut')(cell, options, globals);
return '' + subText + ' \n';
}
function buildTable(headers, cells) {
var tb = '\n\n\n',
tblLgn = headers.length;
for (var i = 0; i < tblLgn; ++i) {
tb += headers[i];
}
tb += ' \n\n\n';
for (i = 0; i < cells.length; ++i) {
tb += '\n';
for (var ii = 0; ii < tblLgn; ++ii) {
tb += cells[i][ii];
}
tb += ' \n';
}
tb += '\n
\n';
return tb;
}
text = globals.converter._dispatch('tables.before', text, options, globals);
text = text.replace(tableRgx, function (rawTable) {
var i, tableLines = rawTable.split('\n');
// strip wrong first and last column if wrapped tables are used
for (i = 0; i < tableLines.length; ++i) {
if (/^[ \t]{0,3}\|/.test(tableLines[i])) {
tableLines[i] = tableLines[i].replace(/^[ \t]{0,3}\|/, '');
}
if (/\|[ \t]*$/.test(tableLines[i])) {
tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
}
}
var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}),
rawCells = [],
headers = [],
styles = [],
cells = [];
tableLines.shift();
tableLines.shift();
for (i = 0; i < tableLines.length; ++i) {
if (tableLines[i].trim() === '') {
continue;
}
rawCells.push(
tableLines[i]
.split('|')
.map(function (s) {
return s.trim();
})
);
}
if (rawHeaders.length < rawStyles.length) {
return rawTable;
}
for (i = 0; i < rawStyles.length; ++i) {
styles.push(parseStyles(rawStyles[i]));
}
for (i = 0; i < rawHeaders.length; ++i) {
if (showdown.helper.isUndefined(styles[i])) {
styles[i] = '';
}
headers.push(parseHeaders(rawHeaders[i], styles[i]));
}
for (i = 0; i < rawCells.length; ++i) {
var row = [];
for (var ii = 0; ii < headers.length; ++ii) {
if (showdown.helper.isUndefined(rawCells[i][ii])) {
}
row.push(parseCells(rawCells[i][ii], styles[ii]));
}
cells.push(row);
}
return buildTable(headers, cells);
});
text = globals.converter._dispatch('tables.after', text, options, globals);
return text;
});
/**
* Swap back in all the special characters we've hidden.
*/
showdown.subParser('unescapeSpecialChars', function (text) {
'use strict';
text = text.replace(/~E(\d+)E/g, function (wholeMatch, m1) {
var charCodeToReplace = parseInt(m1);
return String.fromCharCode(charCodeToReplace);
});
return text;
});
module.exports = showdown;
================================================
FILE: lib/wxParse/wxDiscode.js
================================================
// HTML 支持的数学符号
function strNumDiscode(str){
str = str.replace(/∀/g, '∀');
str = str.replace(/∂/g, '∂');
str = str.replace(/&exists;/g, '∃');
str = str.replace(/∅/g, '∅');
str = str.replace(/∇/g, '∇');
str = str.replace(/∈/g, '∈');
str = str.replace(/∉/g, '∉');
str = str.replace(/∋/g, '∋');
str = str.replace(/∏/g, '∏');
str = str.replace(/∑/g, '∑');
str = str.replace(/−/g, '−');
str = str.replace(/∗/g, '∗');
str = str.replace(/√/g, '√');
str = str.replace(/∝/g, '∝');
str = str.replace(/∞/g, '∞');
str = str.replace(/∠/g, '∠');
str = str.replace(/∧/g, '∧');
str = str.replace(/∨/g, '∨');
str = str.replace(/∩/g, '∩');
str = str.replace(/∩/g, '∪');
str = str.replace(/∫/g, '∫');
str = str.replace(/∴/g, '∴');
str = str.replace(/∼/g, '∼');
str = str.replace(/≅/g, '≅');
str = str.replace(/≈/g, '≈');
str = str.replace(/≠/g, '≠');
str = str.replace(/≤/g, '≤');
str = str.replace(/≥/g, '≥');
str = str.replace(/⊂/g, '⊂');
str = str.replace(/⊃/g, '⊃');
str = str.replace(/⊄/g, '⊄');
str = str.replace(/⊆/g, '⊆');
str = str.replace(/⊇/g, '⊇');
str = str.replace(/⊕/g, '⊕');
str = str.replace(/⊗/g, '⊗');
str = str.replace(/⊥/g, '⊥');
str = str.replace(/⋅/g, '⋅');
return str;
}
//HTML 支持的希腊字母
function strGreeceDiscode(str){
str = str.replace(/Α/g, 'Α');
str = str.replace(/Β/g, 'Β');
str = str.replace(/Γ/g, 'Γ');
str = str.replace(/Δ/g, 'Δ');
str = str.replace(/Ε/g, 'Ε');
str = str.replace(/Ζ/g, 'Ζ');
str = str.replace(/Η/g, 'Η');
str = str.replace(/Θ/g, 'Θ');
str = str.replace(/Ι/g, 'Ι');
str = str.replace(/Κ/g, 'Κ');
str = str.replace(/Λ/g, 'Λ');
str = str.replace(/Μ/g, 'Μ');
str = str.replace(/Ν/g, 'Ν');
str = str.replace(/Ξ/g, 'Ν');
str = str.replace(/Ο/g, 'Ο');
str = str.replace(/Π/g, 'Π');
str = str.replace(/Ρ/g, 'Ρ');
str = str.replace(/Σ/g, 'Σ');
str = str.replace(/Τ/g, 'Τ');
str = str.replace(/Υ/g, 'Υ');
str = str.replace(/Φ/g, 'Φ');
str = str.replace(/Χ/g, 'Χ');
str = str.replace(/Ψ/g, 'Ψ');
str = str.replace(/Ω/g, 'Ω');
str = str.replace(/α/g, 'α');
str = str.replace(/β/g, 'β');
str = str.replace(/γ/g, 'γ');
str = str.replace(/δ/g, 'δ');
str = str.replace(/ε/g, 'ε');
str = str.replace(/ζ/g, 'ζ');
str = str.replace(/η/g, 'η');
str = str.replace(/θ/g, 'θ');
str = str.replace(/ι/g, 'ι');
str = str.replace(/κ/g, 'κ');
str = str.replace(/λ/g, 'λ');
str = str.replace(/μ/g, 'μ');
str = str.replace(/ν/g, 'ν');
str = str.replace(/ξ/g, 'ξ');
str = str.replace(/ο/g, 'ο');
str = str.replace(/π/g, 'π');
str = str.replace(/ρ/g, 'ρ');
str = str.replace(/ς/g, 'ς');
str = str.replace(/σ/g, 'σ');
str = str.replace(/τ/g, 'τ');
str = str.replace(/υ/g, 'υ');
str = str.replace(/φ/g, 'φ');
str = str.replace(/χ/g, 'χ');
str = str.replace(/ψ/g, 'ψ');
str = str.replace(/ω/g, 'ω');
str = str.replace(/ϑ/g, 'ϑ');
str = str.replace(/ϒ/g, 'ϒ');
str = str.replace(/ϖ/g, 'ϖ');
str = str.replace(/·/g, '·');
return str;
}
//
function strcharacterDiscode(str){
// 加入常用解析
str = str.replace(/ /g, ' ');
str = str.replace(/"/g, '"');
str = str.replace(/&/g, '&');
// str = str.replace(/</g, '‹');
// str = str.replace(/>/g, '›');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
return str;
}
// HTML 支持的其他实体
function strOtherDiscode(str){
str = str.replace(/Œ/g, 'Œ');
str = str.replace(/œ/g, 'œ');
str = str.replace(/Š/g, 'Š');
str = str.replace(/š/g, 'š');
str = str.replace(/Ÿ/g, 'Ÿ');
str = str.replace(/ƒ/g, 'ƒ');
str = str.replace(/ˆ/g, 'ˆ');
str = str.replace(/˜/g, '˜');
str = str.replace(/ /g, '');
str = str.replace(/ /g, '');
str = str.replace(/ /g, '');
str = str.replace(//g, '');
str = str.replace(//g, '');
str = str.replace(//g, '');
str = str.replace(//g, '');
str = str.replace(/–/g, '–');
str = str.replace(/—/g, '—');
str = str.replace(/‘/g, '‘');
str = str.replace(/’/g, '’');
str = str.replace(/‚/g, '‚');
str = str.replace(/“/g, '“');
str = str.replace(/”/g, '”');
str = str.replace(/„/g, '„');
str = str.replace(/†/g, '†');
str = str.replace(/‡/g, '‡');
str = str.replace(/•/g, '•');
str = str.replace(/…/g, '…');
str = str.replace(/‰/g, '‰');
str = str.replace(/′/g, '′');
str = str.replace(/″/g, '″');
str = str.replace(/‹/g, '‹');
str = str.replace(/›/g, '›');
str = str.replace(/‾/g, '‾');
str = str.replace(/€/g, '€');
str = str.replace(/™/g, '™');
str = str.replace(/←/g, '←');
str = str.replace(/↑/g, '↑');
str = str.replace(/→/g, '→');
str = str.replace(/↓/g, '↓');
str = str.replace(/↔/g, '↔');
str = str.replace(/↵/g, '↵');
str = str.replace(/⌈/g, '⌈');
str = str.replace(/⌉/g, '⌉');
str = str.replace(/⌊/g, '⌊');
str = str.replace(/⌋/g, '⌋');
str = str.replace(/◊/g, '◊');
str = str.replace(/♠/g, '♠');
str = str.replace(/♣/g, '♣');
str = str.replace(/♥/g, '♥');
str = str.replace(/♦/g, '♦');
return str;
}
function strMoreDiscode(str){
str = str.replace(/\r\n/g,"");
str = str.replace(/\n/g,"");
str = str.replace(/code/g,"wxxxcode-style");
return str;
}
function strDiscode(str){
str = strNumDiscode(str);
str = strGreeceDiscode(str);
str = strcharacterDiscode(str);
str = strOtherDiscode(str);
str = strMoreDiscode(str);
return str;
}
function urlToHttpUrl(url,rep){
var patt1 = new RegExp("^//");
var result = patt1.test(url);
if(result){
url = rep+":"+url;
}
return url;
}
module.exports = {
strDiscode:strDiscode,
urlToHttpUrl:urlToHttpUrl
}
================================================
FILE: lib/wxParse/wxParse.js
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
/**
* utils函数引入
**/
import showdown from 'showdown.js';
import HtmlToJson from 'html2json.js';
/**
* 配置及公有属性
**/
/**
* 主函数入口区
**/
function wxParse(bindName = 'wxParseData', type='html', data='数据不能为空', target,imagePadding) {
var that = target;
var transData = {};//存放转化后的数据
if (type == 'html') {
transData = HtmlToJson.html2json(data, bindName);
console.log(JSON.stringify(transData, ' ', ' '));
} else if (type == 'md' || type == 'markdown') {
var converter = new showdown.Converter();
var html = converter.makeHtml(data);
transData = HtmlToJson.html2json(html, bindName);
console.log(JSON.stringify(transData, ' ', ' '));
}
transData.view = {};
transData.view.imagePadding = 0;
if(typeof(imagePadding) != 'undefined'){
transData.view.imagePadding = imagePadding
}
var bindData = {};
bindData[bindName] = transData;
that.setData(bindData)
that.wxParseImgLoad = wxParseImgLoad;
that.wxParseImgTap = wxParseImgTap;
}
// 图片点击事件
function wxParseImgTap(e) {
var that = this;
var nowImgUrl = e.target.dataset.src;
var tagFrom = e.target.dataset.from;
if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
wx.previewImage({
current: nowImgUrl, // 当前显示图片的http链接
urls: that.data[tagFrom].imageUrls // 需要预览的图片http链接列表
})
}
}
/**
* 图片视觉宽高计算函数区
**/
function wxParseImgLoad(e) {
var that = this;
var tagFrom = e.target.dataset.from;
var idx = e.target.dataset.idx;
if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
calMoreImageInfo(e, idx, that, tagFrom)
}
}
// 假循环获取计算图片视觉最佳宽高
function calMoreImageInfo(e, idx, that, bindName) {
var temData = that.data[bindName];
if (temData.images.length == 0) {
return;
}
var temImages = temData.images;
//因为无法获取view宽度 需要自定义padding进行计算,稍后处理
var recal = wxAutoImageCal(e.detail.width, e.detail.height,that,bindName);
temImages[idx].width = recal.imageWidth;
temImages[idx].height = recal.imageheight;
temData.images = temImages;
var bindData = {};
bindData[bindName] = temData;
that.setData(bindData);
}
// 计算视觉优先的图片宽高
function wxAutoImageCal(originalWidth, originalHeight,that,bindName) {
//获取图片的原始长宽
var windowWidth = 0, windowHeight = 0;
var autoWidth = 0, autoHeight = 0;
var results = {};
wx.getSystemInfo({
success: function (res) {
var padding = that.data[bindName].view.imagePadding;
windowWidth = res.windowWidth-2*padding;
windowHeight = res.windowHeight;
//判断按照那种方式进行缩放
console.log("windowWidth" + windowWidth);
if (originalWidth > windowWidth) {//在图片width大于手机屏幕width时候
autoWidth = windowWidth;
console.log("autoWidth" + autoWidth);
autoHeight = (autoWidth * originalHeight) / originalWidth;
console.log("autoHeight" + autoHeight);
results.imageWidth = autoWidth;
results.imageheight = autoHeight;
} else {//否则展示原来的数据
results.imageWidth = originalWidth;
results.imageheight = originalHeight;
}
}
})
return results;
}
function wxParseTemArray(temArrayName,bindNameReg,total,that){
var array = [];
var temData = that.data;
var obj = null;
for(var i = 0; i < total; i++){
var simArr = temData[bindNameReg+i].nodes;
array.push(simArr);
}
temArrayName = temArrayName || 'wxParseTemArray';
obj = JSON.parse('{"'+ temArrayName +'":""}');
obj[temArrayName] = array;
that.setData(obj);
}
/**
* 配置emojis
*
*/
function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
HtmlToJson.emojisInit(reg,baseSrc,emojis);
}
module.exports = {
wxParse: wxParse,
wxParseTemArray:wxParseTemArray,
emojisInit:emojisInit
}
================================================
FILE: lib/wxParse/wxParse.wxml
================================================
{{item.text}}
================================================
FILE: lib/wxParse/wxParse.wxss
================================================
/**
* author: Di (微信小程序开发工程师)
* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
* 垂直微信小程序开发交流社区
*
* github地址: https://github.com/icindy/wxParse
*
* for: 微信小程序富文本解析
* detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
*/
.wxParse{
margin: 0 5px;
font-family: Helvetica,sans-serif;
font-size: 28rpx;
color: #666;
line-height: 1.8;
}
view{
word-break:break-all; overflow:auto;
}
.wxParse-inline{
display: inline;
margin: 0;
padding: 0;
}
/*//标题 */
.wxParse-div{margin: 0;padding: 0;}
.wxParse-h1{ font-size:2em; margin: .67em 0 }
.wxParse-h2{ font-size:1.5em; margin: .75em 0 }
.wxParse-h3{ font-size:1.17em; margin: .83em 0 }
.wxParse-h4{ margin: 1.12em 0}
.wxParse-h5 { font-size:.83em; margin: 1.5em 0 }
.wxParse-h6{ font-size:.75em; margin: 1.67em 0 }
.wxParse-h1 {
font-size: 18px;
font-weight: 400;
margin-bottom: .9em;
}
.wxParse-h2 {
font-size: 16px;
font-weight: 400;
margin-bottom: .34em;
}
.wxParse-h3 {
font-weight: 400;
font-size: 15px;
margin-bottom: .34em;
}
.wxParse-h4 {
font-weight: 400;
font-size: 14px;
margin-bottom: .24em;
}
.wxParse-h5 {
font-weight: 400;
font-size: 13px;
margin-bottom: .14em;
}
.wxParse-h6 {
font-weight: 400;
font-size: 12px;
margin-bottom: .04em;
}
.wxParse-h1, .wxParse-h2, .wxParse-h3, .wxParse-h4, .wxParse-h5, .wxParse-h6, .wxParse-b, .wxParse-strong { font-weight: bolder }
.wxParse-i,.wxParse-cite,.wxParse-em,.wxParse-var,.wxParse-address{font-style:italic}
.wxParse-pre,.wxParse-tt,.wxParse-code,.wxParse-kbd,.wxParse-samp{font-family:monospace}
.wxParse-pre{white-space:pre}
.wxParse-big{font-size:1.17em}
.wxParse-small,.wxParse-sub,.wxParse-sup{font-size:.83em}
.wxParse-sub{vertical-align:sub}
.wxParse-sup{vertical-align:super}
.wxParse-s,.wxParse-strike,.wxParse-del{text-decoration:line-through}
/*wxparse-自定义个性化的css样式*/
/*增加video的css样式*/
.wxParse-strong,wxParse-s{display: inline}
.wxParse-a{
color: deepskyblue;
word-break:break-all;
overflow:auto;
}
.wxParse-video{
text-align: center;
margin: 10px 0;
}
.wxParse-video-video{
width:100%;
}
.wxParse-img{
background-color: #efefef;
overflow: hidden;
width:40px;
height: 40px;
}
.wxParse-blockquote {
margin: 0;
padding:10px 0 10px 5px;
font-family:Courier, Calibri,"宋体";
background:#f5f5f5;
border-left: 3px solid #dbdbdb;
}
.wxParse-code,.wxParse-wxxxcode-style{
display: inline;
background:#f5f5f5;
}
.wxParse-ul{
margin: 20rpx 10rpx;
}
.wxParse-li,.wxParse-li-inner{
display: flex;
align-items: baseline;
margin: 10rpx 0;
}
.wxParse-li-text{
align-items: center;
line-height: 20px;
}
.wxParse-li-circle{
display: inline-flex;
width: 5px;
height: 5px;
background-color: #333;
margin-right: 5px;
}
.wxParse-li-square{
display: inline-flex;
width: 10rpx;
height: 10rpx;
background-color: #333;
margin-right: 5px;
}
.wxParse-li-ring{
display: inline-flex;
width: 10rpx;
height: 10rpx;
border: 2rpx solid #333;
border-radius: 50%;
background-color: #fff;
margin-right: 5px;
}
/*.wxParse-table{
width: 100%;
height: 400px;
}
.wxParse-thead,.wxParse-tfoot,.wxParse-tr{
display: flex;
flex-direction: row;
}
.wxParse-th,.wxParse-td{
display: flex;
width: 580px;
overflow: auto;
}*/
.wxParse-u {
text-decoration: underline;
}
.wxParse-hide{
display: none;
}
.WxEmojiView{
align-items: center;
}
.wxEmoji{
width: 16px;
height:16px;
}
.wxParse-tr{
display: flex;
border-right:1px solid #e0e0e0;
border-bottom:1px solid #e0e0e0;
}
.wxParse-th,
.wxParse-td{
flex:1;
padding:5px;
font-size:28rpx;
border-left:1px solid #e0e0e0;
word-break: break-all;
}
.wxParse-td:last{
border-top:1px solid #e0e0e0;
}
.wxParse-th{
background:#f0f0f0;
border-top:1px solid #e0e0e0;
}
================================================
FILE: pages/auth/login/login.js
================================================
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
username: '',
password: '',
code: '',
loginErrorCount: 0
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
startLogin: function () {
var that = this;
if (that.data.password.length < 1 || that.data.username.length < 1) {
wx.showModal({
title: '错误信息',
content: '请输入用户名和密码',
showCancel: false
});
return false;
}
wx.request({
url: api.ApiRootUrl + 'auth/login',
data: {
username: that.data.username,
password: that.data.password
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
if(res.data.code == 200){
that.setData({
'loginErrorCount': 0
});
wx.setStorage({
key:"token",
data: res.data.data.token,
success: function(){
wx.switchTab({
url: '/pages/ucenter/index/index'
});
}
});
}
}
});
},
bindUsernameInput: function (e) {
this.setData({
username: e.detail.value
});
},
bindPasswordInput: function (e) {
this.setData({
password: e.detail.value
});
},
bindCodeInput: function (e) {
this.setData({
code: e.detail.value
});
},
clearInput: function (e) {
switch (e.currentTarget.id) {
case 'clear-username':
this.setData({
username: ''
});
break;
case 'clear-password':
this.setData({
password: ''
});
break;
case 'clear-code':
this.setData({
code: ''
});
break;
}
}
})
================================================
FILE: pages/auth/login/login.json
================================================
{}
================================================
FILE: pages/auth/login/login.wxml
================================================
注册账号
忘记密码
================================================
FILE: pages/auth/login/login.wxss
================================================
.form-box{
width: 100%;
height: auto;
overflow: hidden;
padding: 0 40rpx;
margin-top: 96rpx;
background: #fff;
}
.form-item{
position: relative;
background: #fff;
height: 96rpx;
border-bottom: 1px solid #d9d9d9;
}
.form-item .username, .form-item .password, .form-item .code{
position: absolute;
top: 26rpx;
left: 0;
display: block;
width: 100%;
height: 44rpx;
background: #fff;
color: #333;
font-size: 30rpx;
}
.form-item-code{
margin-top:32rpx;
height: auto;
overflow: hidden;
width: 100%;
}
.form-item-code .form-item{
float: left;
width: 350rpx;
}
.form-item-code .code-img{
float: right;
margin-top: 4rpx;
height: 88rpx;
width: 236rpx;
}
.form-item .clear{
position: absolute;
top: 26rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.login-btn{
margin: 60rpx 0 40rpx 0;
height: 96rpx;
line-height: 96rpx;
color: #fff;
font-size: 30rpx;
width: 100%;
background: #b4282d;
border-radius: 6rpx;
}
.form-item-text{
height: 35rpx;
width: 100%;
}
.form-item-text .register{
display: block;
height: 34rpx;
float: left;
font-size: 28rpx;
color: #999;
}
.form-item-text .reset{
display: block;
height: 34rpx;
float: right;
font-size: 28rpx;
color: #999;
}
================================================
FILE: pages/auth/register/register.js
================================================
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
username: '',
password: '',
confirmPassword: '',
code: '',
loginErrorCount: 0
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
startRegister: function () {
var that = this;
if (that.data.password.length < 3 || that.data.username.length < 3) {
wx.showModal({
title: '错误信息',
content: '用户名和密码不得少于3位',
showCancel: false
});
return false;
}
if (that.data.password != that.data.confirmPassword) {
wx.showModal({
title: '错误信息',
content: '确认密码不一致',
showCancel: false
});
return false;
}
wx.request({
url: api.ApiRootUrl + 'auth/register',
data: {
username: that.data.username,
password: that.data.password
},
method: 'POST',
header: {
'content-type': 'application/json'
},
success: function (res) {
if (res.data.code == 200) {
that.setData({
'loginErrorCount': 0
});
wx.setStorage({
key: "token",
data: res.data.data.token,
success: function () {
wx.switchTab({
url: '/pages/ucenter/index/index'
});
}
});
}
console.log(res.data.data.token)
}
});
},
bindUsernameInput: function (e) {
this.setData({
username: e.detail.value
});
},
bindPasswordInput: function (e) {
this.setData({
password: e.detail.value
});
},
bindConfirmPasswordInput: function (e) {
this.setData({
confirmPassword: e.detail.value
});
},
bindCodeInput: function (e) {
this.setData({
code: e.detail.value
});
},
clearInput: function (e) {
switch (e.currentTarget.id) {
case 'clear-username':
this.setData({
username: ''
});
break;
case 'clear-password':
this.setData({
password: ''
});
break;
case 'clear-confirm-password':
this.setData({
confirmPassword: ''
});
break;
case 'clear-code':
this.setData({
code: ''
});
break;
}
}
})
================================================
FILE: pages/auth/register/register.json
================================================
{}
================================================
FILE: pages/auth/register/register.wxml
================================================
================================================
FILE: pages/auth/register/register.wxss
================================================
.form-box{
width: 100%;
height: auto;
overflow: hidden;
padding: 0 40rpx;
margin-top: 96rpx;
background: #fff;
}
.form-item{
position: relative;
background: #fff;
height: 96rpx;
border-bottom: 1px solid #d9d9d9;
}
.form-item .username, .form-item .password, .form-item .code{
position: absolute;
top: 26rpx;
left: 0;
display: block;
width: 100%;
height: 44rpx;
background: #fff;
color: #333;
font-size: 30rpx;
}
.form-item-code{
margin-top:32rpx;
height: auto;
overflow: hidden;
width: 100%;
}
.form-item-code .form-item{
float: left;
width: 350rpx;
}
.form-item-code .code-img{
float: right;
margin-top: 4rpx;
height: 88rpx;
width: 236rpx;
}
.form-item .clear{
position: absolute;
top: 26rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.login-btn{
margin: 60rpx 0 40rpx 0;
height: 96rpx;
line-height: 96rpx;
color: #fff;
font-size: 30rpx;
width: 100%;
background: #b4282d;
border-radius: 6rpx;
}
.form-item-text{
height: 35rpx;
width: 100%;
}
.form-item-text .register{
display: block;
height: 34rpx;
float: left;
font-size: 28rpx;
color: #999;
}
.form-item-text .reset{
display: block;
height: 34rpx;
float: right;
font-size: 28rpx;
color: #999;
}
================================================
FILE: pages/auth/reset/reset.js
================================================
var app = getApp();
Page({
data: {
username: '',
code: ''
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
// 页面渲染完成
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
startLogin: function(){
var that = this;
},
bindUsernameInput: function(e){
this.setData({
username: e.detail.value
});
},
bindCodeInput: function(e){
this.setData({
code: e.detail.value
});
},
clearInput: function(e){
switch (e.currentTarget.id){
case 'clear-username':
this.setData({
username: ''
});
break;
case 'clear-code':
this.setData({
code: ''
});
break;
}
}
})
================================================
FILE: pages/auth/reset/reset.json
================================================
{}
================================================
FILE: pages/auth/reset/reset.wxml
================================================
================================================
FILE: pages/auth/reset/reset.wxss
================================================
.form-box{
width: 100%;
height: auto;
overflow: hidden;
padding: 0 40rpx;
margin-top: 96rpx;
background: #fff;
}
.form-item{
position: relative;
background: #fff;
height: 96rpx;
border-bottom: 1px solid #d9d9d9;
}
.form-item .username, .form-item .code{
position: absolute;
top: 26rpx;
left: 0;
display: block;
width: 100%;
height: 44rpx;
background: #fff;
color: #333;
font-size: 30rpx;
}
.form-item-code{
margin-top:32rpx;
height: auto;
overflow: hidden;
width: 100%;
}
.form-item-code .form-item{
float: left;
width: 350rpx;
}
.form-item-code .code-img{
float: right;
margin-top: 4rpx;
height: 88rpx;
width: 236rpx;
}
.form-item .clear{
position: absolute;
top: 26rpx;
right: 18rpx;
z-index: 2;
display: block;
background: #fff;
height: 44rpx;
width: 44rpx;
}
.login-btn{
margin: 60rpx 0 40rpx 0;
height: 96rpx;
line-height: 96rpx;
color: #fff;
font-size: 30rpx;
width: 100%;
background: #b4282d;
border-radius: 6rpx;
}
================================================
FILE: pages/brand/brand.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
brandList: [],
page: 1,
size: 10,
totalPages: 1
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getBrandList();
},
getBrandList: function () {
wx.showLoading({
title: '加载中...',
});
let that = this;
util.request(api.BrandList, { page: that.data.page, size: that.data.size }).then(function (res) {
if (res.errno === 0) {
that.setData({
brandList: that.data.brandList.concat(res.data.data),
totalPages: res.data.totalPages
});
}
wx.hideLoading();
});
},
onReachBottom (){
if (this.data.totalPages > this.data.page) {
this.setData({
page: this.data.page + 1
});
} else {
return false;
}
this.getBrandList();
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/brand/brand.json
================================================
{}
================================================
FILE: pages/brand/brand.wxml
================================================
{{item.name}}
|
{{item.floor_price}}元起
================================================
FILE: pages/brand/brand.wxss
================================================
.brand-list .item{
display: block;
width: 750rpx;
height: 416rpx;
position: relative;
margin-bottom: 4rpx;
}
.brand-list .item .img-bg{
position: absolute;
left:0;
top:0;
z-index: 0;
width: 750rpx;
height: 417rpx;
overflow: hidden;
}
.brand-list .item .img-bg image{
width: 750rpx;
height: 416rpx;
}
.brand-list .item .txt-box{
position: absolute;
left:0;
top:0;
display: table;
z-index: 0;
width: 750rpx;
height: 417rpx;
}
.brand-list .item .line{
display: table-cell;
vertical-align: middle;
text-align: center;
height: 63rpx;
line-height: 63rpx;
}
.brand-list .item .line text{
font-size: 35rpx;
font-weight: 700;
text-shadow: 1rpx 1rpx rgba(0,0,0,.32);
color: #fff;
}
.brand-list .item .line .s{
padding: 0 10rpx;
font-size: 40rpx;
}
================================================
FILE: pages/brandDetail/brandDetail.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
id: 0,
brand: {},
goodsList: [],
page: 1,
size: 1000
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
var that = this;
that.setData({
id: parseInt(options.id)
});
this.getBrand();
},
getBrand: function () {
let that = this;
util.request(api.BrandDetail, { id: that.data.id }).then(function (res) {
if (res.errno === 0) {
that.setData({
brand: res.data.brand
});
that.getGoodsList();
}
});
},
getGoodsList() {
var that = this;
util.request(api.GoodsList, { brandId: that.data.id, page: that.data.page, size: that.data.size})
.then(function (res) {
if (res.errno === 0) {
that.setData({
goodsList: res.data.goodsList
});
}
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/brandDetail/brandDetail.json
================================================
{
}
================================================
FILE: pages/brandDetail/brandDetail.wxml
================================================
{{brand.name}}
{{brand.simple_desc}}
{{iitem.name}}
¥{{iitem.retail_price}}
================================================
FILE: pages/brandDetail/brandDetail.wxss
================================================
page{
background: #f4f4f4;
}
.brand-info .name{
width: 100%;
height: 290rpx;
position: relative;
}
.brand-info .img{
position: absolute;
top:0;
left:0;
width: 100%;
height: 290rpx;
}
.brand-info .info-box{
position: absolute;
top:0;
left:0;
width: 100%;
height: 290rpx;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.brand-info .info{
display: block;
}
.brand-info .txt{
display: block;
height: 37.5rpx;
font-size: 37.5rpx;
color: #fff;
}
.brand-info .line{
margin: 0 auto;
margin-top: 16rpx;
display: block;
height: 2rpx;
width: 145rpx;
background: #fff;
}
.brand-info .desc{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
padding: 41.5rpx 31.25rpx;
font-size: 30rpx;
color: #666;
line-height: 41.5rpx;
text-align: center;
}
.cate-item .b{
width: 750rpx;
height: auto;
overflow: hidden;
border-top: 1rpx solid #f4f4f4;
margin-top: 20rpx;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 375rpx;
padding-bottom: 33.333rpx;
border-bottom: 1rpx solid #f4f4f4;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
border-right: 1rpx solid #f4f4f4;
}
.cate-item .item .img{
margin-top: 10rpx;
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
padding: 0 20rpx;
overflow: hidden;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/cart/cart.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
cartGoods: [],
cartTotal: {
"goodsCount": 0,
"goodsAmount": 0.00,
"checkedGoodsCount": 0,
"checkedGoodsAmount": 0.00
},
isEditCart: false,
checkedAllStatus: true,
editCartList: []
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
this.getCartList();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
getCartList: function () {
let that = this;
util.request(api.CartList).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
cartGoods: res.data.cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
},
isCheckedAll: function () {
//判断购物车商品已全选
return this.data.cartGoods.every(function (element, index, array) {
if (element.checked == true) {
return true;
} else {
return false;
}
});
},
checkedItem: function (event) {
let itemIndex = event.target.dataset.itemIndex;
let that = this;
if (!this.data.isEditCart) {
util.request(api.CartChecked, { productIds: that.data.cartGoods[itemIndex].product_id, isChecked: that.data.cartGoods[itemIndex].checked ? 0 : 1 }, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
cartGoods: res.data.cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
} else {
//编辑状态
let tmpCartData = this.data.cartGoods.map(function (element, index, array) {
if (index == itemIndex){
element.checked = !element.checked;
}
return element;
});
that.setData({
cartGoods: tmpCartData,
checkedAllStatus: that.isCheckedAll(),
'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount()
});
}
},
getCheckedGoodsCount: function(){
let checkedGoodsCount = 0;
this.data.cartGoods.forEach(function (v) {
if (v.checked === true) {
checkedGoodsCount += v.number;
}
});
console.log(checkedGoodsCount);
return checkedGoodsCount;
},
checkedAll: function () {
let that = this;
if (!this.data.isEditCart) {
var productIds = this.data.cartGoods.map(function (v) {
return v.product_id;
});
util.request(api.CartChecked, { productIds: productIds.join(','), isChecked: that.isCheckedAll() ? 0 : 1 }, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
cartGoods: res.data.cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
} else {
//编辑状态
let checkedAllStatus = that.isCheckedAll();
let tmpCartData = this.data.cartGoods.map(function (v) {
v.checked = !checkedAllStatus;
return v;
});
that.setData({
cartGoods: tmpCartData,
checkedAllStatus: that.isCheckedAll(),
'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount()
});
}
},
editCart: function () {
var that = this;
if (this.data.isEditCart) {
this.getCartList();
this.setData({
isEditCart: !this.data.isEditCart
});
} else {
//编辑状态
let tmpCartList = this.data.cartGoods.map(function (v) {
v.checked = false;
return v;
});
this.setData({
editCartList: this.data.cartGoods,
cartGoods: tmpCartList,
isEditCart: !this.data.isEditCart,
checkedAllStatus: that.isCheckedAll(),
'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount()
});
}
},
updateCart: function (productId, goodsId, number, id) {
let that = this;
util.request(api.CartUpdate, {
productId: productId,
goodsId: goodsId,
number: number,
id: id
}, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
//cartGoods: res.data.cartList,
//cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
},
cutNumber: function (event) {
let itemIndex = event.target.dataset.itemIndex;
let cartItem = this.data.cartGoods[itemIndex];
let number = (cartItem.number - 1 > 1) ? cartItem.number - 1 : 1;
cartItem.number = number;
this.setData({
cartGoods: this.data.cartGoods
});
this.updateCart(cartItem.product_id, cartItem.goods_id, number, cartItem.id);
},
addNumber: function (event) {
let itemIndex = event.target.dataset.itemIndex;
let cartItem = this.data.cartGoods[itemIndex];
let number = cartItem.number + 1;
cartItem.number = number;
this.setData({
cartGoods: this.data.cartGoods
});
this.updateCart(cartItem.product_id, cartItem.goods_id, number, cartItem.id);
},
checkoutOrder: function () {
//获取已选择的商品
let that = this;
var checkedGoods = this.data.cartGoods.filter(function (element, index, array) {
if (element.checked == true) {
return true;
} else {
return false;
}
});
if (checkedGoods.length <= 0) {
return false;
}
wx.navigateTo({
url: '../shopping/checkout/checkout'
})
},
deleteCart: function () {
//获取已选择的商品
let that = this;
let productIds = this.data.cartGoods.filter(function (element, index, array) {
if (element.checked == true) {
return true;
} else {
return false;
}
});
if (productIds.length <= 0) {
return false;
}
productIds = productIds.map(function (element, index, array) {
if (element.checked == true) {
return element.product_id;
}
});
util.request(api.CartDelete, {
productIds: productIds.join(',')
}, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
let cartList = res.data.cartList.map(v => {
console.log(v);
v.checked = false;
return v;
});
that.setData({
cartGoods: cartList,
cartTotal: res.data.cartTotal
});
}
that.setData({
checkedAllStatus: that.isCheckedAll()
});
});
}
})
================================================
FILE: pages/cart/cart.json
================================================
{
"backgroundColor": "#f4f4f4"
}
================================================
FILE: pages/cart/cart.wxml
================================================
30天无忧退货
48小时快速退款
满88元免邮费
去添加点什么吧
{{item.goods_name}}
x{{item.number}}
{{ isEditCart ? '已选择:' : ''}}{{item.goods_specifition_name_value}}
¥{{item.retail_price}}
-
+
全选({{cartTotal.checkedGoodsCount}})
{{!isEditCart ? '¥'+cartTotal.checkedGoodsAmount : ''}}
{{!isEditCart ? '编辑' : '完成'}}
删除所选
下单
================================================
FILE: pages/cart/cart.wxss
================================================
page{
height: 100%;
min-height: 100%;
background: #f4f4f4;
}
.container{
background: #f4f4f4;
width: 100%;
height: auto;
min-height: 100%;
overflow: hidden;
}
.service-policy{
width: 750rpx;
height: 73rpx;
background: #f4f4f4;
padding: 0 31.25rpx;
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: space-between;
}
.service-policy .item{
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/servicePolicyRed-518d32d74b.png) 0 center no-repeat;
background-size: 10rpx;
padding-left: 15rpx;
display: flex;
align-items: center;
font-size: 25rpx;
color: #666;
}
.no-cart{
width: 100%;
height: auto;
margin: 0 auto;
}
.no-cart .c{
width: 100%;
height: auto;
margin-top: 200rpx;
}
.no-cart .c image{
margin: 0 auto;
display: block;
text-align: center;
width: 258rpx;
height: 258rpx;
}
.no-cart .c text{
margin: 0 auto;
display: block;
width: 258rpx;
height: 29rpx;
line-height: 29rpx;
text-align: center;
font-size: 29rpx;
color: #999;
}
.cart-view{
width: 100%;
height: auto;
overflow: hidden;
}
.cart-view .list{
height: auto;
width: 100%;
overflow: hidden;
margin-bottom: 120rpx;
}
.cart-view .group-item{
height: auto;
width: 100%;
background: #fff;
margin-bottom: 18rpx;
}
.cart-view .item{
height: 164rpx;
width: 100%;
overflow: hidden;
}
.cart-view .item .checkbox{
float: left;
height: 34rpx;
width: 34rpx;
margin: 65rpx 18rpx 65rpx 26rpx;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-0e09baa37e.png) no-repeat;
background-size: 34rpx;
}
.cart-view .item .checkbox.checked{
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-checked-822e54472a.png) no-repeat;
background-size: 34rpx;
}
.cart-view .item .cart-goods{
float: left;
height: 164rpx;
width: 672rpx;
border-bottom: 1px solid #f4f4f4;
}
.cart-view .item .img{
float: left;
height:125rpx;
width: 125rpx;
background: #f4f4f4;
margin: 19.5rpx 18rpx 19.5rpx 0;
}
.cart-view .item .info{
float: left;
height:125rpx;
width: 503rpx;
margin: 19.5rpx 26rpx 19.5rpx 0;
}
.cart-view .item .t{
margin: 8rpx 0;
height: 28rpx;
font-size: 25rpx;
color: #333;
overflow: hidden;
}
.cart-view .item .name{
height: 28rpx;
max-width: 310rpx;
line-height: 28rpx;
font-size: 25rpx;
color: #333;
overflow: hidden;
}
.cart-view .item .num{
height: 28rpx;
line-height: 28rpx;
float: right;
}
.cart-view .item .attr{
margin-bottom: 17rpx;
height: 24rpx;
line-height: 24rpx;
font-size: 22rpx;
color: #666;
overflow: hidden;
}
.cart-view .item .b{
height: 28rpx;
line-height: 28rpx;
font-size: 25rpx;
color: #333;
overflow: hidden;
}
.cart-view .item .price{
float: left;
}
.cart-view .item .open{
height: 28rpx;
width: 150rpx;
display: block;
float: right;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/arrowDown-d48093db25.png) right center no-repeat;
background-size: 25rpx;
font-size: 25rpx;
color: #333;
}
.cart-view .item.edit .t{
display: none;
}
.cart-view .item.edit .attr{
text-align: right;
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/arrow-right1-e9828c5b35.png) right center no-repeat;
padding-right: 25rpx;
background-size: 12rpx 20rpx;
margin-bottom: 24rpx;
height: 39rpx;
line-height: 39rpx;
font-size: 24rpx;
color: #999;
overflow: hidden;
}
.cart-view .item.edit .b{
display: flex;
height: 52rpx;
overflow: hidden;
}
.cart-view .item.edit .price{
line-height: 52rpx;
height: 52rpx;
flex: 1;
}
.cart-view .item .selnum{
display: none;
}
.cart-view .item.edit .selnum{
width: 235rpx;
height: 52rpx;
border: 1rpx solid #ccc;
display: flex;
}
.selnum .cut{
width: 70rpx;
height: 100%;
text-align: center;
line-height: 50rpx;
}
.selnum .number{
flex: 1;
height: 100%;
text-align: center;
line-height: 68.75rpx;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
float: left;
}
.selnum .add{
width: 80rpx;
height: 100%;
text-align: center;
line-height: 50rpx;
}
.cart-view .group-item .header{
width: 100%;
height: 94rpx;
line-height: 94rpx;
padding: 0 26rpx;
border-bottom: 1px solid #f4f4f4;
}
.cart-view .promotion .icon{
display: inline-block;
height: 24rpx;
width: 15rpx;
}
.cart-view .promotion{
margin-top: 25.5rpx;
float: left;
height: 43rpx;
width: 480rpx;
/*margin-right: 84rpx;*/
line-height: 43rpx;
font-size: 0;
}
.cart-view .promotion .tag{
border: 1px solid #f48f18;
height: 37rpx;
line-height: 31rpx;
padding: 0 9rpx;
margin-right: 10rpx;
color: #f48f18;
font-size: 24.5rpx;
}
.cart-view .promotion .txt{
height: 43rpx;
line-height: 43rpx;
padding-right: 10rpx;
color: #333;
font-size: 29rpx;
overflow: hidden;
}
.cart-view .get{
margin-top: 18rpx;
float: right;
height: 58rpx;
padding-left: 14rpx;
border-left: 1px solid #d9d9d9;
line-height: 58rpx;
font-size: 29rpx;
color: #333;
}
.cart-bottom{
position: fixed;
bottom:0;
left:0;
height: 100rpx;
width: 100%;
background: #fff;
display: flex;
}
.cart-bottom .checkbox{
height: 34rpx;
padding-left: 60rpx;
line-height: 34rpx;
margin: 33rpx 18rpx 33rpx 26rpx;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-0e09baa37e.png) no-repeat;
background-size: 34rpx;
font-size: 29rpx;
}
.cart-bottom .checkbox.checked{
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-checked-822e54472a.png) no-repeat;
background-size: 34rpx;
}
.cart-bottom .total{
height: 34rpx;
flex: 1;
margin: 33rpx 10rpx;
font-size: 29rpx;
}
.cart-bottom .delete{
height: 34rpx;
width: auto;
margin: 33rpx 18rpx;
font-size: 29rpx;
}
.cart-bottom .checkout{
height: 100rpx;
width: 210rpx;
text-align: center;
line-height: 100rpx;
font-size: 29rpx;
background: #b4282d;
color: #fff;
}
================================================
FILE: pages/catalog/catalog.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
navList: [],
categoryList: [],
currentCategory: {},
scrollLeft: 0,
scrollTop: 0,
goodsCount: 0,
scrollHeight: 0
},
onLoad: function (options) {
this.getCatalog();
},
getCatalog: function () {
//CatalogList
let that = this;
wx.showLoading({
title: '加载中...',
});
util.request(api.CatalogList).then(function (res) {
that.setData({
navList: res.data.categoryList,
currentCategory: res.data.currentCategory
});
wx.hideLoading();
});
util.request(api.GoodsCount).then(function (res) {
that.setData({
goodsCount: res.data.goodsCount
});
});
},
getCurrentCategory: function (id) {
let that = this;
util.request(api.CatalogCurrent, { id: id })
.then(function (res) {
that.setData({
currentCategory: res.data.currentCategory
});
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
getList: function () {
var that = this;
util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.cat_id)
.then(function (res) {
that.setData({
categoryList: res.data,
});
});
},
switchCate: function (event) {
var that = this;
var currentTarget = event.currentTarget;
if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
return false;
}
this.getCurrentCategory(event.currentTarget.dataset.id);
}
})
================================================
FILE: pages/catalog/catalog.json
================================================
{}
================================================
FILE: pages/catalog/catalog.wxml
================================================
商品搜索, 共{{goodsCount}}款好物
{{item.name}}
{{currentCategory.front_name}}
{{currentCategory.name}}分类
{{item.name}}
================================================
FILE: pages/catalog/catalog.wxss
================================================
page {
height: 100%;
}
.container {
background: #f9f9f9;
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.search {
height: 88rpx;
width: 100%;
padding: 0 30rpx;
background: #fff;
display: flex;
align-items: center;
}
.search .input {
width: 690rpx;
height: 56rpx;
background: #ededed;
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
}
.search .icon {
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png) center no-repeat;
background-size: 100%;
width: 28rpx;
height: 28rpx;
}
.search .txt {
height: 42rpx;
line-height: 42rpx;
color: #666;
padding-left: 10rpx;
font-size: 30rpx;
}
.catalog {
flex: 1;
width: 100%;
background: #fff;
display: flex;
border-top: 1px solid #fafafa;
}
.catalog .nav {
width: 162rpx;
height: 100%;
}
.catalog .nav .item {
text-align: center;
line-height: 90rpx;
width: 162rpx;
height: 90rpx;
color: #333;
font-size: 28rpx;
border-left: 6rpx solid #fff;
}
.catalog .nav .item.active {
color: #ab2b2b;
font-size: 36rpx;
border-left: 6rpx solid #ab2b2b;
}
.catalog .cate {
border-left: 1px solid #fafafa;
flex: 1;
height: 100%;
padding: 0 30rpx 0 30rpx;
}
.banner {
display: block;
height: 222rpx;
width: 100%;
position: relative;
}
.banner .image {
position: absolute;
top: 30rpx;
left: 0;
border-radius: 4rpx;
height: 192rpx;
width: 100%;
}
.banner .txt {
position: absolute;
top: 30rpx;
text-align: center;
color: #fff;
font-size: 28rpx;
left: 0;
height: 192rpx;
line-height: 192rpx;
width: 100%;
}
.catalog .hd {
height: 108rpx;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.catalog .hd .txt {
font-size: 24rpx;
text-align: center;
color: #333;
padding: 0 10rpx;
width: auto;
}
.catalog .hd .line {
width: 40rpx;
height: 1px;
background: #d9d9d9;
}
.catalog .bd {
height: auto;
width: 100%;
overflow: hidden;
}
.catalog .bd .item {
display: block;
float: left;
height: 216rpx;
width: 144rpx;
margin-right: 34rpx;
}
.catalog .bd .item.last {
margin-right: 0;
}
.catalog .bd .item .icon {
height: 144rpx;
width: 144rpx;
}
.catalog .bd .item .txt {
display: block;
text-align: center;
font-size: 24rpx;
color: #333;
height: 72rpx;
width: 144rpx;
}
================================================
FILE: pages/category/category.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
// text:"这是一个页面"
navList: [],
goodsList: [],
id: 0,
currentCategory: {},
scrollLeft: 0,
scrollTop: 0,
scrollHeight: 0,
page: 1,
size: 10000
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
var that = this;
if (options.id) {
that.setData({
id: parseInt(options.id)
});
}
wx.getSystemInfo({
success: function (res) {
that.setData({
scrollHeight: res.windowHeight
});
}
});
this.getCategoryInfo();
},
getCategoryInfo: function () {
let that = this;
util.request(api.GoodsCategory, { id: this.data.id })
.then(function (res) {
if (res.errno == 0) {
that.setData({
navList: res.data.brotherCategory,
currentCategory: res.data.currentCategory
});
//nav位置
let currentIndex = 0;
let navListCount = that.data.navList.length;
for (let i = 0; i < navListCount; i++) {
currentIndex += 1;
if (that.data.navList[i].id == that.data.id) {
break;
}
}
if (currentIndex > navListCount / 2 && navListCount > 5) {
that.setData({
scrollLeft: currentIndex * 60
});
}
that.getGoodsList();
} else {
//显示错误信息
}
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
console.log(1);
},
onHide: function () {
// 页面隐藏
},
getGoodsList: function () {
var that = this;
util.request(api.GoodsList, {categoryId: that.data.id, page: that.data.page, size: that.data.size})
.then(function (res) {
that.setData({
goodsList: res.data.goodsList,
});
});
},
onUnload: function () {
// 页面关闭
},
switchCate: function (event) {
if (this.data.id == event.currentTarget.dataset.id) {
return false;
}
var that = this;
var clientX = event.detail.x;
var currentTarget = event.currentTarget;
if (clientX < 60) {
that.setData({
scrollLeft: currentTarget.offsetLeft - 60
});
} else if (clientX > 330) {
that.setData({
scrollLeft: currentTarget.offsetLeft
});
}
this.setData({
id: event.currentTarget.dataset.id
});
this.getCategoryInfo();
}
})
================================================
FILE: pages/category/category.json
================================================
{}
================================================
FILE: pages/category/category.wxml
================================================
{{item.name}}
{{currentCategory.name}}
{{currentCategory.front_name}}
{{iitem.name}}
¥{{iitem.retail_price}}
================================================
FILE: pages/category/category.wxss
================================================
.container{
background: #f9f9f9;
}
.cate-nav{
position: fixed;
left:0;
top:0;
z-index: 1000;
}
.cate-nav-body{
height: 84rpx;
white-space: nowrap;
background: #fff;
border-top: 1px solid rgba(0,0,0,.15);
overflow: hidden;
}
.cate-nav .item{
display: inline-block;
height: 84rpx;
min-width: 130rpx;
padding: 0 15rpx;
}
.cate-nav .item .name{
display: block;
height: 84rpx;
padding: 0 20rpx;
line-height: 84rpx;
color: #333;
font-size: 30rpx;
width: auto;
}
.cate-nav .item.active .name{
color: #ab2b2b;
border-bottom: 2px solid #ab2b2b;
}
.cate-item{
margin-top: 94rpx;
height: auto;
overflow: hidden;
}
.cate-item .h{
height: 145rpx;
width: 750rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.cate-item .h .name{
display: block;
height: 35rpx;
margin-bottom: 18rpx;
font-size: 30rpx;
color: #333;
}
.cate-item .h .desc{
display: block;
height: 24rpx;
font-size: 24rpx;
color: #999;
}
.cate-item .b{
width: 750rpx;
padding: 0 6.25rpx;
height: auto;
overflow: hidden;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 365rpx;
margin-bottom: 6.25rpx;
padding-bottom: 33.333rpx;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
margin-left: 6.25rpx;
}
.cate-item .item .img{
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
overflow: hidden;
padding: 0 20rpx;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/comment/comment.js
================================================
var app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
comments: [],
allCommentList: [],
picCommentList: [],
typeId: 0,
valueId: 0,
showType: 0,
allCount: 0,
hasPicCount: 0,
allPage: 1,
picPage: 1,
size: 20
},
getCommentCount: function () {
let that = this;
util.request(api.CommentCount, { valueId: that.data.valueId, typeId: that.data.typeId}).then(function (res) {
if (res.errno === 0) {
that.setData({
allCount: res.data.allCount,
hasPicCount: res.data.hasPicCount
});
}
});
},
getCommentList: function(){
let that = this;
util.request(api.CommentList, {
valueId: that.data.valueId,
typeId: that.data.typeId,
size: that.data.size,
page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
showType: that.data.showType
}).then(function (res) {
if (res.errno === 0) {
if (that.data.showType == 0) {
that.setData({
allCommentList: that.data.allCommentList.concat(res.data.data),
allPage: res.data.currentPage,
comments: that.data.allCommentList.concat(res.data.data)
});
} else {
that.setData({
picCommentList: that.data.picCommentList.concat(res.data.data),
picPage: res.data.currentPage,
comments: that.data.picCommentList.concat(res.data.data)
});
}
}
});
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
typeId: options.typeId,
valueId: options.valueId
});
this.getCommentCount();
this.getCommentList();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
switchTab: function () {
this.setData({
showType: this.data.showType == 1 ? 0 :1
});
this.getCommentList();
},
onReachBottom: function(){
console.log('onPullDownRefresh');
if ( this.data.showType == 0) {
if (this.data.allCount / this.data.size < this.data.allPage) {
return false;
}
this.setData({
'allPage' : this.data.allPage + 1
});
} else {
if (this.data.hasPicCount / this.data.size < this.data.picPage) {
return false;
}
this.setData({
'picPage': this.data.picPage + 1
});
}
this.getCommentList();
}
})
================================================
FILE: pages/comment/comment.json
================================================
{
}
================================================
FILE: pages/comment/comment.wxml
================================================
全部({{allCount}})
有图({{hasPicCount}})
{{item.user_info.nickname}}
{{item.add_time}}
{{item.content}}
================================================
FILE: pages/comment/comment.wxss
================================================
.comments{
width: 100%;
height: auto;
padding-left:30rpx;
background: #fff;
margin: 20rpx 0;
}
.comments .h{
position: fixed;
left:0;
top:0;
z-index: 1000;
width: 100%;
display: flex;
background: #fff;
height: 84rpx;
border-bottom: 1px solid rgba(0,0,0,.15);
}
.comments .h .item{
display: inline-block;
height: 82rpx;
width: 50%;
padding: 0 15rpx;
text-align: center;
}
.comments .h .item .txt{
display: inline-block;
height: 82rpx;
padding: 0 20rpx;
line-height: 82rpx;
color: #333;
font-size: 30rpx;
width: 170rpx;
}
.comments .h .item.active .txt{
color: #ab2b2b;
border-bottom: 4rpx solid #ab2b2b;
}
.comments .b{
margin-top: 85rpx;
height: auto;
width: 720rpx;
}
.comments .b.no-h{
margin-top: 0;
}
.comments .item{
height: auto;
width: 720rpx;
overflow: hidden;
border-bottom: 1px solid #d9d9d9;
padding-bottom: 25rpx;
}
.comments .info{
height: 127rpx;
width: 100%;
padding: 33rpx 0 27rpx 0;
}
.comments .user{
float: left;
width: auto;
height: 67rpx;
line-height: 67rpx;
font-size: 0;
}
.comments .user image{
float: left;
width: 67rpx;
height: 67rpx;
margin-right: 17rpx;
border-radius: 50%;
}
.comments .user text{
display: inline-block;
width: auto;
height: 66rpx;
overflow: hidden;
font-size: 29rpx;
line-height: 66rpx;
}
.comments .time{
display: block;
float: right;
width: auto;
height: 67rpx;
line-height: 67rpx;
color: #7f7f7f;
font-size: 25rpx;
margin-right: 30rpx;
}
.comments .comment{
width: 720rpx;
padding-right: 30rpx;
line-height: 45.8rpx;
font-size: 29rpx;
margin-bottom: 16rpx;
}
.comments .imgs{
width: 720rpx;
height: 150rpx;
margin-bottom: 25rpx;
}
.comments .imgs .img{
height: 150rpx;
width: 150rpx;
margin-right: 28rpx;
}
.comments .spec{
width: 720rpx;
height: 25rpx;
font-size: 24rpx;
color: #999;
}
.comments .spec .item{
color: #7f7f7f;
font-size: 25rpx;
}
.comments .customer-service{
width: 690rpx;
height: auto;
overflow: hidden;
margin-top: 23rpx;
background: rgba(0,0,0,.03);
padding: 21rpx;
}
.comments .customer-service .u{
font-size: 24rpx;
color: #333;
line-height: 37.5rpx;
}
.comments .customer-service .c{
font-size: 24rpx;
color: #999;
line-height: 37.5rpx;
}
================================================
FILE: pages/commentPost/commentPost.js
================================================
var app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
typeId: 0,
valueId: 0,
content: ''
},
onLoad: function (options) {
var that = this;
that.setData({
typeId: parseInt(options.typeId),
valueId: parseInt(options.valueId)
});
},
onClose() {
wx.navigateBack({
delta: 1
});
},
onPost() {
let that = this;
if (!this.data.content) {
util.showErrorToast('请填写评论')
return false;
}
util.request(api.CommentPost, {
typeId: that.data.typeId,
valueId: that.data.valueId,
content: that.data.content
}, 'POST').then(function (res) {
if (res.errno === 0) {
wx.showToast({
title: '评论成功',
complete: function(){
wx.navigateBack({
delta: 1
});
}
})
}
console.log(res)
});
},
bindInpuntValue(event){
let value = event.detail.value;
//判断是否超过140个字符
if (value && value.length > 140) {
return false;
}
this.setData({
content: event.detail.value,
})
console.log(event.detail)
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/commentPost/commentPost.json
================================================
{
"navigationBarTitleText": "填写留言"
}
================================================
FILE: pages/commentPost/commentPost.wxml
================================================
{{140 - content.length}}
取消
发表
================================================
FILE: pages/commentPost/commentPost.wxss
================================================
page, .container {
height: 100%;
background: #f4f4f4;
}
.post-comment {
width: 750rpx;
height: auto;
overflow: hidden;
padding: 30rpx;
}
.post-comment .input-box {
height: 337.5rpx;
width: 690rpx;
position: relative;
background: #fff;
}
.post-comment .input-box .content {
position: absolute;
top: 0;
left: 0;
display: block;
background: #fff;
font-size: 29rpx;
color: #333;
height: 300rpx;
width: 650rpx;
padding: 20rpx;
}
.post-comment .input-box .count {
position: absolute;
bottom: 20rpx;
right: 20rpx;
display: block;
height: 30rpx;
width: 50rpx;
font-size: 29rpx;
color: #999;
}
.post-comment .btns {
height: 108rpx;
}
.post-comment .close {
float: left;
height: 108rpx;
line-height: 108rpx;
text-align: left;
color: #666;
padding: 0 30rpx;
}
.post-comment .post {
float: right;
height: 108rpx;
line-height: 108rpx;
text-align: right;
padding: 0 30rpx;
}
================================================
FILE: pages/goods/goods.js
================================================
var app = getApp();
var WxParse = require('../../lib/wxParse/wxParse.js');
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
id: 0,
goods: {},
gallery: [],
attribute: [],
issueList: [],
comment: [],
brand: {},
specificationList: [],
productList: [],
relatedGoods: [],
cartGoodsCount: 0,
userHasCollect: 0,
number: 1,
checkedSpecText: '请选择规格数量',
openAttr: false,
noCollectImage: "/static/images/icon_collect.png",
hasCollectImage: "/static/images/icon_collect_checked.png",
collectBackImage: "/static/images/icon_collect.png"
},
getGoodsInfo: function () {
let that = this;
util.request(api.GoodsDetail, { id: that.data.id }).then(function (res) {
if (res.errno === 0) {
that.setData({
goods: res.data.info,
gallery: res.data.gallery,
attribute: res.data.attribute,
issueList: res.data.issue,
comment: res.data.comment,
brand: res.data.brand,
specificationList: res.data.specificationList,
productList: res.data.productList,
userHasCollect: res.data.userHasCollect
});
if (res.data.userHasCollect == 1) {
that.setData({
'collectBackImage': that.data.hasCollectImage
});
} else {
that.setData({
'collectBackImage': that.data.noCollectImage
});
}
WxParse.wxParse('goodsDetail', 'html', res.data.info.goods_desc, that);
that.getGoodsRelated();
}
});
},
getGoodsRelated: function () {
let that = this;
util.request(api.GoodsRelated, { id: that.data.id }).then(function (res) {
if (res.errno === 0) {
that.setData({
relatedGoods: res.data.goodsList,
});
}
});
},
clickSkuValue: function (event) {
let that = this;
let specNameId = event.currentTarget.dataset.nameId;
let specValueId = event.currentTarget.dataset.valueId;
//判断是否可以点击
//TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
let _specificationList = this.data.specificationList;
for (let i = 0; i < _specificationList.length; i++) {
if (_specificationList[i].specification_id == specNameId) {
for (let j = 0; j < _specificationList[i].valueList.length; j++) {
if (_specificationList[i].valueList[j].id == specValueId) {
//如果已经选中,则反选
if (_specificationList[i].valueList[j].checked) {
_specificationList[i].valueList[j].checked = false;
} else {
_specificationList[i].valueList[j].checked = true;
}
} else {
_specificationList[i].valueList[j].checked = false;
}
}
}
}
this.setData({
'specificationList': _specificationList
});
//重新计算spec改变后的信息
this.changeSpecInfo();
//重新计算哪些值不可以点击
},
//获取选中的规格信息
getCheckedSpecValue: function () {
let checkedValues = [];
let _specificationList = this.data.specificationList;
for (let i = 0; i < _specificationList.length; i++) {
let _checkedObj = {
nameId: _specificationList[i].specification_id,
valueId: 0,
valueText: ''
};
for (let j = 0; j < _specificationList[i].valueList.length; j++) {
if (_specificationList[i].valueList[j].checked) {
_checkedObj.valueId = _specificationList[i].valueList[j].id;
_checkedObj.valueText = _specificationList[i].valueList[j].value;
}
}
checkedValues.push(_checkedObj);
}
return checkedValues;
},
//根据已选的值,计算其它值的状态
setSpecValueStatus: function () {
},
//判断规格是否选择完整
isCheckedAllSpec: function () {
return !this.getCheckedSpecValue().some(function (v) {
if (v.valueId == 0) {
return true;
}
});
},
getCheckedSpecKey: function () {
let checkedValue = this.getCheckedSpecValue().map(function (v) {
return v.valueId;
});
return checkedValue.join('_');
},
changeSpecInfo: function () {
let checkedNameValue = this.getCheckedSpecValue();
//设置选择的信息
let checkedValue = checkedNameValue.filter(function (v) {
if (v.valueId != 0) {
return true;
} else {
return false;
}
}).map(function (v) {
return v.valueText;
});
if (checkedValue.length > 0) {
this.setData({
'checkedSpecText': checkedValue.join(' ')
});
} else {
this.setData({
'checkedSpecText': '请选择规格数量'
});
}
},
getCheckedProductItem: function (key) {
return this.data.productList.filter(function (v) {
if (v.goods_specification_ids == key) {
return true;
} else {
return false;
}
});
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
id: parseInt(options.id)
// id: 1181000
});
var that = this;
this.getGoodsInfo();
util.request(api.CartGoodsCount).then(function (res) {
if (res.errno === 0) {
that.setData({
cartGoodsCount: res.data.cartTotal.goodsCount
});
}
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
switchAttrPop: function () {
if (this.data.openAttr == false) {
this.setData({
openAttr: !this.data.openAttr
});
}
},
closeAttr: function () {
this.setData({
openAttr: false,
});
},
addCannelCollect: function () {
let that = this;
//添加或是取消收藏
util.request(api.CollectAddOrDelete, { typeId: 0, valueId: this.data.id }, "POST")
.then(function (res) {
let _res = res;
if (_res.errno == 0) {
if (_res.data.type == 'add') {
that.setData({
'collectBackImage': that.data.hasCollectImage
});
} else {
that.setData({
'collectBackImage': that.data.noCollectImage
});
}
} else {
wx.showToast({
image: '/static/images/icon_error.png',
title: _res.errmsg,
mask: true
});
}
});
},
openCartPage: function () {
wx.switchTab({
url: '/pages/cart/cart',
});
},
addToCart: function () {
var that = this;
if (this.data.openAttr === false) {
//打开规格选择窗口
this.setData({
openAttr: !this.data.openAttr
});
} else {
//提示选择完整规格
if (!this.isCheckedAllSpec()) {
wx.showToast({
image: '/static/images/icon_error.png',
title: '请选择规格',
mask: true
});
return false;
}
//根据选中的规格,判断是否有对应的sku信息
let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey());
if (!checkedProduct || checkedProduct.length <= 0) {
//找不到对应的product信息,提示没有库存
wx.showToast({
image: '/static/images/icon_error.png',
title: '库存不足',
mask: true
});
return false;
}
//验证库存
if (checkedProduct.goods_number < this.data.number) {
//找不到对应的product信息,提示没有库存
wx.showToast({
image: '/static/images/icon_error.png',
title: '库存不足',
mask: true
});
return false;
}
//添加到购物车
util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST")
.then(function (res) {
let _res = res;
if (_res.errno == 0) {
wx.showToast({
title: '添加成功'
});
that.setData({
openAttr: !that.data.openAttr,
cartGoodsCount: _res.data.cartTotal.goodsCount
});
} else {
wx.showToast({
image: '/static/images/icon_error.png',
title: _res.errmsg,
mask: true
});
}
});
}
},
cutNumber: function () {
this.setData({
number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
});
},
addNumber: function () {
this.setData({
number: this.data.number + 1
});
}
})
================================================
FILE: pages/goods/goods.json
================================================
{}
================================================
FILE: pages/goods/goods.wxml
================================================
30天无忧退货
48小时快速退款
满88元免邮费
{{goods.name}}
{{goods.goods_brief}}
¥{{goods.retail_price}}
{{brand.name}}
请选择规格数量
评价({{comment.count > 999 ? '999+' : comment.count}})
查看全部
{{comment.data.nickname}}
{{comment.data.add_time}}
{{comment.data.content}}
商品参数
{{item.name}}
{{item.value}}
常见问题
{{item.question}}
{{item.answer}}
大家都在看
{{item.name}}
¥{{item.retail_price}}
价格:¥{{goods.retail_price}}
已选择:{{checkedSpecText}}
{{item.name}}
{{vitem.value}}
数量
-
+
{{cartGoodsCount}}
立即购买
加入购物车
================================================
FILE: pages/goods/goods.wxss
================================================
.container {
margin-bottom: 100rpx;
}
.goodsimgs {
width: 750rpx;
height: 750rpx;
}
.goodsimgs image {
width: 750rpx;
height: 750rpx;
}
.service-policy {
width: 750rpx;
height: 73rpx;
background: #f4f4f4;
padding: 0 31.25rpx;
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: space-between;
}
.service-policy .item {
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/servicePolicyRed-518d32d74b.png) 0 center no-repeat;
background-size: 10rpx;
padding-left: 15rpx;
display: flex;
align-items: center;
font-size: 25rpx;
color: #666;
}
.goods-info {
width: 750rpx;
height: 306rpx;
overflow: hidden;
background: #fff;
}
.goods-info .c {
display: block;
width: 718.75rpx;
height: 100%;
margin-left: 31.25rpx;
padding: 38rpx 31.25rpx 38rpx 0;
border-bottom: 1px solid #f4f4f4;
}
.goods-info .c text {
display: block;
width: 687.5rpx;
text-align: center;
}
.goods-info .name {
height: 41rpx;
margin-bottom: 5.208rpx;
font-size: 41rpx;
line-height: 41rpx;
}
.goods-info .desc {
height: 43rpx;
margin-bottom: 41rpx;
font-size: 24rpx;
line-height: 36rpx;
color: #999;
}
.goods-info .price {
height: 35rpx;
font-size: 35rpx;
line-height: 35rpx;
color: #b4282d;
}
.goods-info .brand {
margin-top: 23rpx;
min-height: 40rpx;
text-align: center;
}
.goods-info .brand text {
display: inline-block;
width: auto;
padding: 2px 30rpx 2px 10.5rpx;
line-height: 35.5rpx;
border: 1px solid #f48f18;
font-size: 25rpx;
color: #f48f18;
border-radius: 4px;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/detailTagArrow-18bee52dab.png) 95% center no-repeat;
background-size: 10.75rpx 18.75rpx;
}
.section-nav {
width: 750rpx;
height: 108rpx;
background: #fff;
margin-bottom: 20rpx;
}
.section-nav .t {
float: left;
width: 600rpx;
height: 108rpx;
line-height: 108rpx;
font-size: 29rpx;
color: #333;
margin-left: 31.25rpx;
}
.section-nav .i {
float: right;
width: 52rpx;
height: 52rpx;
margin-right: 16rpx;
margin-top: 28rpx;
}
.section-act .t {
float: left;
display: flex;
align-items: center;
width: 600rpx;
height: 108rpx;
overflow: hidden;
line-height: 108rpx;
font-size: 29rpx;
color: #999;
margin-left: 31.25rpx;
}
.section-act .label {
color: #999;
}
.section-act .tag {
display: flex;
align-items: center;
padding: 0 10rpx;
border-radius: 3px;
height: 37rpx;
width: auto;
color: #f48f18;
overflow: hidden;
border: 1px solid #f48f18;
font-size: 25rpx;
margin: 0 10rpx;
}
.section-act .text {
display: flex;
align-items: center;
height: 37rpx;
width: auto;
overflow: hidden;
color: #f48f18;
font-size: 29rpx;
}
.comments {
width: 100%;
height: auto;
padding-left: 30rpx;
background: #fff;
margin: 20rpx 0;
}
.comments .h {
height: 102.5rpx;
line-height: 100.5rpx;
width: 718.75rpx;
padding-right: 16rpx;
border-bottom: 1px solid #d9d9d9;
}
.comments .h .t {
display: block;
float: left;
width: 50%;
font-size: 38.5rpx;
color: #333;
}
.comments .h .i {
display: block;
float: right;
width: 164rpx;
height: 100.5rpx;
line-height: 100.5rpx;
background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/address-right-990628faa7.png) right center no-repeat;
background-size: 52rpx;
}
.comments .b {
height: auto;
width: 720rpx;
}
.comments .item {
height: auto;
width: 720rpx;
overflow: hidden;
}
.comments .info {
height: 127rpx;
width: 100%;
padding: 33rpx 0 27rpx 0;
}
.comments .user {
float: left;
width: auto;
height: 67rpx;
line-height: 67rpx;
font-size: 0;
}
.comments .user image {
float: left;
width: 67rpx;
height: 67rpx;
margin-right: 17rpx;
border-radius: 50%;
}
.comments .user text {
display: inline-block;
width: auto;
height: 66rpx;
overflow: hidden;
font-size: 29rpx;
line-height: 66rpx;
}
.comments .time {
display: block;
float: right;
width: auto;
height: 67rpx;
line-height: 67rpx;
color: #7f7f7f;
font-size: 25rpx;
margin-right: 30rpx;
}
.comments .content {
width: 720rpx;
padding-right: 30rpx;
line-height: 45.8rpx;
font-size: 29rpx;
margin-bottom: 24rpx;
}
.comments .imgs {
width: 720rpx;
height: auto;
margin-bottom: 25rpx;
}
.comments .imgs .img {
height: 150rpx;
width: 150rpx;
margin-right: 28rpx;
}
.comments .spec {
width: 720rpx;
padding-right: 30rpx;
line-height: 30rpx;
font-size: 24rpx;
color: #999;
margin-bottom: 30rpx;
}
.goods-attr {
width: 750rpx;
height: auto;
overflow: hidden;
padding: 0 31.25rpx 25rpx 31.25rpx;
background: #fff;
}
.goods-attr .t {
width: 687.5rpx;
height: 104rpx;
line-height: 104rpx;
font-size: 38.5rpx;
}
.goods-attr .item {
width: 687.5rpx;
height: 68rpx;
padding: 11rpx 20rpx;
margin-bottom: 11rpx;
background: #f7f7f7;
font-size: 38.5rpx;
}
.goods-attr .left {
float: left;
font-size: 25rpx;
width: 134rpx;
height: 45rpx;
line-height: 45rpx;
overflow: hidden;
color: #999;
}
.goods-attr .right {
float: left;
font-size: 36.5rpx;
margin-left: 20rpx;
width: 480rpx;
height: 45rpx;
line-height: 45rpx;
overflow: hidden;
color: #333;
}
.detail {
width: 750rpx;
height: auto;
overflow: hidden;
}
.detail image {
width: 750rpx;
display: block;
}
.common-problem {
width: 750rpx;
height: auto;
overflow: hidden;
}
.common-problem .h {
position: relative;
height: 145.5rpx;
width: 750rpx;
padding: 56.25rpx 0;
background: #fff;
text-align: center;
}
.common-problem .h .line {
display: inline-block;
position: absolute;
top: 72rpx;
left: 0;
z-index: 2;
height: 1px;
margin-left: 225rpx;
width: 300rpx;
background: #ccc;
}
.common-problem .h .title {
display: inline-block;
position: absolute;
top: 56.125rpx;
left: 0;
z-index: 3;
height: 33rpx;
margin-left: 285rpx;
width: 180rpx;
background: #fff;
}
.common-problem .b {
width: 750rpx;
height: auto;
overflow: hidden;
padding: 0rpx 30rpx;
background: #fff;
}
.common-problem .item {
height: auto;
overflow: hidden;
padding-bottom: 25rpx;
}
.common-problem .question-box .spot {
float: left;
display: block;
height: 8rpx;
width: 8rpx;
background: #b4282d;
border-radius: 50%;
margin-top: 11rpx;
}
.common-problem .question-box .question {
float: left;
line-height: 30rpx;
padding-left: 8rpx;
display: block;
font-size: 26rpx;
padding-bottom: 15rpx;
color: #303030;
}
.common-problem .answer {
line-height: 36rpx;
padding-left: 16rpx;
font-size: 26rpx;
color: #787878;
}
.related-goods {
width: 750rpx;
height: auto;
overflow: hidden;
}
.related-goods .h {
position: relative;
height: 145.5rpx;
width: 750rpx;
padding: 56.25rpx 0;
background: #fff;
text-align: center;
border-bottom: 1px solid #f4f4f4;
}
.related-goods .h .line {
display: inline-block;
position: absolute;
top: 72rpx;
left: 0;
z-index: 2;
height: 1px;
margin-left: 225rpx;
width: 300rpx;
background: #ccc;
}
.related-goods .h .title {
display: inline-block;
position: absolute;
top: 56.125rpx;
left: 0;
z-index: 3;
height: 33rpx;
margin-left: 285rpx;
width: 180rpx;
background: #fff;
}
.related-goods .b {
width: 750rpx;
height: auto;
overflow: hidden;
}
.related-goods .b .item {
float: left;
background: #fff;
width: 375rpx;
height: auto;
overflow: hidden;
text-align: center;
padding: 15rpx 31.25rpx;
border-right: 1px solid #f4f4f4;
border-bottom: 1px solid #f4f4f4;
}
.related-goods .item .img {
width: 311.45rpx;
height: 311.45rpx;
}
.related-goods .item .name {
display: block;
width: 311.45rpx;
height: 35rpx;
margin: 11.5rpx 0 15rpx 0;
text-align: center;
overflow: hidden;
font-size: 30rpx;
color: #333;
}
.related-goods .item .price {
display: block;
width: 311.45rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
.bottom-btn {
position: fixed;
left: 0;
bottom: 0;
z-index: 10;
width: 750rpx;
height: 100rpx;
display: flex;
background: #fff;
}
.bottom-btn .l {
float: left;
height: 100rpx;
width: 162rpx;
border: 1px solid #f4f4f4;
display: flex;
align-items: center;
justify-content: center;
}
.bottom-btn .l.l-collect {
border-right: none;
border-left: none;
text-align: center;
}
.bottom-btn .l.l-cart .box {
position: relative;
height: 60rpx;
width: 60rpx;
}
.bottom-btn .l.l-cart .cart-count {
height: 28rpx;
width: 28rpx;
z-index: 10;
position: absolute;
top: 0;
right: 0;
background: #b4282d;
text-align: center;
font-size: 18rpx;
color: #fff;
line-height: 28rpx;
border-radius: 50%;
}
.bottom-btn .l.l-cart .icon {
position: absolute;
top: 10rpx;
left: 0;
}
.bottom-btn .l .icon {
display: block;
height: 44rpx;
width: 44rpx;
}
.bottom-btn .c {
float: left;
height: 100rpx;
line-height: 96rpx;
flex: 1;
text-align: center;
color: #333;
border-top: 1px solid #f4f4f4;
border-bottom: 1px solid #f4f4f4;
}
.bottom-btn .r {
border: 1px solid #b4282d;
background: #b4282d;
float: left;
height: 100rpx;
line-height: 96rpx;
flex: 1;
text-align: center;
color: #fff;
}
@import "../../lib/wxParse/wxParse.wxss";
.attr-pop-box {
width: 100%;
height: 100%;
position: fixed;
background: rgba(0, 0, 0, .5);
z-index: 8;
bottom: 0;
/* display: none; */
}
.attr-pop {
width: 100%;
height: auto;
max-height: 780rpx;
padding: 31.25rpx;
background: #fff;
position: fixed;
z-index: 9;
bottom: 100rpx;
}
.attr-pop .close {
position: absolute;
width: 48rpx;
height: 48rpx;
right: 31.25rpx;
overflow: hidden;
top: 31.25rpx;
}
.attr-pop .close .icon {
width: 48rpx;
height: 48rpx;
}
.attr-pop .img-info {
width: 687.5rpx;
height: 177rpx;
overflow: hidden;
margin-bottom: 41.5rpx;
}
.attr-pop .img {
float: left;
height: 177rpx;
width: 177rpx;
background: #f4f4f4;
margin-right: 31.25rpx;
}
.attr-pop .info {
float: left;
height: 177rpx;
display: flex;
align-items: center;
}
.attr-pop .p {
font-size: 33rpx;
color: #333;
height: 33rpx;
line-height: 33rpx;
margin-bottom: 10rpx;
}
.attr-pop .a {
font-size: 29rpx;
color: #333;
height: 40rpx;
line-height: 40rpx;
}
.spec-con {
width: 100%;
height: auto;
overflow: hidden;
}
.spec-con .name {
height: 32rpx;
margin-bottom: 22rpx;
font-size: 29rpx;
color: #333;
}
.spec-con .values {
height: auto;
margin-bottom: 31.25rpx;
font-size: 0;
}
.spec-con .value {
display: inline-block;
height: 62rpx;
padding: 0 35rpx;
line-height: 56rpx;
text-align: center;
margin-right: 25rpx;
margin-bottom: 16.5rpx;
border: 1px solid #333;
font-size: 25rpx;
color: #333;
}
.spec-con .value.disable {
border: 1px solid #ccc;
color: #ccc;
}
.spec-con .value.selected {
border: 1px solid #b4282d;
color: #b4282d;
}
.number-item .selnum {
width: 322rpx;
height: 71rpx;
border: 1px solid #ccc;
display: flex;
}
.number-item .cut {
width: 93.75rpx;
height: 100%;
text-align: center;
line-height: 65rpx;
}
.number-item .number {
flex: 1;
height: 100%;
text-align: center;
line-height: 68.75rpx;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
float: left;
}
.number-item .add {
width: 93.75rpx;
height: 100%;
text-align: center;
line-height: 65rpx;
}
================================================
FILE: pages/hotGoods/hotGoods.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
bannerInfo: {
'img_url': '',
'name': ''
},
categoryFilter: false,
filterCategory: [],
goodsList: [],
categoryId: 0,
currentSortType: 'default',
currentSortOrder: 'desc',
page: 1,
size: 1000
},
getData: function () {
let that = this;
util.request(api.GoodsHot).then(function (res) {
if (res.errno === 0) {
that.setData({
bannerInfo: res.data.bannerInfo,
});
that.getGoodsList();
}
});
},
getGoodsList (){
var that = this;
util.request(api.GoodsList, { isHot: 1, page: that.data.page, size: that.data.size, order: that.data.currentSortOrder, sort: that.data.currentSortType, categoryId: that.data.categoryId})
.then(function (res) {
if (res.errno === 0) {
that.setData({
goodsList: res.data.goodsList,
filterCategory: res.data.filterCategory
});
}
});
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getData();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
openSortFilter: function (event) {
let currentId = event.currentTarget.id;
switch (currentId) {
case 'categoryFilter':
this.setData({
'categoryFilter': !this.data.categoryFilter,
'currentSortType': 'category',
'currentSortOrder': 'asc'
});
break;
case 'priceSort':
let tmpSortOrder = 'asc';
if (this.data.currentSortOrder == 'asc') {
tmpSortOrder = 'desc';
}
this.setData({
'currentSortType': 'price',
'currentSortOrder': tmpSortOrder,
'categoryFilter': false
});
this.getData();
break;
default:
//综合排序
this.setData({
'currentSortType': 'default',
'currentSortOrder': 'desc',
'categoryFilter': false
});
this.getData();
}
},
selectCategory: function(event){
let currentIndex = event.target.dataset.categoryIndex;
this.setData({
'categoryFilter': false,
'categoryId': this.data.filterCategory[currentIndex].id
});
this.getData();
}
})
================================================
FILE: pages/hotGoods/hotGoods.json
================================================
{
}
================================================
FILE: pages/hotGoods/hotGoods.wxml
================================================
{{bannerInfo.name}}
综合
价格
分类
{{item.name}}
{{iitem.name}}
¥{{iitem.retail_price}}
================================================
FILE: pages/hotGoods/hotGoods.wxss
================================================
page{
background: #f4f4f4;
}
.brand-info .name{
width: 100%;
height: 278rpx;
position: relative;
}
.brand-info .img{
position: absolute;
top:0;
left:0;
width: 100%;
height: 278rpx;
}
.brand-info .info-box{
position: absolute;
top:0;
left:0;
width: 100%;
height: 278rpx;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.brand-info .info{
display: block;
}
.brand-info .txt{
display: block;
height: 40rpx;
font-size: 37.5rpx;
color: #fff;
}
.brand-info .line{
margin: 0 auto;
margin-top: 16rpx;
display: block;
height: 2rpx;
width: 145rpx;
background: #fff;
}
.sort{
position: relative;
background: #fff;
width: 100%;
height: 78rpx;
}
.sort-box{
background: #fff;
width: 100%;
height: 78rpx;
overflow: hidden;
padding: 0 30rpx;
display: flex;
border-bottom: 1px solid #d9d9d9;
}
.sort-box .item{
height: 78rpx;
line-height: 78rpx;
text-align: center;
flex:1;
color: #333;
font-size: 30rpx;
}
.sort-box .item .txt{
display: block;
width: 100%;
height: 100%;
color: #333;
}
.sort-box .item.active .txt{
color: #b4282d;
}
.sort-box .item.by-price{
background: url(//yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/no-3127092a69.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box .item.by-price.active.asc{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/up-636b92c0a5.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box .item.by-price.active.desc{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/down-95e035f3e5.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box-category{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
padding: 40rpx 40rpx 0 0;
border-bottom: 1px solid #d9d9d9;
}
.sort-box-category .item{
height: 54rpx;
line-height: 54rpx;
text-align: center;
float: left;
padding: 0 16rpx;
margin: 0 0 40rpx 40rpx;
border: 1px solid #666;
color: #333;
font-size: 24rpx;
}
.sort-box-category .item.active{
color: #b4282d;
border: 1px solid #b4282d;
}
.cate-item .b{
width: 750rpx;
height: auto;
overflow: hidden;
border-top: 1rpx solid #f4f4f4;
margin-top: 20rpx;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 375rpx;
padding-bottom: 33.333rpx;
border-bottom: 1rpx solid #f4f4f4;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
border-right: 1rpx solid #f4f4f4;
}
.cate-item .item .img{
margin-top: 10rpx;
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
padding: 0 20rpx;
overflow: hidden;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/index/index.js
================================================
const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');
//获取应用实例
const app = getApp()
Page({
data: {
goodsCount: 0,
newGoods: [],
hotGoods: [],
topics: [],
brands: [],
floorGoods: [],
banner: [],
channel: []
},
onShareAppMessage: function () {
return {
title: 'NideShop',
desc: '仿网易严选微信小程序商城',
path: '/pages/index/index'
}
},
getIndexData: function () {
let that = this;
util.request(api.IndexUrl).then(function (res) {
if (res.errno === 0) {
that.setData({
newGoods: res.data.newGoodsList,
hotGoods: res.data.hotGoodsList,
topics: res.data.topicList,
brand: res.data.brandList,
floorGoods: res.data.categoryList,
banner: res.data.banner,
channel: res.data.channel
});
}
});
},
onLoad: function (options) {
this.getIndexData();
util.request(api.GoodsCount).then(res => {
this.setData({
goodsCount: res.data.goodsCount
});
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
})
================================================
FILE: pages/index/index.json
================================================
{}
================================================
FILE: pages/index/index.wxml
================================================
商品搜索, 共{{goodsCount}}款好物
{{item.name}}
品牌制造商直供
{{item.name}}
{{item.floor_price}}
元起
周一周四 · 新品首发
{{item.name}}
¥{{item.retail_price}}
人气推荐
{{item.name}}
{{item.goods_brief}}
¥{{item.retail_price}}
专题精选
{{item.title}}
¥{{item.price_info}}元起
{{item.subtitle}}
{{item.name}}
{{iitem.name}}
¥{{iitem.retail_price}}
================================================
FILE: pages/index/index.wxss
================================================
.search {
height: 88rpx;
width: 100%;
padding: 0 30rpx;
background: #fff;
display: flex;
align-items: center;
}
.search .input {
width: 690rpx;
height: 56rpx;
background: #ededed;
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
}
.search .icon {
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png) center no-repeat;
background-size: 100%;
width: 28rpx;
height: 28rpx;
}
.search .txt {
height: 42rpx;
line-height: 42rpx;
color: #666;
padding-left: 10rpx;
font-size: 30rpx;
}
.banner {
width: 750rpx;
height: 417rpx;
}
.banner image {
width: 100%;
height: 417rpx;
}
.m-menu {
display: flex;
height: 181rpx;
width: 750rpx;
flex-flow: row nowrap;
align-items: center;
justify-content: space-between;
background-color: #fff;
}
.m-menu .item {
flex: 1;
display: block;
padding: 20rpx 0;
}
.m-menu image {
display: block;
width: 58rpx;
height: 58rpx;
margin: 0 auto;
margin-bottom: 12rpx;
}
.m-menu text {
display: block;
font-size: 24rpx;
text-align: center;
margin: 0 auto;
line-height: 1;
color: #333;
}
.a-section {
width: 750rpx;
height: auto;
overflow: hidden;
background: #fff;
color: #333;
margin-top: 20rpx;
}
.a-section .h {
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: center;
height: 130rpx;
}
.a-section .h .txt {
padding-right: 30rpx;
background: url("http://ac-3yr0g9cz.clouddn.com/2cdba05369e10f934e54.png") right 4rpx no-repeat;
background-size: 16.656rpx 27rpx;
display: inline-block;
height: 36rpx;
font-size: 33rpx;
line-height: 36rpx;
}
.a-brand .b {
width: 750rpx;
height: auto;
overflow: hidden;
position: relative;
}
.a-brand .wrap {
position: relative;
}
.a-brand .img {
position: absolute;
left: 0;
top: 0;
}
.a-brand .mt {
position: absolute;
z-index: 2;
padding: 27rpx 31rpx;
left: 0;
top: 0;
}
.a-brand .mt .brand {
display: block;
font-size: 33rpx;
height: 43rpx;
color: #333;
}
.a-brand .mt .price, .a-brand .mt .unit {
font-size: 25rpx;
color: #999;
}
.a-brand .item-1 {
float: left;
width: 375rpx;
height: 252rpx;
overflow: hidden;
border-top: 1rpx solid #fff;
margin-left: 1rpx;
}
.a-brand .item-1:nth-child(2n+1){
margin-left: 0;
width: 374rpx;
}
.a-brand .item-1 .img {
width: 375rpx;
height: 253rpx;
}
.a-new .b {
width: 750rpx;
height: auto;
overflow: hidden;
padding: 0 31rpx 45rpx 31rpx;
}
.a-new .b .item {
float: left;
width: 302rpx;
margin-top: 10rpx;
margin-left: 21rpx;
margin-right: 21rpx;
}
.a-new .b .item-b {
margin-left: 42rpx;
}
.a-new .b .img {
width: 302rpx;
height: 302rpx;
}
.a-new .b .name {
text-align: center;
display: block;
width: 302rpx;
height: 35rpx;
margin-bottom: 14rpx;
overflow: hidden;
font-size: 30rpx;
color: #333;
}
.a-new .b .price {
display: block;
text-align: center;
line-height: 30rpx;
font-size: 30rpx;
color: #b4282d;
}
.a-popular {
width: 750rpx;
height: auto;
overflow: hidden;
}
.a-popular .b .item {
border-top: 1px solid #d9d9d9;
margin: 0 20rpx;
height: 264rpx;
width: 710rpx;
}
.a-popular .b .img {
margin-top: 12rpx;
margin-right: 12rpx;
float: left;
width: 240rpx;
height: 240rpx;
}
.a-popular .b .right {
float: left;
height: 264rpx;
width: 456rpx;
display: flex;
flex-flow: row nowrap;
}
.a-popular .b .text {
display: flex;
flex-wrap: nowrap;
flex-direction: column;
justify-content: center;
overflow: hidden;
height: 264rpx;
width: 456rpx;
}
.a-popular .b .name {
width: 456rpx;
display: block;
color: #333;
line-height: 50rpx;
font-size: 30rpx;
}
.a-popular .b .desc {
width: 456rpx;
display: block;
color: #999;
line-height: 50rpx;
font-size: 25rpx;
}
.a-popular .b .price {
width: 456rpx;
display: block;
color: #b4282d;
line-height: 50rpx;
font-size: 33rpx;
}
.a-topic .b {
height: 533rpx;
width: 750rpx;
padding: 0 0 48rpx 0;
}
.a-topic .b .list {
height: 533rpx;
width: 750rpx;
white-space: nowrap;
}
.a-topic .b .item {
display: inline-block;
height: 533rpx;
width: 680.5rpx;
margin-left: 30rpx;
overflow: hidden;
}
.a-topic .b .item:last-child {
margin-right: 30rpx;
}
.a-topic .b .img {
height: 387.5rpx;
width: 680.5rpx;
margin-bottom: 30rpx;
}
.a-topic .b .np {
height: 35rpx;
margin-bottom: 13.5rpx;
color: #333;
font-size: 30rpx;
}
.a-topic .b .np .price {
margin-left: 20.8rpx;
color: #b4282d;
}
.a-topic .b .desc {
display: block;
height: 30rpx;
color: #999;
font-size: 24rpx;
white-space: nowrap;
overflow: hidden;
text-overflow:ellipsis;
}
.good-grid {
width: 750rpx;
height: auto;
overflow: hidden;
background: #fff;
margin-top: 20rpx;
}
.good-grid .h {
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: center;
height: 130rpx;
font-size: 33rpx;
color: #333;
}
.good-grid .b {
width: 750rpx;
height: auto;
overflow: hidden;
padding: 0 20rpx;
}
.good-grid .b .item {
display: block;
float: left;
width: 345rpx;
margin-bottom: 30rpx;
height: auto;
overflow: hidden;
text-align: center;
}
.good-grid .b .item:nth-child(2n + 1) {
margin-right: 20rpx;
}
.good-grid .item .img {
width: 345rpx;
height: 345rpx;
background: #f8f8f8;
margin-bottom: 10rpx;
}
.good-grid .item .name {
width: 100%;
overflow: hidden;
height: 40rpx;
line-height: 40rpx;
text-align: center;
font-size: 30rpx;
color: #333;
}
.good-grid .item .price {
width: 100%;
height: 46rpx;
line-height: 46rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/logs/logs.js
================================================
//logs.js
var util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(function (log) {
return util.formatTime(new Date(log))
})
})
}
})
================================================
FILE: pages/logs/logs.json
================================================
{
"navigationBarTitleText": "查看启动日志"
}
================================================
FILE: pages/logs/logs.wxml
================================================
{{index + 1}}. {{log}}
================================================
FILE: pages/logs/logs.wxss
================================================
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
================================================
FILE: pages/newGoods/newGoods.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp();
Page({
data: {
bannerInfo: {
'img_url': '',
'name': ''
},
categoryFilter: false,
filterCategory: [],
goodsList: [],
categoryId: 0,
currentSortType: 'default',
currentSortOrder: 'desc',
page: 1,
size: 1000
},
getData: function () {
let that = this;
util.request(api.GoodsHot).then(function (res) {
if (res.errno === 0) {
that.setData({
bannerInfo: res.data.bannerInfo,
});
that.getGoodsList();
}
});
},
getGoodsList() {
var that = this;
util.request(api.GoodsList, { isNew: 1, page: that.data.page, size: that.data.size, order: that.data.currentSortOrder, sort: that.data.currentSortType, categoryId: that.data.categoryId })
.then(function (res) {
if (res.errno === 0) {
that.setData({
goodsList: res.data.goodsList,
filterCategory: res.data.filterCategory
});
}
});
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getData();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
openSortFilter: function (event) {
let currentId = event.currentTarget.id;
switch (currentId) {
case 'categoryFilter':
this.setData({
'categoryFilter': !this.data.categoryFilter,
'currentSortType': 'category',
'currentSortOrder': 'asc'
});
break;
case 'priceSort':
let tmpSortOrder = 'asc';
if (this.data.currentSortOrder == 'asc') {
tmpSortOrder = 'desc';
}
this.setData({
'currentSortType': 'price',
'currentSortOrder': tmpSortOrder,
'categoryFilter': false
});
this.getData();
break;
default:
//综合排序
this.setData({
'currentSortType': 'default',
'currentSortOrder': 'desc',
'categoryFilter': false
});
this.getData();
}
},
selectCategory: function (event) {
let currentIndex = event.target.dataset.categoryIndex;
this.setData({
'categoryFilter': false,
'categoryId': this.data.filterCategory[currentIndex].id
});
this.getData();
}
})
================================================
FILE: pages/newGoods/newGoods.json
================================================
{
}
================================================
FILE: pages/newGoods/newGoods.wxml
================================================
{{bannerInfo.name}}
综合
价格
分类
{{item.name}}
{{iitem.name}}
¥{{iitem.retail_price}}
================================================
FILE: pages/newGoods/newGoods.wxss
================================================
page{
background: #f4f4f4;
}
.brand-info .name{
width: 100%;
height: 278rpx;
position: relative;
}
.brand-info .img{
position: absolute;
top:0;
left:0;
width: 100%;
height: 278rpx;
}
.brand-info .info-box{
position: absolute;
top:0;
left:0;
width: 100%;
height: 278rpx;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.brand-info .info{
display: block;
}
.brand-info .txt{
display: block;
height: 40rpx;
font-size: 37.5rpx;
color: #fff;
}
.brand-info .line{
margin: 0 auto;
margin-top: 16rpx;
display: block;
height: 2rpx;
width: 145rpx;
background: #fff;
}
.sort{
position: relative;
background: #fff;
width: 100%;
height: 78rpx;
}
.sort-box{
background: #fff;
width: 100%;
height: 78rpx;
overflow: hidden;
padding: 0 30rpx;
display: flex;
border-bottom: 1px solid #d9d9d9;
}
.sort-box .item{
height: 78rpx;
line-height: 78rpx;
text-align: center;
flex:1;
color: #333;
font-size: 30rpx;
}
.sort-box .item .txt{
display: block;
width: 100%;
height: 100%;
color: #333;
}
.sort-box .item.active .txt{
color: #b4282d;
}
.sort-box .item.by-price{
background: url(//yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/no-3127092a69.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box .item.by-price.active.asc{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/up-636b92c0a5.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box .item.by-price.active.desc{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/down-95e035f3e5.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box-category{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
padding: 40rpx 40rpx 0 0;
border-bottom: 1px solid #d9d9d9;
}
.sort-box-category .item{
height: 54rpx;
line-height: 54rpx;
text-align: center;
float: left;
padding: 0 16rpx;
margin: 0 0 40rpx 40rpx;
border: 1px solid #666;
color: #333;
font-size: 24rpx;
}
.sort-box-category .item.active{
color: #b4282d;
border: 1px solid #b4282d;
}
.cate-item .b{
width: 750rpx;
height: auto;
overflow: hidden;
border-top: 1rpx solid #f4f4f4;
margin-top: 20rpx;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 375rpx;
padding-bottom: 33.333rpx;
border-bottom: 1rpx solid #f4f4f4;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
border-right: 1rpx solid #f4f4f4;
}
.cate-item .item .img{
margin-top: 10rpx;
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
padding: 0 20rpx;
overflow: hidden;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
================================================
FILE: pages/pay/pay.js
================================================
var app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
orderId: 0,
actualPrice: 0.00
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
orderId: options.orderId,
actualPrice: options.actualPrice
})
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
//向服务请求支付参数
requestPayParam() {
let that = this;
util.request(api.PayPrepayId, { orderId: that.data.orderId, payType: 1 }).then(function (res) {
if (res.errno === 0) {
let payParam = res.data;
wx.requestPayment({
'timeStamp': payParam.timeStamp,
'nonceStr': payParam.timeStamp,
'package': payParam.nonceStr,
'signType': payParam.signType,
'paySign': payParam.paySign,
'success': function (res) {
wx.redirectTo({
url: '/pages/payResult/payResult?status=true',
})
},
'fail': function (res) {
wx.redirectTo({
url: '/pages/payResult/payResult?status=false',
})
}
})
}
});
},
startPay() {
this.requestPayParam();
}
})
================================================
FILE: pages/pay/pay.json
================================================
{
"navigationBarTitleText": "支付订单"
}
================================================
FILE: pages/pay/pay.wxml
================================================
订单金额
{{actualPrice}}元
请选择支付方式
微信支付
小程序只支持微信支付,如需其它支付方式,请在网页版支付
确定
================================================
FILE: pages/pay/pay.wxss
================================================
page{
min-height: 100%;
width: 100%;
background: #f4f4f4;
}
.container{
padding-top: 20rpx;
}
.total{
height: 104rpx;
background: #fff;
width: 100%;
line-height: 104rpx;
padding-left: 30rpx;
padding-right: 30rpx;
}
.total .label{
float: left;
}
.total .txt{
float: right;
}
.pay-list{
margin-top: 30rpx;
height: auto;
width: 100%;
overflow: hidden;
}
.pay-list .h{
width: 100%;
height: 24rpx;
line-height: 24rpx;
margin-left: 31.25rpx;
margin-bottom: 31.25rpx;
}
.pay-list .item{
height: 108rpx;
padding-left: 31.25rpx;
background: #fff;
display: flex;
align-items: center;
border-bottom: 1px solid #f4f4f4;
}
.pay-list .checkbox{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/checkbox-sed825af9d3-a6b8540d42.png) 0 -448rpx no-repeat;
background-size: 38rpx 486rpx;
width: 40rpx;
height: 40rpx;
display: inline-block;
vertical-align: middle;
margin-right: 30rpx;
}
.pay-list .checkbox.checked{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/checkbox-sed825af9d3-a6b8540d42.png) 0 -192rpx no-repeat;
background-size: 38rpx 486rpx;
}
.pay-list .icon-alipay{
display: inline-block;
vertical-align: middle;
background-image: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/payMethod-s3c1faebee4-d754da9c65.png);
background-repeat: no-repeat;
background-size: 56.25rpx 189.583rpx;
margin-right: 10.5rpx;
width: 56.25rpx;
height: 56.25rpx;
}
.pay-list .icon-net{
display: inline-block;
vertical-align: middle;
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/payMethod-s3c1faebee4-d754da9c65.png) 0 -66.7rpx no-repeat;
background-size: 56.25rpx 189.583rpx;
margin-right: 10.5rpx;
width: 56.25rpx;
height: 56.25rpx;
}
.pay-list .icon{
display: inline-block;
vertical-align: middle;
margin-right: 10.5rpx;
width: 56.25rpx;
height: 56.25rpx;
}
.pay-list .name{
display: inline-block;
vertical-align: middle;
height: 56.25rpx;
line-height: 56.25rpx;
}
.pay-btn{
position: fixed;
left: 0;
bottom: 0;
height: 100rpx;
width: 100%;
text-align: center;
line-height: 100rpx;
background: #b4282d;
color: #fff;
font-size: 30rpx;
}
.tips{
height: 40rpx;
width: 100%;
font-size: 24rpx;
color: #999;
line-height: 40rpx;
padding-left: 30rpx;
padding-right: 30rpx;
}
================================================
FILE: pages/payResult/payResult.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
const pay = require('../../services/pay.js');
var app = getApp();
Page({
data: {
status: false,
orderId: 0
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
orderId: options.orderId || 24,
status: options.status
})
},
onReady: function () {
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
payOrder() {
pay.payOrder(parseInt(this.data.orderId)).then(res => {
this.setData({
status: true
});
}).catch(res => {
util.showErrorToast('支付失败');
});
}
})
================================================
FILE: pages/payResult/payResult.json
================================================
{
"navigationBarTitleText": "付款结果",
"navigationBarBackgroundColor": "#fafafa"
}
================================================
FILE: pages/payResult/payResult.wxml
================================================
付款成功
查看订单
继续逛
付款失败
请在 1小时 内完成付款
否则订单将会被系统取消
查看订单
重新付款
================================================
FILE: pages/payResult/payResult.wxss
================================================
page {
min-height: 100%;
width: 100%;
background: #fff;
}
.container {
height: 100%;
background: #fff;
}
.pay-result {
background: #fff;
}
.pay-result .msg {
text-align: center;
margin: 100rpx auto;
color: #2bab25;
font-size: 36rpx;
}
.pay-result .btns {
display: flex;
align-items: center;
justify-content: center;
}
.pay-result .btn {
text-align: center;
height: 80rpx;
margin: 0 20rpx;
width: 200rpx;
line-height: 78rpx;
border: 1px solid #868686;
color: #000000;
border-radius: 5rpx;
}
.pay-result .error .msg {
color: #b4282d;
margin-bottom: 60rpx;
}
.pay-result .error .tips {
color: #7f7f7f;
margin-bottom: 70rpx;
}
.pay-result .error .tips .p {
font-size: 24rpx;
line-height: 42rpx;
text-align: center;
}
.pay-result .error .tips .p {
line-height: 42rpx;
text-align: center;
}
================================================
FILE: pages/search/search.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp()
Page({
data: {
keywrod: '',
searchStatus: false,
goodsList: [],
helpKeyword: [],
historyKeyword: [],
categoryFilter: false,
currentSortType: 'default',
currentSortOrder: '',
filterCategory: [],
defaultKeyword: {},
hotKeyword: [],
page: 1,
size: 20,
currentSortType: 'id',
currentSortOrder: 'desc',
categoryId: 0
},
//事件处理函数
closeSearch: function () {
wx.navigateBack()
},
clearKeyword: function () {
this.setData({
keyword: '',
searchStatus: false
});
},
onLoad: function () {
this.getSearchKeyword();
},
getSearchKeyword() {
let that = this;
util.request(api.SearchIndex).then(function (res) {
if (res.errno === 0) {
that.setData({
historyKeyword: res.data.historyKeywordList,
defaultKeyword: res.data.defaultKeyword,
hotKeyword: res.data.hotKeywordList
});
}
});
},
inputChange: function (e) {
this.setData({
keyword: e.detail.value,
searchStatus: false
});
this.getHelpKeyword();
},
getHelpKeyword: function () {
let that = this;
util.request(api.SearchHelper, { keyword: that.data.keyword }).then(function (res) {
if (res.errno === 0) {
that.setData({
helpKeyword: res.data
});
}
});
},
inputFocus: function () {
this.setData({
searchStatus: false,
goodsList: []
});
if (this.data.keyword) {
this.getHelpKeyword();
}
},
clearHistory: function () {
this.setData({
historyKeyword: []
})
util.request(api.SearchClearHistory, {}, 'POST')
.then(function (res) {
console.log('清除成功');
});
},
getGoodsList: function () {
let that = this;
util.request(api.GoodsList, { keyword: that.data.keyword, page: that.data.page, size: that.data.size, sort: that.data.currentSortType, order: that.data.currentSortOrder, categoryId: that.data.categoryId }).then(function (res) {
if (res.errno === 0) {
that.setData({
searchStatus: true,
categoryFilter: false,
goodsList: res.data.data,
filterCategory: res.data.filterCategory,
page: res.data.currentPage,
size: res.data.numsPerPage
});
}
//重新获取关键词
that.getSearchKeyword();
});
},
onKeywordTap: function (event) {
this.getSearchResult(event.target.dataset.keyword);
},
getSearchResult(keyword) {
this.setData({
keyword: keyword,
page: 1,
categoryId: 0,
goodsList: []
});
this.getGoodsList();
},
openSortFilter: function (event) {
let currentId = event.currentTarget.id;
switch (currentId) {
case 'categoryFilter':
this.setData({
'categoryFilter': !this.data.categoryFilter,
'currentSortOrder': 'asc'
});
break;
case 'priceSort':
let tmpSortOrder = 'asc';
if (this.data.currentSortOrder == 'asc') {
tmpSortOrder = 'desc';
}
this.setData({
'currentSortType': 'price',
'currentSortOrder': tmpSortOrder,
'categoryFilter': false
});
this.getGoodsList();
break;
default:
//综合排序
this.setData({
'currentSortType': 'default',
'currentSortOrder': 'desc',
'categoryFilter': false
});
this.getGoodsList();
}
},
selectCategory: function (event) {
let currentIndex = event.target.dataset.categoryIndex;
let filterCategory = this.data.filterCategory;
let currentCategory = null;
for (let key in filterCategory) {
if (key == currentIndex) {
filterCategory[key].selected = true;
currentCategory = filterCategory[key];
} else {
filterCategory[key].selected = false;
}
}
this.setData({
'filterCategory': filterCategory,
'categoryFilter': false,
categoryId: currentCategory.id,
page: 1,
goodsList: []
});
this.getGoodsList();
},
onKeywordConfirm(event) {
this.getSearchResult(event.detail.value);
}
})
================================================
FILE: pages/search/search.json
================================================
{
}
================================================
FILE: pages/search/search.wxml
================================================
取消
历史记录
{{item}}
热门搜索
{{item.keyword}}
{{item}}
综合
价格
分类
{{item.name}}
{{iitem.name}}
¥{{iitem.retail_price}}
您寻找的商品还未上架
================================================
FILE: pages/search/search.wxss
================================================
page{
min-height: 100%;
background-color: #f4f4f4;
}
.container{
min-height: 100%;
background-color: #f4f4f4;
}
.search-header{
position: fixed;
top: 0;
width: 750rpx;
height: 91rpx;
display: flex;
background: #fff;
border-bottom: 1px solid rgba(0,0,0,.15);
padding: 0 31.25rpx;
font-size: 29rpx;
color: #333;
}
.search-header .input-box{
position: relative;
margin-top: 16rpx;
float: left;
width: 0;
flex: 1;
height: 59rpx;
line-height: 59rpx;
padding: 0 20rpx;
background: #f4f4f4;
}
.search-header .icon{
position: absolute;
top: 14rpx;
left: 20rpx;
width: 31rpx;
height: 31rpx;
}
.search-header .del{
position: absolute;
top: 3rpx;
right: 10rpx;
width: 53rpx;
height: 53rpx;
z-index: 10;
}
.search-header .keywrod{
position: absolute;
top: 0;
left: 40rpx;
width: 506rpx;
height: 59rpx;
padding-left: 30rpx;
}
.search-header .right{
margin-top: 24rpx;
margin-left: 31rpx;
margin-right: 6rpx;
width: 58rpx;
height: 43rpx;
line-height: 43rpx;
float: right;
}
.no-search{
height: auto;
overflow: hidden;
margin-top: 91rpx;
}
.serach-keywords{
background: #fff;
width: 750rpx;
height: auto;
overflow: hidden;
margin-bottom: 20rpx;
}
.serach-keywords .h{
padding: 0 31.25rpx;
height: 93rpx;
line-height: 93rpx;
width: 100%;
color: #999;
font-size: 29rpx;
}
.serach-keywords .title{
display: block;
width: 120rpx;
float: left;
}
.serach-keywords .icon{
margin-top: 19rpx;
float: right;
display: block;
margin-left: 511rpx;
height: 55rpx;
width: 55rpx;
}
.serach-keywords .b{
width: 750rpx;
height: auto;
overflow: hidden;
padding-left: 31.25rpx;
}
.serach-keywords .item{
display: inline-block;
width: auto;
height: 48rpx;
line-height: 48rpx;
padding:0 15rpx;
border: 1px solid #999;
margin: 0 31.25rpx 31.25rpx 0;
font-size: 24rpx;
color: #333;
}
.serach-keywords .item.active{
color: #b4282d;
border: 1px solid #b4282d;
}
.shelper-list{
width: 750rpx;
height: auto;
overflow: hidden;
background: #fff;
padding: 0 31.25rpx;
}
.shelper-list .item{
height: 93rpx;
width: 687.5rpx;
line-height: 93rpx;
font-size: 24rpx;
color: #333;
border-bottom: 1px solid #f4f4f4;
}
.sort{
position: fixed;
top: 91rpx;
background: #fff;
width: 100%;
height: 78rpx;
}
.sort-box{
background: #fff;
width: 100%;
height: 78rpx;
overflow: hidden;
padding: 0 30rpx;
display: flex;
border-bottom: 1px solid #d9d9d9;
}
.sort-box .item{
height: 78rpx;
line-height: 78rpx;
text-align: center;
flex:1;
color: #333;
font-size: 30rpx;
}
.sort-box .item .txt{
display: block;
width: 100%;
height: 100%;
color: #333;
}
.sort-box .item.active .txt{
color: #b4282d;
}
.sort-box .item.by-price{
background: url(//yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/no-3127092a69.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box .item.by-price.active.asc{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/up-636b92c0a5.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box .item.by-price.active.desc{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/down-95e035f3e5.png) 155rpx center no-repeat;
background-size: 15rpx 21rpx;
}
.sort-box-category{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
padding: 40rpx 40rpx 0 0;
border-bottom: 1px solid #d9d9d9;
}
.sort-box-category .item{
height: 54rpx;
line-height: 54rpx;
text-align: center;
float: left;
padding: 0 16rpx;
margin: 0 0 40rpx 40rpx;
border: 1px solid #666;
color: #333;
font-size: 24rpx;
}
.sort-box-category .item.active{
color: #b4282d;
border: 1px solid #b4282d;
}
.cate-item{
margin-top: 175rpx;
height: auto;
overflow: hidden;
}
.cate-item .h{
height: 145rpx;
width: 750rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.cate-item .h .name{
display: block;
height: 35rpx;
margin-bottom: 18rpx;
font-size: 30rpx;
color: #333;
}
.cate-item .h .desc{
display: block;
height: 24rpx;
font-size: 24rpx;
color: #999;
}
.cate-item .b{
width: 750rpx;
padding: 0 6.25rpx;
height: auto;
overflow: hidden;
}
.cate-item .list-filter{
height: 80rpx;
width: 100%;
background: #fff;
margin-bottom: 6.25rpx;
}
.cate-item .b .item{
float: left;
background: #fff;
width: 365rpx;
margin-bottom: 6.25rpx;
padding-bottom: 33.333rpx;
height: auto;
overflow: hidden;
text-align: center;
}
.cate-item .b .item-b{
margin-left: 6.25rpx;
}
.cate-item .item .img{
width: 302rpx;
height: 302rpx;
}
.cate-item .item .name{
display: block;
width: 365.625rpx;
height: 35rpx;
margin: 11.5rpx 0 22rpx 0;
text-align: center;
overflow: hidden;
padding: 0 20rpx;
font-size: 30rpx;
color: #333;
}
.cate-item .item .price{
display: block;
width: 365.625rpx;
height: 30rpx;
text-align: center;
font-size: 30rpx;
color: #b4282d;
}
.search-result-empty{
width: 100%;
height: 100%;
padding-top: 300rpx;
}
.search-result-empty .icon{
margin: 0 auto;
display: block;
width: 240rpx;
height: 240rpx;
}
.search-result-empty .text{
display: block;
width: 100%;
height: 40rpx;
font-size: 28rpx;
text-align: center;
color: #999;
}
================================================
FILE: pages/shopping/address/address.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
addressList: [],
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getAddressList();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
getAddressList (){
let that = this;
util.request(api.AddressList).then(function (res) {
if (res.errno === 0) {
that.setData({
addressList: res.data
});
}
});
},
addressAddOrUpdate (event) {
console.log(event)
wx.navigateTo({
url: '/pages/shopping/addressAdd/addressAdd?id=' + event.currentTarget.dataset.addressId
})
},
selectAddress(event){
console.log(event.currentTarget.dataset.addressId);
try {
wx.setStorageSync('addressId', event.currentTarget.dataset.addressId);
} catch (e) {
}
//选择该收货地址
wx.redirectTo({
url: '/pages/shopping/checkout/checkout'
})
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/shopping/address/address.json
================================================
{}
================================================
FILE: pages/shopping/address/address.wxml
================================================
{{item.name}}
默认
{{item.mobile}}
{{item.full_region + item.address}}
收货地址在哪里
新建
================================================
FILE: pages/shopping/address/address.wxss
================================================
page{
height: 100%;
width: 100%;
background: #f4f4f4;
}
.container{
height: 100%;
width: 100%;
}
.address-list{
padding-left: 31.25rpx;
background: #fff url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-bd30f2bfeb.png) 0 0 repeat-x;
background-size: auto 10.5rpx;
margin-bottom: 90rpx;
}
.address-list .item{
height: 156.55rpx;
align-items: center;
display: flex;
border-bottom: 1rpx solid #DCD9D9;
}
.address-list .item:last-child{
border-bottom: none;
}
.address-list .l{
width: 125rpx;
height: 80rpx;
overflow: hidden;
}
.address-list .name{
width: 125rpx;
height: 43rpx;
font-size: 29rpx;
color: #333;
margin-bottom: 5.2rpx;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.address-list .default{
width: 62.5rpx;
height: 33rpx;
line-height: 28rpx;
text-align: center;
font-size: 20rpx;
color: #b4282d;
border: 1rpx solid #b4282d;
visibility: visible;
}
.address-list .c{
flex: 1;
height: auto;
overflow: hidden;
}
.address-list .mobile{
height: 29rpx;
font-size: 29rpx;
line-height: 29rpx;
overflow: hidden;
color: #333;
margin-bottom: 6.25rpx;
}
.address-list .address{
height: 37rpx;
font-size: 25rpx;
line-height: 37rpx;
overflow: hidden;
color: #666;
}
.address-list .r{
width: 52rpx;
height: auto;
overflow: hidden;
margin-right: 16.5rpx;
}
.address-list .del{
display: block;
width: 52rpx;
height: 52rpx;
}
.add-address{
background: #b4282d;
text-align: center;
width: 100%;
height: 99rpx;
line-height: 99rpx;
position: fixed;
border-radius: 0;
border: none;
color: #fff;
font-size: 29rpx;
bottom: 0;
left:0;
}
.empty-view{
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.empty-view .icon{
height: 248rpx;
width: 258rpx;
margin-bottom: 10rpx;
}
.empty-view .text{
width: auto;
font-size: 28rpx;
line-height: 35rpx;
color: #999;
}
================================================
FILE: pages/shopping/addressAdd/addressAdd.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
address: {
id:0,
province_id: 0,
city_id: 0,
district_id: 0,
address: '',
full_region: '',
name: '',
mobile: '',
is_default: 0
},
addressId: 0,
openSelectRegion: false,
selectRegionList: [
{ id: 0, name: '省份', parent_id: 1, type: 1 },
{ id: 0, name: '城市', parent_id: 1, type: 2 },
{ id: 0, name: '区县', parent_id: 1, type: 3 }
],
regionType: 1,
regionList: [],
selectRegionDone: false
},
bindinputMobile(event) {
let address = this.data.address;
address.mobile = event.detail.value;
this.setData({
address: address
});
},
bindinputName(event) {
let address = this.data.address;
address.name = event.detail.value;
this.setData({
address: address
});
},
bindinputAddress (event){
let address = this.data.address;
address.address = event.detail.value;
this.setData({
address: address
});
},
bindIsDefault(){
let address = this.data.address;
address.is_default = !address.is_default;
this.setData({
address: address
});
},
getAddressDetail() {
let that = this;
util.request(api.AddressDetail, { id: that.data.addressId }).then(function (res) {
if (res.errno === 0) {
that.setData({
address: res.data
});
}
});
},
setRegionDoneStatus() {
let that = this;
let doneStatus = that.data.selectRegionList.every(item => {
return item.id != 0;
});
that.setData({
selectRegionDone: doneStatus
})
},
chooseRegion() {
let that = this;
this.setData({
openSelectRegion: !this.data.openSelectRegion
});
//设置区域选择数据
let address = this.data.address;
if (address.province_id > 0 && address.city_id > 0 && address.district_id > 0) {
let selectRegionList = this.data.selectRegionList;
selectRegionList[0].id = address.province_id;
selectRegionList[0].name = address.province_name;
selectRegionList[0].parent_id = 1;
selectRegionList[1].id = address.city_id;
selectRegionList[1].name = address.city_name;
selectRegionList[1].parent_id = address.province_id;
selectRegionList[2].id = address.district_id;
selectRegionList[2].name = address.district_name;
selectRegionList[2].parent_id = address.city_id;
this.setData({
selectRegionList: selectRegionList,
regionType: 3
});
this.getRegionList(address.city_id);
} else {
this.setData({
selectRegionList: [
{ id: 0, name: '省份', parent_id: 1, type: 1 },
{ id: 0, name: '城市', parent_id: 1, type: 2 },
{ id: 0, name: '区县', parent_id: 1, type: 3 }
],
regionType: 1
})
this.getRegionList(1);
}
this.setRegionDoneStatus();
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
console.log(options)
if (options.id) {
this.setData({
addressId: options.id
});
this.getAddressDetail();
}
this.getRegionList(1);
},
onReady: function () {
},
selectRegionType(event) {
let that = this;
let regionTypeIndex = event.target.dataset.regionTypeIndex;
let selectRegionList = that.data.selectRegionList;
//判断是否可点击
if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex-1].id <= 0)) {
return false;
}
this.setData({
regionType: regionTypeIndex + 1
})
let selectRegionItem = selectRegionList[regionTypeIndex];
this.getRegionList(selectRegionItem.parent_id);
this.setRegionDoneStatus();
},
selectRegion(event) {
let that = this;
let regionIndex = event.target.dataset.regionIndex;
let regionItem = this.data.regionList[regionIndex];
let regionType = regionItem.type;
let selectRegionList = this.data.selectRegionList;
selectRegionList[regionType - 1] = regionItem;
if (regionType != 3) {
this.setData({
selectRegionList: selectRegionList,
regionType: regionType + 1
})
this.getRegionList(regionItem.id);
} else {
this.setData({
selectRegionList: selectRegionList
})
}
//重置下级区域为空
selectRegionList.map((item, index) => {
if (index > regionType - 1) {
item.id = 0;
item.name = index == 1 ? '城市' : '区县';
item.parent_id = 0;
}
return item;
});
this.setData({
selectRegionList: selectRegionList
})
that.setData({
regionList: that.data.regionList.map(item => {
//标记已选择的
if (that.data.regionType == item.type && that.data.selectRegionList[that.data.regionType - 1].id == item.id) {
item.selected = true;
} else {
item.selected = false;
}
return item;
})
});
this.setRegionDoneStatus();
},
doneSelectRegion() {
if (this.data.selectRegionDone === false) {
return false;
}
let address = this.data.address;
let selectRegionList = this.data.selectRegionList;
address.province_id = selectRegionList[0].id;
address.city_id = selectRegionList[1].id;
address.district_id = selectRegionList[2].id;
address.province_name = selectRegionList[0].name;
address.city_name = selectRegionList[1].name;
address.district_name = selectRegionList[2].name;
address.full_region = selectRegionList.map(item => {
return item.name;
}).join('');
this.setData({
address: address,
openSelectRegion: false
});
},
cancelSelectRegion() {
this.setData({
openSelectRegion: false,
regionType: this.data.regionDoneStatus ? 3 : 1
});
},
getRegionList(regionId) {
let that = this;
let regionType = that.data.regionType;
util.request(api.RegionList, { parentId: regionId }).then(function (res) {
if (res.errno === 0) {
that.setData({
regionList: res.data.map(item => {
//标记已选择的
if (regionType == item.type && that.data.selectRegionList[regionType - 1].id == item.id) {
item.selected = true;
} else {
item.selected = false;
}
return item;
})
});
}
});
},
cancelAddress(){
wx.reLaunch({
url: '/pages/shopping/address/address',
})
},
saveAddress(){
console.log(this.data.address)
let address = this.data.address;
if (address.name == '') {
util.showErrorToast('请输入姓名');
return false;
}
if (address.mobile == '') {
util.showErrorToast('请输入手机号码');
return false;
}
if (address.district_id == 0) {
util.showErrorToast('请输入省市区');
return false;
}
if (address.address == '') {
util.showErrorToast('请输入详细地址');
return false;
}
let that = this;
util.request(api.AddressSave, {
id: address.id,
name: address.name,
mobile: address.mobile,
province_id: address.province_id,
city_id: address.city_id,
district_id: address.district_id,
address: address.address,
is_default: address.is_default,
}, 'POST').then(function (res) {
if (res.errno === 0) {
wx.reLaunch({
url: '/pages/shopping/address/address',
})
}
});
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/shopping/addressAdd/addressAdd.json
================================================
{
}
================================================
FILE: pages/shopping/addressAdd/addressAdd.wxml
================================================
设为默认地址
{{item.name}}
确定
{{item.name}}
================================================
FILE: pages/shopping/addressAdd/addressAdd.wxss
================================================
page{
height: 100%;
background: #f4f4f4;
}
.add-address .add-form{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
}
.add-address .form-item{
height: 116rpx;
padding-left: 31.25rpx;
border-bottom: 1px solid #d9d9d9;
display: flex;
align-items: center;
padding-right: 31.25rpx;
}
.add-address .input{
flex: 1;
height: 44rpx;
line-height: 44rpx;
overflow: hidden;
}
.add-address .form-default{
border-bottom: 1px solid #d9d9d9;
height: 96rpx;
background: #fafafa;
padding-top: 28rpx;
font-size: 28rpx;
}
.default-input{
margin: 0 auto;
display: block;
width: 240rpx;
height: 40rpx;
padding-left: 50rpx;
line-height: 40rpx;
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/checkbox-sed825af9d3-a6b8540d42.png) 1rpx -448rpx no-repeat;
background-size: 38rpx 486rpx;
font-size: 28rpx;
}
.default-input.selected{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/checkbox-sed825af9d3-a6b8540d42.png) 0 -192rpx no-repeat;
background-size: 38rpx 486rpx;
}
.add-address .btns{
position: fixed;
bottom: 0;
left: 0;
overflow: hidden;
display: flex;
height: 100rpx;
width: 100%;
}
.add-address .cannel,.add-address .save{
flex: 1;
height: 100rpx;
text-align: center;
line-height: 100rpx;
font-size: 28rpx;
color: #fff;
border:none;
border-radius: 0;
}
.add-address .cannel{
background: #333;
}
.add-address .save{
background: #b4282d;
}
.region-select{
width: 100%;
height: 600rpx;
background: #fff;
position: fixed;
z-index: 10;
left:0;
bottom: 0;
}
.region-select .hd{
height: 108rpx;
width: 100%;
border-bottom: 1px solid #f4f4f4;
padding: 46rpx 30rpx 0 30rpx;
}
.region-select .region-selected{
float: left;
height: 60rpx;
display: flex;
}
.region-select .region-selected .item{
max-width: 140rpx;
margin-right: 30rpx;
text-align: left;
line-height: 60rpx;
height: 100%;
color: #333;
font-size: 28rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.region-select .region-selected .item.disabled{
color: #999;
}
.region-select .region-selected .item.selected{
color: #b4282d;
}
.region-select .done{
float: right;
height: 60rpx;
width: 60rpx;
border: none;
background: #fff;
line-height: 60rpx;
text-align: center;
color: #333;
font-size: 28rpx;
}
.region-select .done.disabled{
color: #999;
}
.region-select .bd{
height: 492rpx;
width: 100%;
padding: 0 30rpx;
}
.region-select .region-list{
height: auto;
overflow: scroll;
}
.region-select .region-list .item{
width: 100%;
height: 104rpx;
line-height: 104rpx;
text-align: left;
color: #333;
font-size: 28rpx;
}
.region-select .region-list .item.selected{
color: #b4282d;
}
.bg-mask{
height: 100%;
width: 100%;
background: rgba(0, 0, 0, 0.4);
position: fixed;
top:0;
left:0;
z-index: 8;
}
================================================
FILE: pages/shopping/checkout/checkout.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
const pay = require('../../../services/pay.js');
var app = getApp();
Page({
data: {
checkedGoodsList: [],
checkedAddress: {},
checkedCoupon: [],
couponList: [],
goodsTotalPrice: 0.00, //商品总价
freightPrice: 0.00, //快递费
couponPrice: 0.00, //优惠券的价格
orderTotalPrice: 0.00, //订单总价
actualPrice: 0.00, //实际需要支付的总价
addressId: 0,
couponId: 0
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
try {
var addressId = wx.getStorageSync('addressId');
if (addressId) {
this.setData({
'addressId': addressId
});
}
var couponId = wx.getStorageSync('couponId');
if (couponId) {
this.setData({
'couponId': couponId
});
}
} catch (e) {
// Do something when catch error
}
},
getCheckoutInfo: function () {
let that = this;
util.request(api.CartCheckout, { addressId: that.data.addressId, couponId: that.data.couponId }).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
checkedGoodsList: res.data.checkedGoodsList,
checkedAddress: res.data.checkedAddress,
actualPrice: res.data.actualPrice,
checkedCoupon: res.data.checkedCoupon,
couponList: res.data.couponList,
couponPrice: res.data.couponPrice,
freightPrice: res.data.freightPrice,
goodsTotalPrice: res.data.goodsTotalPrice,
orderTotalPrice: res.data.orderTotalPrice
});
}
wx.hideLoading();
});
},
selectAddress() {
wx.navigateTo({
url: '/pages/shopping/address/address',
})
},
addAddress() {
wx.navigateTo({
url: '/pages/shopping/addressAdd/addressAdd',
})
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
wx.showLoading({
title: '加载中...',
})
this.getCheckoutInfo();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
submitOrder: function () {
if (this.data.addressId <= 0) {
util.showErrorToast('请选择收货地址');
return false;
}
util.request(api.OrderSubmit, { addressId: this.data.addressId, couponId: this.data.couponId }, 'POST').then(res => {
if (res.errno === 0) {
const orderId = res.data.orderInfo.id;
pay.payOrder(parseInt(orderId)).then(res => {
wx.redirectTo({
url: '/pages/payResult/payResult?status=1&orderId=' + orderId
});
}).catch(res => {
wx.redirectTo({
url: '/pages/payResult/payResult?status=0&orderId=' + orderId
});
});
} else {
util.showErrorToast('下单失败');
}
});
}
})
================================================
FILE: pages/shopping/checkout/checkout.json
================================================
{
}
================================================
FILE: pages/shopping/checkout/checkout.wxml
================================================
{{checkedAddress.name}}
默认
{{checkedAddress.mobile}}
{{checkedAddress.full_region + checkedAddress.address}}
还没有收货地址,去添加
请选择优惠券
{{couponList.length}}张
商品合计
¥{{goodsTotalPrice}}
运费
¥{{freightPrice}}
优惠券
-¥{{couponPrice}}
{{item.goods_name}}
x{{item.number}}
{{item.goods_specifition_name_value}}
¥{{item.retail_price}}
实付:¥{{actualPrice}}
去付款
================================================
FILE: pages/shopping/checkout/checkout.wxss
================================================
page{
height: 100%;
background: #f4f4f4;
}
.address-box{
width: 100%;
height: 166.55rpx;
background: url('http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-bd30f2bfeb.png') 0 0 repeat-x;
background-size: 62.5rpx 10.5rpx;
margin-bottom: 20rpx;
padding-top: 10.5rpx;
}
.address-item{
display: flex;
height: 155.55rpx;
background: #fff;
padding: 41.6rpx 0 41.6rpx 31.25rpx;
}
.address-item.address-empty{
line-height: 75rpx;
text-align: center;
}
.address-box .l{
width: 125rpx;
height: 100%;
}
.address-box .l .name{
margin-left: 6.25rpx;
margin-top: -7.25rpx;
display: block;
width: 125rpx;
height: 43rpx;
line-height: 43rpx;
font-size: 30rpx;
color: #333;
margin-bottom: 5rpx;
}
.address-box .l .default{
margin-left: 6.25rpx;
display: block;
width: 62rpx;
height: 33rpx;
border-radius: 5rpx;
border: 1px solid #b4282d;
font-size: 20.5rpx;
text-align: center;
line-height: 29rpx;
color: #b4282d;
}
.address-box .m{
flex: 1;
height: 72.25rpx;
color: #999;
}
.address-box .mobile{
display: block;
height: 29rpx;
line-height: 29rpx;
margin-bottom: 6.25rpx;
font-size: 30rpx;
color:#333;
}
.address-box .address{
display: block;
height: 37.5rpx;
line-height: 37.5rpx;
font-size: 25rpx;
color:#666;
}
.address-box .r{
width: 77rpx;
height: 77rpx;
display: flex;
justify-content: center;
align-items: center;
}
.address-box .r image{
width: 52.078rpx;
height: 52.078rpx;
}
.coupon-box{
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
}
.coupon-box .coupon-item{
width: 100%;
height: 108.3rpx;
overflow: hidden;
background: #fff;
display: flex;
padding-left: 31.25rpx;
}
.coupon-box .l{
flex: 1;
height: 43rpx;
line-height: 43rpx;
padding-top: 35rpx;
}
.coupon-box .l .name{
float: left;
font-size: 30rpx;
color: #666;
}
.coupon-box .l .txt{
float: right;
font-size: 30rpx;
color: #666;
}
.coupon-box .r{
margin-top: 15.5rpx;
width: 77rpx;
height: 77rpx;
display: flex;
justify-content: center;
align-items: center;
}
.coupon-box .r image{
width: 52.078rpx;
height: 52.078rpx;
}
.order-box{
margin-top: 20rpx;
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
}
.order-box .order-item{
height: 104.3rpx;
overflow: hidden;
background: #fff;
display: flex;
margin-left: 31.25rpx;
padding-right: 31.25rpx;
padding-top: 26rpx;
border-bottom: 1px solid #d9d9d9;
}
.order-box .order-item .l{
float: left;
height: 52rpx;
width: 50%;
line-height: 52rpx;
overflow: hidden;
}
.order-box .order-item .r{
float: right;
text-align: right;
width: 50%;
height: 52rpx;
line-height: 52rpx;
overflow: hidden;
}
.order-box .order-item.no-border{
border-bottom: none;
}
.goods-items{
margin-top: 20rpx;
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
padding-left: 31.25rpx;
margin-bottom: 120rpx;
}
.goods-items .item{
height: 192rpx;
padding-right: 31.25rpx;
display: flex;
align-items: center;
border-bottom: 1px solid rgba(0,0,0,0.15);
}
.goods-items .item.no-border{
border-bottom: none;
}
.goods-items .item:last-child{
border-bottom: none;
}
.goods-items .img{
height: 145.83rpx;
width: 145.83rpx;
background-color: #f4f4f4;
margin-right: 20rpx;
}
.goods-items .img image{
height: 145.83rpx;
width: 145.83rpx;
}
.goods-items .info{
flex: 1;
height: 145.83rpx;
padding-top: 5rpx;
}
.goods-items .t{
height: 33rpx;
line-height: 33rpx;
margin-bottom: 10rpx;
overflow: hidden;
font-size: 30rpx;
color: #333;
}
.goods-items .t .name{
display: block;
float: left;
}
.goods-items .t .number{
display: block;
float: right;
text-align: right;
}
.goods-items .m {
height: 29rpx;
overflow: hidden;
line-height: 29rpx;
margin-bottom: 25rpx;
font-size: 25rpx;
color: #666;
}
.goods-items .b {
height: 41rpx;
overflow: hidden;
line-height: 41rpx;
font-size: 30rpx;
color: #333;
}
.order-total{
position: fixed;
left:0;
bottom: 0;
height: 100rpx;
width: 100%;
display: flex;
}
.order-total .l{
flex: 1;
height: 100rpx;
line-height: 100rpx;
color: #b4282d;
background: #fff;
font-size: 33rpx;
padding-left: 31.25rpx;
border-top: 1rpx solid rgba(0,0,0,0.2);
border-bottom: 1rpx solid rgba(0,0,0,0.2);
}
.order-total .r{
width: 233rpx;
height: 100rpx;
background: #b4282d;
border: 1px solid #b4282d;
line-height: 100rpx;
text-align: center;
color: #fff;
font-size: 30rpx;
}
================================================
FILE: pages/topic/topic.js
================================================
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
var app = getApp()
Page({
data: {
// text:"这是一个页面"
topicList: [],
page: 1,
size: 10,
count: 0,
scrollTop: 0,
showPage: false
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getTopic();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
nextPage: function (event) {
console.log();
var that = this;
if (this.data.page+1 > that.data.count / that.data.size) {
return true;
}
that.setData({
"page": parseInt(that.data.page) + 1
});
this.getTopic();
},
getTopic: function(){
let that = this;
that.setData({
scrollTop: 0,
showPage: false,
topicList: []
});
// 页面渲染完成
wx.showToast({
title: '加载中...',
icon: 'loading',
duration: 2000
});
util.request(api.TopicList, { page: that.data.page, size: that.data.size }).then(function (res) {
if (res.errno === 0) {
that.setData({
scrollTop: 0,
topicList: res.data.data,
showPage: true,
count: res.data.count
});
}
wx.hideToast();
});
},
prevPage: function (event) {
if (this.data.page <= 1) {
return false;
}
var that = this;
that.setData({
"page": parseInt(that.data.page) - 1
});
this.getTopic();
}
})
================================================
FILE: pages/topic/topic.json
================================================
{}
================================================
FILE: pages/topic/topic.wxml
================================================
{{item.title}}
{{item.subtitle}}
{{item.price_info}}元起
上一页
下一页
================================================
FILE: pages/topic/topic.wxss
================================================
page ,.container{
width: 750rpx;
height: 100%;
overflow: hidden;
background: #f4f4f4;
}
.topic-list{
width: 750rpx;
height: 100%;
overflow: hidden;
background: #f4f4f4;
}
.topic-list .item{
width: 100%;
height: 625rpx;
overflow: hidden;
background: #fff;
margin-bottom: 20rpx;
}
.topic-list .img{
width: 100%;
height: 415rpx;
}
.topic-list .info{
width: 100%;
height: 210rpx;
overflow: hidden;
}
.topic-list .title{
display: block;
text-align: center;
width: 100%;
height: 33rpx;
line-height: 35rpx;
color: #333;
overflow: hidden;
font-size: 35rpx;
margin-top: 30rpx;
}
.topic-list .desc{
display: block;
text-align: center;
position: relative;
width: auto;
height: 24rpx;
line-height: 24rpx;
overflow: hidden;
color: #999;
font-size: 24rpx;
margin-top: 16rpx;
margin-bottom: 30rpx;
}
.topic-list .price{
display: block;
text-align: center;
width: 100%;
height: 27rpx;
line-height: 27rpx;
overflow: hidden;
color: #b4282d;
font-size: 27rpx;
}
.page{
width: 750rpx;
height: 108rpx;
background: #fff;
margin-bottom: 20rpx;
}
.page view{
height: 108rpx;
width: 50%;
float: left;
font-size: 29rpx;
color: #333;
text-align: center;
line-height: 108rpx;
}
.page .prev{
border-right: 1px solid #D9D9D9;
}
.page .disabled{
color: #ccc;
}
================================================
FILE: pages/topicComment/topicComment.js
================================================
var app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
comments: [],
allCommentList: [],
picCommentList: [],
typeId: 0,
valueId: 0,
showType: 0,
allCount: 0,
hasPicCount: 0,
allPage: 1,
picPage: 1,
size: 20
},
getCommentCount: function () {
let that = this;
util.request(api.CommentCount, { valueId: that.data.valueId, typeId: that.data.typeId}).then(function (res) {
if (res.errno === 0) {
that.setData({
allCount: res.data.allCount,
hasPicCount: res.data.hasPicCount
});
}
});
},
getCommentList: function(){
let that = this;
util.request(api.CommentList, {
valueId: that.data.valueId,
typeId: that.data.typeId,
size: that.data.size,
page: (that.data.showType == 0 ? that.data.allPage : that.data.picPage),
showType: that.data.showType
}).then(function (res) {
if (res.errno === 0) {
if (that.data.showType == 0) {
that.setData({
allCommentList: that.data.allCommentList.concat(res.data.data),
allPage: res.data.currentPage,
comments: that.data.allCommentList.concat(res.data.data)
});
} else {
that.setData({
picCommentList: that.data.picCommentList.concat(res.data.data),
picPage: res.data.currentPage,
comments: that.data.picCommentList.concat(res.data.data)
});
}
}
});
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
typeId: options.typeId,
valueId: options.valueId
});
this.getCommentCount();
this.getCommentList();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
switchTab: function () {
this.setData({
showType: this.data.showType == 1 ? 0 :1
});
this.getCommentList();
},
onReachBottom: function(){
console.log('onPullDownRefresh');
if ( this.data.showType == 0) {
if (this.data.allCount / this.data.size < this.data.allPage) {
return false;
}
this.setData({
'allPage' : this.data.allPage + 1
});
} else {
if (this.data.hasPicCount / this.data.size < this.data.picPage) {
return false;
}
this.setData({
'picPage': this.data.picPage + 1
});
}
this.getCommentList();
}
})
================================================
FILE: pages/topicComment/topicComment.json
================================================
{
}
================================================
FILE: pages/topicComment/topicComment.wxml
================================================
{{item.user_info.nickname}}
{{item.add_time}}
{{item.content}}
================================================
FILE: pages/topicComment/topicComment.wxss
================================================
.comments{
width: 100%;
height: auto;
padding-left:30rpx;
background: #fff;
margin: 20rpx 0;
}
.comments .b{
height: auto;
width: 720rpx;
}
.comments .b.no-h{
margin-top: 0;
}
.comments .item{
height: auto;
width: 720rpx;
overflow: hidden;
border-bottom: 1px solid #d9d9d9;
padding-bottom: 25rpx;
}
.comments .info{
height: 127rpx;
width: 100%;
padding: 33rpx 0 27rpx 0;
}
.comments .user{
float: left;
width: auto;
height: 67rpx;
line-height: 67rpx;
font-size: 0;
}
.comments .user image{
float: left;
width: 67rpx;
height: 67rpx;
margin-right: 17rpx;
border-radius: 50%;
}
.comments .user text{
display: inline-block;
width: auto;
height: 66rpx;
overflow: hidden;
font-size: 29rpx;
line-height: 66rpx;
}
.comments .time{
display: block;
float: right;
width: auto;
height: 67rpx;
line-height: 67rpx;
color: #7f7f7f;
font-size: 25rpx;
margin-right: 30rpx;
}
.comments .comment{
width: 720rpx;
padding-right: 30rpx;
line-height: 45.8rpx;
font-size: 29rpx;
margin-bottom: 16rpx;
}
.comments .imgs{
width: 720rpx;
height: 150rpx;
margin-bottom: 25rpx;
}
.comments .imgs .img{
height: 150rpx;
width: 150rpx;
margin-right: 28rpx;
}
.comments .customer-service{
width: 690rpx;
height: auto;
overflow: hidden;
margin-top: 23rpx;
background: rgba(0,0,0,.03);
padding: 21rpx;
}
.comments .customer-service .u{
font-size: 24rpx;
color: #333;
line-height: 37.5rpx;
}
.comments .customer-service .c{
font-size: 24rpx;
color: #999;
line-height: 37.5rpx;
}
================================================
FILE: pages/topicDetail/topicDetail.js
================================================
var app = getApp();
var WxParse = require('../../lib/wxParse/wxParse.js');
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
data: {
id: 0,
topic: {},
topicList: [],
commentCount: 0,
commentList: []
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
var that = this;
that.setData({
id: parseInt(options.id)
});
util.request(api.TopicDetail, { id: that.data.id}).then(function (res) {
if (res.errno === 0) {
that.setData({
topic: res.data,
});
WxParse.wxParse('topicDetail', 'html', res.data.content, that);
}
});
util.request(api.TopicRelated, { id: that.data.id}).then(function (res) {
if (res.errno === 0) {
that.setData({
topicList: res.data
});
}
});
},
getCommentList(){
let that = this;
util.request(api.CommentList, { valueId: that.data.id, typeId: 1, size: 5 }).then(function (res) {
if (res.errno === 0) {
that.setData({
commentList: res.data.data,
commentCount: res.data.count
});
}
});
},
postComment (){
wx.navigateTo({
url: '/pages/commentPost/commentPost?valueId='+this.data.id + '&typeId=1',
})
},
onReady: function () {
},
onShow: function () {
// 页面显示
this.getCommentList();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/topicDetail/topicDetail.json
================================================
{}
================================================
FILE: pages/topicDetail/topicDetail.wxml
================================================
精选留言
{{item.user_info.nickname}}
{{item.add_time}}
{{item.content}}
查看更多
等你来留言
专题推荐
{{item.title}}
================================================
FILE: pages/topicDetail/topicDetail.wxss
================================================
.content{
width: 100%;
height: auto;
font-size: 0;
}
.content image{
display: inline-block;
width: 100%;
}
.comments{
width: 100%;
height: auto;
padding-left:30rpx;
background: #fff;
margin-top: 20rpx;
}
.comments .h{
height: 93rpx;
line-height: 93rpx;
width: 720rpx;
padding-right: 30rpx;
border-bottom: 1px solid #d9d9d9;
}
.comments .h .t{
display: block;
float: left;
width: 50%;
font-size: 29rpx;
color: #333;
}
.comments .h .i{
display: block;
float: right;
margin-top: 30rpx;
width: 33rpx;
height: 33rpx;
}
.comments .b{
height: auto;
width: 720rpx;
}
.comments .item{
height: auto;
width: 720rpx;
overflow: hidden;
border-bottom: 1px solid #d9d9d9;
}
.comments .info{
height: 127rpx;
width: 100%;
padding: 33rpx 0 27rpx 0;
}
.comments .user{
float: left;
width: auto;
height: 67rpx;
line-height: 67rpx;
font-size: 0;
}
.comments .user .avatar{
display: block;
float: left;
width: 67rpx;
height: 67rpx;
margin-right: 17rpx;
border-radius: 50%;
}
.comments .user .nickname{
display: block;
width: auto;
float: left;
height: 66rpx;
overflow: hidden;
font-size: 29rpx;
line-height: 66rpx;
}
.comments .time{
display: block;
float: right;
width: auto;
height: 67rpx;
line-height: 67rpx;
color: #7f7f7f;
font-size: 25rpx;
margin-right: 30rpx;
}
.comments .comment{
width: 720rpx;
padding-right: 30rpx;
line-height: 45.8rpx;
margin-bottom: 30rpx;
font-size: 29rpx;
color: #333;
}
.comments .load{
width: 720rpx;
height: 108rpx;
line-height: 108rpx;
text-align: center;
font-size: 38.5rpx;
}
.no-comments{
height: 297rpx;
}
.no-comments .txt{
height: 43rpx;
line-height: 43rpx;
display: block;
width: 100%;
text-align: center;
font-size: 29rpx;
color: #7f7f7f;
}
.no-comments .icon{
margin: 48rpx auto 18rpx auto;
height: 130rpx;
display: block;
width: 115rpx;
}
.rec-box{
width: 690rpx;
height: auto;
margin: 0 30rpx;
}
.rec-box .h{
position: relative;
width: 690rpx;
height: 96rpx;
/*border-bottom: 1px solid #d0d0d0;*/
margin-bottom: 32rpx;
}
.rec-box .h .txt{
display: inline-block;
position: absolute;
background: #f4f4f4;
top: 59rpx;
left: 200rpx;
width: 290rpx;
height: 45rpx;
line-height: 45rpx;
font-size: 30rpx;
color: #999;
text-align: center;
}
.rec-box .b .item{
width: 690rpx;
height: 397rpx;
padding: 24rpx 24rpx 30rpx 24rpx;
background: #fff;
margin-bottom: 30rpx;
}
.rec-box .b .item .img{
height: 278rpx;
width: 642rpx;
}
.rec-box .b .item .title{
display: block;
margin-top: 30rpx;
height: 30rpx;
width: 642rpx;
font-size: 28rpx;
}
@import "../../lib/wxParse/wxParse.wxss";
================================================
FILE: pages/ucenter/address/address.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
addressList: [],
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.getAddressList();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
getAddressList (){
let that = this;
util.request(api.AddressList).then(function (res) {
if (res.errno === 0) {
that.setData({
addressList: res.data
});
}
});
},
addressAddOrUpdate (event) {
console.log(event)
wx.navigateTo({
url: '/pages/ucenter/addressAdd/addressAdd?id=' + event.currentTarget.dataset.addressId
})
},
deleteAddress(event){
console.log(event.target)
let that = this;
wx.showModal({
title: '',
content: '确定要删除地址?',
success: function (res) {
if (res.confirm) {
let addressId = event.target.dataset.addressId;
util.request(api.AddressDelete, { id: addressId }, 'POST').then(function (res) {
if (res.errno === 0) {
that.getAddressList();
}
});
console.log('用户点击确定')
}
}
})
return false;
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/ucenter/address/address.json
================================================
{}
================================================
FILE: pages/ucenter/address/address.wxml
================================================
{{item.name}}
默认
{{item.mobile}}
{{item.full_region + item.address}}
收货地址在哪里
新建
================================================
FILE: pages/ucenter/address/address.wxss
================================================
page{
height: 100%;
width: 100%;
background: #f4f4f4;
}
.container{
height: 100%;
width: 100%;
}
.address-list{
padding-left: 31.25rpx;
background: #fff url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-bd30f2bfeb.png) 0 0 repeat-x;
background-size: auto 10.5rpx;
margin-bottom: 90rpx;
}
.address-list .item{
height: 156.55rpx;
align-items: center;
display: flex;
border-bottom: 1rpx solid #DCD9D9;
}
.address-list .l{
width: 125rpx;
height: 80rpx;
overflow: hidden;
}
.address-list .name{
width: 125rpx;
height: 43rpx;
font-size: 29rpx;
color: #333;
margin-bottom: 5.2rpx;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.address-list .default{
width: 62.5rpx;
height: 33rpx;
line-height: 28rpx;
text-align: center;
font-size: 20rpx;
color: #b4282d;
border: 1rpx solid #b4282d;
visibility: visible;
}
.address-list .c{
flex: 1;
height: auto;
overflow: hidden;
}
.address-list .mobile{
height: 29rpx;
font-size: 29rpx;
line-height: 29rpx;
overflow: hidden;
color: #333;
margin-bottom: 6.25rpx;
}
.address-list .address{
height: 37rpx;
font-size: 25rpx;
line-height: 37rpx;
overflow: hidden;
color: #666;
}
.address-list .r{
width: 52rpx;
height: auto;
overflow: hidden;
margin-right: 16.5rpx;
}
.address-list .del{
display: block;
width: 52rpx;
height: 52rpx;
}
.add-address{
background: #b4282d;
text-align: center;
width: 100%;
height: 99rpx;
line-height: 99rpx;
position: fixed;
border-radius: 0;
border: none;
color: #fff;
font-size: 29rpx;
bottom: 0;
left:0;
}
.empty-view{
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.empty-view .icon{
height: 248rpx;
width: 258rpx;
margin-bottom: 10rpx;
}
.empty-view .text{
width: auto;
font-size: 28rpx;
line-height: 35rpx;
color: #999;
}
================================================
FILE: pages/ucenter/addressAdd/addressAdd.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
address: {
id:0,
province_id: 0,
city_id: 0,
district_id: 0,
address: '',
full_region: '',
name: '',
mobile: '',
is_default: 0
},
addressId: 0,
openSelectRegion: false,
selectRegionList: [
{ id: 0, name: '省份', parent_id: 1, type: 1 },
{ id: 0, name: '城市', parent_id: 1, type: 2 },
{ id: 0, name: '区县', parent_id: 1, type: 3 }
],
regionType: 1,
regionList: [],
selectRegionDone: false
},
bindinputMobile(event) {
let address = this.data.address;
address.mobile = event.detail.value;
this.setData({
address: address
});
},
bindinputName(event) {
let address = this.data.address;
address.name = event.detail.value;
this.setData({
address: address
});
},
bindinputAddress (event){
let address = this.data.address;
address.address = event.detail.value;
this.setData({
address: address
});
},
bindIsDefault(){
let address = this.data.address;
address.is_default = !address.is_default;
this.setData({
address: address
});
},
getAddressDetail() {
let that = this;
util.request(api.AddressDetail, { id: that.data.addressId }).then(function (res) {
if (res.errno === 0) {
that.setData({
address: res.data
});
}
});
},
setRegionDoneStatus() {
let that = this;
let doneStatus = that.data.selectRegionList.every(item => {
return item.id != 0;
});
that.setData({
selectRegionDone: doneStatus
})
},
chooseRegion() {
let that = this;
this.setData({
openSelectRegion: !this.data.openSelectRegion
});
//设置区域选择数据
let address = this.data.address;
if (address.province_id > 0 && address.city_id > 0 && address.district_id > 0) {
let selectRegionList = this.data.selectRegionList;
selectRegionList[0].id = address.province_id;
selectRegionList[0].name = address.province_name;
selectRegionList[0].parent_id = 1;
selectRegionList[1].id = address.city_id;
selectRegionList[1].name = address.city_name;
selectRegionList[1].parent_id = address.province_id;
selectRegionList[2].id = address.district_id;
selectRegionList[2].name = address.district_name;
selectRegionList[2].parent_id = address.city_id;
this.setData({
selectRegionList: selectRegionList,
regionType: 3
});
this.getRegionList(address.city_id);
} else {
this.setData({
selectRegionList: [
{ id: 0, name: '省份', parent_id: 1, type: 1 },
{ id: 0, name: '城市', parent_id: 1, type: 2 },
{ id: 0, name: '区县', parent_id: 1, type: 3 }
],
regionType: 1
})
this.getRegionList(1);
}
this.setRegionDoneStatus();
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
console.log(options)
if (options.id) {
this.setData({
addressId: options.id
});
this.getAddressDetail();
}
this.getRegionList(1);
},
onReady: function () {
},
selectRegionType(event) {
let that = this;
let regionTypeIndex = event.target.dataset.regionTypeIndex;
let selectRegionList = that.data.selectRegionList;
//判断是否可点击
if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex-1].id <= 0)) {
return false;
}
this.setData({
regionType: regionTypeIndex + 1
})
let selectRegionItem = selectRegionList[regionTypeIndex];
this.getRegionList(selectRegionItem.parent_id);
this.setRegionDoneStatus();
},
selectRegion(event) {
let that = this;
let regionIndex = event.target.dataset.regionIndex;
let regionItem = this.data.regionList[regionIndex];
let regionType = regionItem.type;
let selectRegionList = this.data.selectRegionList;
selectRegionList[regionType - 1] = regionItem;
if (regionType != 3) {
this.setData({
selectRegionList: selectRegionList,
regionType: regionType + 1
})
this.getRegionList(regionItem.id);
} else {
this.setData({
selectRegionList: selectRegionList
})
}
//重置下级区域为空
selectRegionList.map((item, index) => {
if (index > regionType - 1) {
item.id = 0;
item.name = index == 1 ? '城市' : '区县';
item.parent_id = 0;
}
return item;
});
this.setData({
selectRegionList: selectRegionList
})
that.setData({
regionList: that.data.regionList.map(item => {
//标记已选择的
if (that.data.regionType == item.type && that.data.selectRegionList[that.data.regionType - 1].id == item.id) {
item.selected = true;
} else {
item.selected = false;
}
return item;
})
});
this.setRegionDoneStatus();
},
doneSelectRegion() {
if (this.data.selectRegionDone === false) {
return false;
}
let address = this.data.address;
let selectRegionList = this.data.selectRegionList;
address.province_id = selectRegionList[0].id;
address.city_id = selectRegionList[1].id;
address.district_id = selectRegionList[2].id;
address.province_name = selectRegionList[0].name;
address.city_name = selectRegionList[1].name;
address.district_name = selectRegionList[2].name;
address.full_region = selectRegionList.map(item => {
return item.name;
}).join('');
this.setData({
address: address,
openSelectRegion: false
});
},
cancelSelectRegion() {
this.setData({
openSelectRegion: false,
regionType: this.data.regionDoneStatus ? 3 : 1
});
},
getRegionList(regionId) {
let that = this;
let regionType = that.data.regionType;
util.request(api.RegionList, { parentId: regionId }).then(function (res) {
if (res.errno === 0) {
that.setData({
regionList: res.data.map(item => {
//标记已选择的
if (regionType == item.type && that.data.selectRegionList[regionType - 1].id == item.id) {
item.selected = true;
} else {
item.selected = false;
}
return item;
})
});
}
});
},
cancelAddress(){
wx.navigateTo({
url: '/pages/ucenter/address/address',
})
},
saveAddress(){
console.log(this.data.address)
let address = this.data.address;
if (address.name == '') {
util.showErrorToast('请输入姓名');
return false;
}
if (address.mobile == '') {
util.showErrorToast('请输入手机号码');
return false;
}
if (address.district_id == 0) {
util.showErrorToast('请输入省市区');
return false;
}
if (address.address == '') {
util.showErrorToast('请输入详细地址');
return false;
}
let that = this;
util.request(api.AddressSave, {
id: address.id,
name: address.name,
mobile: address.mobile,
province_id: address.province_id,
city_id: address.city_id,
district_id: address.district_id,
address: address.address,
is_default: address.is_default,
}, 'POST').then(function (res) {
if (res.errno === 0) {
wx.navigateTo({
url: '/pages/ucenter/address/address',
})
}
});
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/ucenter/addressAdd/addressAdd.json
================================================
{
}
================================================
FILE: pages/ucenter/addressAdd/addressAdd.wxml
================================================
设为默认地址
{{item.name}}
确定
{{item.name}}
================================================
FILE: pages/ucenter/addressAdd/addressAdd.wxss
================================================
page{
height: 100%;
background: #f4f4f4;
}
.add-address .add-form{
background: #fff;
width: 100%;
height: auto;
overflow: hidden;
}
.add-address .form-item{
height: 116rpx;
padding-left: 31.25rpx;
border-bottom: 1px solid #d9d9d9;
display: flex;
align-items: center;
padding-right: 31.25rpx;
}
.add-address .input{
flex: 1;
height: 44rpx;
line-height: 44rpx;
overflow: hidden;
}
.add-address .form-default{
border-bottom: 1px solid #d9d9d9;
height: 96rpx;
background: #fafafa;
padding-top: 28rpx;
font-size: 28rpx;
}
.default-input{
margin: 0 auto;
display: block;
width: 240rpx;
height: 40rpx;
padding-left: 50rpx;
line-height: 40rpx;
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/checkbox-sed825af9d3-a6b8540d42.png) 1rpx -448rpx no-repeat;
background-size: 38rpx 486rpx;
font-size: 28rpx;
}
.default-input.selected{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/checkbox-sed825af9d3-a6b8540d42.png) 0 -192rpx no-repeat;
background-size: 38rpx 486rpx;
}
.add-address .btns{
position: fixed;
bottom: 0;
left: 0;
overflow: hidden;
display: flex;
height: 100rpx;
width: 100%;
}
.add-address .cannel,.add-address .save{
flex: 1;
height: 100rpx;
text-align: center;
line-height: 100rpx;
font-size: 28rpx;
color: #fff;
border:none;
border-radius: 0;
}
.add-address .cannel{
background: #333;
}
.add-address .save{
background: #b4282d;
}
.region-select{
width: 100%;
height: 600rpx;
background: #fff;
position: fixed;
z-index: 10;
left:0;
bottom: 0;
}
.region-select .hd{
height: 108rpx;
width: 100%;
border-bottom: 1px solid #f4f4f4;
padding: 46rpx 30rpx 0 30rpx;
}
.region-select .region-selected{
float: left;
height: 60rpx;
display: flex;
}
.region-select .region-selected .item{
max-width: 140rpx;
margin-right: 30rpx;
text-align: left;
line-height: 60rpx;
height: 100%;
color: #333;
font-size: 28rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.region-select .region-selected .item.disabled{
color: #999;
}
.region-select .region-selected .item.selected{
color: #b4282d;
}
.region-select .done{
float: right;
height: 60rpx;
width: 60rpx;
border: none;
background: #fff;
line-height: 60rpx;
text-align: center;
color: #333;
font-size: 28rpx;
}
.region-select .done.disabled{
color: #999;
}
.region-select .bd{
height: 492rpx;
width: 100%;
padding: 0 30rpx;
}
.region-select .region-list{
height: auto;
overflow: scroll;
}
.region-select .region-list .item{
width: 100%;
height: 104rpx;
line-height: 104rpx;
text-align: left;
color: #333;
font-size: 28rpx;
}
.region-select .region-list .item.selected{
color: #b4282d;
}
.bg-mask{
height: 100%;
width: 100%;
background: rgba(0, 0, 0, 0.4);
position: fixed;
top:0;
left:0;
z-index: 8;
}
================================================
FILE: pages/ucenter/collect/collect.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
typeId: 0,
collectList: []
},
getCollectList() {
let that = this;
util.request(api.CollectList, { typeId: that.data.typeId}).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
collectList: res.data.data
});
}
});
},
onLoad: function (options) {
this.getCollectList();
},
onReady: function () {
},
onShow: function () {
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
openGoods(event) {
let that = this;
let goodsId = this.data.collectList[event.currentTarget.dataset.index].value_id;
//触摸时间距离页面打开的毫秒数
var touchTime = that.data.touch_end - that.data.touch_start;
console.log(touchTime);
//如果按下时间大于350为长按
if (touchTime > 350) {
wx.showModal({
title: '',
content: '确定删除吗?',
success: function (res) {
if (res.confirm) {
util.request(api.CollectAddOrDelete, { typeId: that.data.typeId, valueId: goodsId}, 'POST').then(function (res) {
if (res.errno === 0) {
console.log(res.data);
wx.showToast({
title: '删除成功',
icon: 'success',
duration: 2000
});
that.getCollectList();
}
});
}
}
})
} else {
wx.navigateTo({
url: '/pages/goods/goods?id=' + goodsId,
});
}
},
//按下事件开始
touchStart: function (e) {
let that = this;
that.setData({
touch_start: e.timeStamp
})
console.log(e.timeStamp + '- touch-start')
},
//按下事件结束
touchEnd: function (e) {
let that = this;
that.setData({
touch_end: e.timeStamp
})
console.log(e.timeStamp + '- touch-end')
},
})
================================================
FILE: pages/ucenter/collect/collect.json
================================================
{
}
================================================
FILE: pages/ucenter/collect/collect.wxml
================================================
{{item.name}}
{{item.goods_brief}}
¥{{item.retail_price}}
================================================
FILE: pages/ucenter/collect/collect.wxss
================================================
page{
background: #f4f4f4;
min-height: 100%;
}
.container{
background: #f4f4f4;
min-height: 100%;
}
.collect-list{
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
padding-left: 30rpx;
border-top: 1px solid #e1e1e1;
}
.item{
height: 212rpx;
width: 720rpx;
background: #fff;
padding: 30rpx 30rpx 30rpx 0;
border-bottom: 1px solid #e1e1e1;
}
.item:last-child{
border-bottom: 1px solid #fff;
}
.item .img{
float: left;
width: 150rpx;
height: 150rpx;
}
.item .info{
float: right;
width: 540rpx;
height: 150rpx;
display: flex;
flex-direction: column;
justify-content: center;
padding-left: 20rpx;
}
.item .info .name{
font-size: 28rpx;
color: #333;
line-height: 40rpx;
}
.item .info .subtitle{
margin-top: 8rpx;
font-size: 24rpx;
color: #888;
line-height: 40rpx;
}
.item .info .price{
margin-top: 8rpx;
font-size: 28rpx;
color: #333;
line-height: 40rpx;
}
================================================
FILE: pages/ucenter/coupon/coupon.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
},
onLoad: function (options) {
},
onReady: function () {
},
onShow: function () {
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/ucenter/coupon/coupon.json
================================================
{
}
================================================
FILE: pages/ucenter/coupon/coupon.wxml
================================================
使用说明
新人专享
限时免单券
2017.06.08-2017.06.11
简约陶瓷马克杯专享;小米用户福利;限时购、三石福利价、礼品卡及详情页标注不可用券特殊商品除外
新人专享
限时免单券
2017.06.08-2017.06.11
简约陶瓷马克杯专享;小米用户福利;限时购、三石福利价、礼品卡及详情页标注不可用券特殊商品除外
================================================
FILE: pages/ucenter/coupon/coupon.wxss
================================================
page{
background: #f4f4f4;
min-height: 100%;
}
.container{
background: #f4f4f4;
min-height: 100%;
padding-top: 30rpx;
}
.coupon-form{
height: 110rpx;
width: 100%;
background: #fff;
padding-left: 30rpx;
padding-right: 30rpx;
padding-top: 20rpx;
display: flex;
}
.input-box{
flex: 1;
height: 70rpx;
color: #333;
font-size: 24rpx;
background: #fff;
position: relative;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4rpx;
margin-right: 30rpx;
}
.input-box .coupon-sn{
position: absolute;
top: 10rpx;
left: 30rpx;
height: 50rpx;
width: 100%;
color: #000;
line-height: 50rpx;
font-size: 24rpx;
}
.clear-icon{
position: absolute;
top: 21rpx;
right: 30rpx;
width: 28rpx;
height: 28rpx;
}
.add-btn{
height: 70rpx;
border:none;
width: 168rpx;
background: #b4282d;
border-radius: 0;
line-height: 70rpx;
color: #fff;
font-size: 28rpx;
}
.add-btn.disabled{
background: #ccc;
}
.help{
height: 72rpx;
line-height: 72rpx;
text-align: right;
padding-right: 30rpx;
background: url(https://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/couponHelp-4768607555.png) 590rpx center no-repeat;
background-size: 28rpx;
color: #999;
font-size: 24rpx;
}
.coupon-list{
width: 100%;
height: auto;
overflow: hidden;
padding-left: 30rpx;
padding-right: 30rpx;
}
.item{
position: relative;
height: 290rpx;
width: 100%;
background: linear-gradient(to right,#cfa568,#e3bf79);
margin-bottom: 30rpx;
padding-top: 52rpx;
}
.tag{
height: 32rpx;
background: #A48143;
padding-left: 16rpx;
padding-right: 16rpx;
position: absolute;
left: 20rpx;
color: #fff;
top: 20rpx;
font-size: 20rpx;
text-align: center;
line-height: 32rpx;
}
.content{
margin-top: 24rpx;
margin-left: 40rpx;
display: flex;
margin-right: 40rpx;
flex-direction: row;
align-items: center;
}
.content .left{
flex: 1;
}
.name{
font-size: 44rpx;
color: #fff;
margin-bottom: 14rpx;
}
.time{
font-size: 24rpx;
color: rgba(255,255,255, 0.8);
line-height: 30rpx;
}
.content .right{
width: 162rpx;
}
.go{
height: 48rpx;
border:none;
width: 162rpx;
background: rgba(255,255,255, 0.8);
border-radius: 4rpx;
line-height: 48rpx;
color: #b69150;
font-size: 24rpx;
}
.condition{
position: absolute;
width: 100%;
bottom: 0;
left:0;
height: 78rpx;
background: rgba(0,0,0,.08);
padding: 24rpx 40rpx;
display: flex;
flex-direction: row;
}
.condition .txt{
display: block;
height: 30rpx;
flex: 1;
overflow: hidden;
font-size: 24rpx;
line-height: 30rpx;
color: #fff;
}
.condition .icon{
margin-left: 30rpx;
width: 24rpx;
height: 24rpx;
}
================================================
FILE: pages/ucenter/express/express.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
orderId: 1,
expressInfo: {},
expressTraces: []
},
onLoad: function (options) {
this.setData({
orderId: options.id
});
this.getExpressInfo();
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
getExpressInfo() {
let that = this;
util.request(api.OrderExpress, { orderId: that.data.orderId }).then(function (res) {
if (res.errno === 0) {
that.setData({
expressInfo: res.data,
expressTraces: res.data.traces
});
}
});
},
updateExpress() {
this.getExpressInfo();
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/ucenter/express/express.json
================================================
{
"navigationBarTitleText": "物流详情"
}
================================================
FILE: pages/ucenter/express/express.wxml
================================================
物流单号:{{expressInfo.logistic_code}}
物流公司:{{expressInfo.shipper_name}}
更新时间:{{expressInfo.request_time}}
更新物流
{{item.content}}
{{item.datetime}}
================================================
FILE: pages/ucenter/express/express.wxss
================================================
page {
height: 100%;
width: 100%;
background: #f4f4f4;
}
.container {
height: 100%;
width: 100%;
}
.express-header {
border-top: 1px solid #d9d9d9;
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
display: flex;
padding: 20rpx 30rpx;
}
.express-header .left {
flex: 1;
height: 100%;
}
.express-header .left .txt {
height: 50rpx;
line-height: 50rpx;
overflow: hidden;
width: 100%;
}
.express-header .right {
width: 160rpx;
height: 100%;
display: flex;
}
.express-header .update-btn {
margin-top: 47rpx;
width: 158rpx;
height: 56rpx;
line-height: 54rpx;
overflow: hidden;
text-align: center;
border-radius: 8rpx;
color: #333;
border: 1px solid #666;
}
.express-body {
margin-top: 20rpx;
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
padding: 30rpx;
position: relative;
}
.current-icon{
height: 24rpx;
width: 24rpx;
position: absolute;
top: 30rpx;
left: 50rpx;
background: #b4282d;
border-radius: 24rpx;
}
.express-item {
height: auto;
width: 100%;
overflow: hidden;
display: flex;
margin-left: 30rpx;
border-left: 1px solid #d9d9d9;
}
.express-item .left {
width: 44rpx;
height: 100%;
overflow: hidden;
}
.express-item .right {
flex: 1;
height: 100%;
margin-left: 10rpx;
padding: 20rpx 0;
border-bottom: 1px solid #f1f2f4;
}
.express-item.item-0 .right {
padding-top: 0rpx;
}
.express-item:last-child .right{
border-bottom: none;
padding-bottom: 0rpx;
}
.express-item .right .info {
min-height: 42rpx;
height: auto;
overflow: hidden;
padding-right: 30rpx;
line-height: 42rpx;
color: #999;
}
.express-item.item-0 .right .info {
color: #b4282d;
}
.express-item .right .time {
min-height: 42rpx;
height: auto;
overflow: hidden;
line-height: 42rpx;
color: #999;
}
.express-item.item-0 .right .time {
color: #b4282d;
}
================================================
FILE: pages/ucenter/feedback/feedback.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
array: ['请选择反馈类型', '商品相关', '物流状况', '客户服务', '优惠活动', '功能异常', '产品建议', '其他'],
index: 0,
},
bindPickerChange: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
index: e.detail.value
})
},
onLoad: function (options) {
},
onReady: function () {
},
onShow: function () {
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/ucenter/feedback/feedback.json
================================================
{
}
================================================
FILE: pages/ucenter/feedback/feedback.wxml
================================================
{{array[index]}}
0/500
手机号码
================================================
FILE: pages/ucenter/feedback/feedback.wxss
================================================
page{
background: #f4f4f4;
min-height: 100%;
}
.container{
background: #f4f4f4;
min-height: 100%;
padding-top: 30rpx;
}
.fb-type{
height: 104rpx;
width: 100%;
background: #fff;
margin-bottom: 20rpx;
display: flex;
flex-direction: row;
align-items: center;
padding-left: 30rpx;
padding-right: 30rpx;
}
.fb-type .type-label{
height: 36rpx;
flex: 1;
color: #333;
font-size: 28rpx;
}
.fb-type .type-icon{
height: 36rpx;
width: 36rpx;
}
.fb-body{
width: 100%;
background: #fff;
height: 374rpx;
padding: 18rpx 30rpx 64rpx 30rpx;
}
.fb-body .content{
width: 100%;
height: 100%;
color: #333;
line-height: 40rpx;
font-size: 28rpx;
}
.fb-body .text-count{
padding-top: 17rpx;
line-height: 30rpx;
float: right;
color: #666;
font-size: 24rpx;
}
.fb-mobile{
height: 162rpx;
width: 100%;
}
.fb-mobile .label{
height: 58rpx;
width: 100%;
padding-top: 14rpx;
padding-bottom: 11rpx;
color: #7f7f7f;
font-size: 24rpx;
padding-left: 30rpx;
padding-right: 30rpx;
line-height: 33rpx;
}
.fb-mobile .mobile-box{
height: 104rpx;
width: 100%;
color: #333;
padding-left: 30rpx;
padding-right: 30rpx;
font-size: 24rpx;
background: #fff;
position: relative;
}
.fb-mobile .mobile{
position: absolute;
top: 27rpx;
left: 30rpx;
height: 50rpx;
width: 100%;
color: #333;
line-height: 50rpx;
font-size: 24rpx;
}
.clear-icon{
position: absolute;
top: 43rpx;
right: 30rpx;
width: 28rpx;
height: 28rpx;
}
.fb-btn{
width: 100%;
height: 98rpx;
line-height: 98rpx;
background: #b4282d;
position: fixed;
bottom: 0;
left: 0;
border-radius: 0;
color: #fff;
font-size: 28rpx;
}
================================================
FILE: pages/ucenter/footprint/footprint.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();
Page({
data: {
footprintList: [],
},
getFootprintList() {
let that = this;
util.request(api.FootprintList).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
footprintList: res.data.data
});
}
});
},
deleteItem (event){
let that = this;
let footprint = event.currentTarget.dataset.footprint;
var touchTime = that.data.touch_end - that.data.touch_start;
console.log(touchTime);
//如果按下时间大于350为长按
if (touchTime > 350) {
wx.showModal({
title: '',
content: '要删除所选足迹?',
success: function (res) {
if (res.confirm) {
util.request(api.FootprintDelete, { footprintId: footprint.id }, 'POST').then(function (res) {
if (res.errno === 0) {
wx.showToast({
title: '删除成功',
icon: 'success',
duration: 2000
});
that.getFootprintList();
}
});
console.log('用户点击确定')
}
}
});
} else {
wx.navigateTo({
url: '/pages/goods/goods?id=' + footprint.goods_id,
});
}
},
onLoad: function (options) {
this.getFootprintList();
},
onReady: function () {
},
onShow: function () {
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
},
//按下事件开始
touchStart: function (e) {
let that = this;
that.setData({
touch_start: e.timeStamp
})
console.log(e.timeStamp + '- touch-start')
},
//按下事件结束
touchEnd: function (e) {
let that = this;
that.setData({
touch_end: e.timeStamp
})
console.log(e.timeStamp + '- touch-end')
},
})
================================================
FILE: pages/ucenter/footprint/footprint.json
================================================
{
}
================================================
FILE: pages/ucenter/footprint/footprint.wxml
================================================
{{item[0].add_time}}
{{iitem.name}}
{{iitem.goods_brief}}
¥{{iitem.retail_price}}
================================================
FILE: pages/ucenter/footprint/footprint.wxss
================================================
page{
background: #f4f4f4;
min-height: 100%;
}
.container{
background: #f4f4f4;
min-height: 100%;
}
.footprint{
height: auto;
overflow: hidden;
width: 100%;
border-top: 1px solid #e1e1e1;
}
.day-item{
height: auto;
overflow: hidden;
width: 100%;
margin-bottom: 20rpx;
}
.day-hd{
height: 94rpx;
width: 100%;
line-height: 94rpx;
background: #fff;
padding-left: 30rpx;
color: #333;
font-size: 28rpx;
}
.day-list{
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
padding-left: 30rpx;
border-top: 1px solid #e1e1e1;
}
.item{
height: 212rpx;
width: 720rpx;
background: #fff;
padding: 30rpx 30rpx 30rpx 0;
border-bottom: 1px solid #e1e1e1;
}
.item:last-child{
border-bottom: 1px solid #fff;
}
.item .img{
float: left;
width: 150rpx;
height: 150rpx;
}
.item .info{
float: right;
width: 540rpx;
height: 150rpx;
display: flex;
flex-direction: column;
justify-content: center;
padding-left: 20rpx;
}
.item .info .name{
font-size: 28rpx;
color: #333;
line-height: 40rpx;
}
.item .info .subtitle{
margin-top: 8rpx;
font-size: 24rpx;
color: #888;
line-height: 40rpx;
}
.item .info .price{
margin-top: 8rpx;
font-size: 28rpx;
color: #333;
line-height: 40rpx;
}
================================================
FILE: pages/ucenter/index/index.js
================================================
const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
const user = require('../../../services/user.js');
const app = getApp();
Page({
data: {
userInfo: {},
showLoginDialog: false
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
},
onReady: function() {
},
onShow: function() {
this.setData({
userInfo: app.globalData.userInfo,
});
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
},
onUserInfoClick: function() {
if (wx.getStorageSync('token')) {
} else {
this.showLoginDialog();
}
},
showLoginDialog() {
this.setData({
showLoginDialog: true
})
},
onCloseLoginDialog () {
this.setData({
showLoginDialog: false
})
},
onDialogBody () {
// 阻止冒泡
},
onWechatLogin(e) {
if (e.detail.errMsg !== 'getUserInfo:ok') {
if (e.detail.errMsg === 'getUserInfo:fail auth deny') {
return false
}
wx.showToast({
title: '微信登录失败',
})
return false
}
util.login().then((res) => {
return util.request(api.AuthLoginByWeixin, {
code: res,
userInfo: e.detail
}, 'POST');
}).then((res) => {
console.log(res)
if (res.errno !== 0) {
wx.showToast({
title: '微信登录失败',
})
return false;
}
// 设置用户信息
this.setData({
userInfo: res.data.userInfo,
showLoginDialog: false
});
app.globalData.userInfo = res.data.userInfo;
app.globalData.token = res.data.token;
wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo));
wx.setStorageSync('token', res.data.token);
}).catch((err) => {
console.log(err)
})
},
onOrderInfoClick: function(event) {
wx.navigateTo({
url: '/pages/ucenter/order/order',
})
},
onSectionItemClick: function(event) {
},
// TODO 移到个人信息页面
exitLogin: function() {
wx.showModal({
title: '',
confirmColor: '#b4282d',
content: '退出登录?',
success: function(res) {
if (res.confirm) {
wx.removeStorageSync('token');
wx.removeStorageSync('userInfo');
wx.switchTab({
url: '/pages/index/index'
});
}
}
})
}
})
================================================
FILE: pages/ucenter/index/index.json
================================================
{
"navigationBarBackgroundColor": "#333",
"navigationBarTitleText": "我的",
"navigationBarTextStyle": "white",
"backgroundColor": "#f4f4f4"
}
================================================
FILE: pages/ucenter/index/index.wxml
================================================
{{ userInfo.nickname || '点击登录' }}
我的订单
优惠券
礼品卡
我的收藏
我的足迹
会员福利
地址管理
账号安全
联系客服
帮助中心
意见反馈
请选择登录方式
================================================
FILE: pages/ucenter/index/index.wxss
================================================
page{
height: 100%;
width: 100%;
background: #f4f4f4;
}
.container{
background: #f4f4f4;
height: auto;
overflow: hidden;
width: 100%;
}
.profile-info {
width: 100%;
height: 280rpx;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-start;
padding: 0 30.25rpx;
background: #333;
}
.profile-info .avatar {
height: 148rpx;
width: 148rpx;
border-radius: 50%;
border: 4rpx solid #fff;
}
.profile-info .info {
flex: 1;
height: 85rpx;
margin-left: 30rpx;
display: flex;
flex-direction: column;
justify-content: center;
}
.profile-info .name {
height: 45rpx;
line-height: 45rpx;
color: #fff;
font-size: 37.5rpx;
}
.profile-info .level {
height: 30rpx;
line-height: 30rpx;
margin-top: 10rpx;
color: #7f7f7f;
font-size: 30rpx;
}
.profile-info .btn {
width: 50rpx;
height: 50rpx;
margin-left: 10rpx;
border-radius: 50%;
}
.user-menu{
width: 100%;
height: auto;
overflow: hidden;
background: #fff;
}
.user-menu .item{
float: left;
width: 33.33333%;
height: 187.5rpx;
border-right: 1px solid rgba(0,0,0,.15);
border-bottom: 1px solid rgba(0,0,0,.15);
text-align: center;
}
.user-menu .item .a{
display: flex;
width: 100%;
height: 100%;
flex-direction: column;
align-items: center;
justify-content: center;
}
.user-menu .item.no-border {
border-right: 0;
}
.user-menu .item.item-bottom {
border-bottom: none;
}
.user-menu .icon{
margin: 0 auto;
display: block;
height: 52.803rpx;
width: 52.803rpx;
margin-bottom: 16rpx;
}
.user-menu .icon.order{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -437.5rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.coupon{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -62.4997rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.gift{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -187.5rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.address{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 0 no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.security{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -500rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.kefu{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -312.5rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.help{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -250rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .icon.feedback{
background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/sprites/ucenter-sdf6a55ee56-f2c2b9c2f0.png) 0 -125rpx no-repeat;
background-size: 52.803rpx;
}
.user-menu .txt{
display: block;
height: 24rpx;
width: 100%;
font-size: 24rpx;
color:#333;
}
.logout{
margin-top: 50rpx;
height: 101rpx;
width: 100%;
line-height: 101rpx;
text-align: center;
background: #fff;
color: #333;
font-size: 30rpx;
}
.dialog-login{
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.dialog-login .dialog-body{
width: 540rpx;
height: auto;
overflow: hidden;
background: #fff;
border-radius: 5px;
padding: 40rpx;
}
.dialog-login .dialog-body .title{
width: 100%;
text-align: center;
line-height: 60rpx;
}
.dialog-login .dialog-body .content{
width: 100%;
}
.dialog-login .dialog-body button{
margin-top: 30rpx;
}
================================================
FILE: pages/ucenter/order/order.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({
data:{
orderList: []
},
onLoad:function(options){
// 页面初始化 options为页面跳转所带来的参数
this.getOrderList();
},
getOrderList(){
let that = this;
util.request(api.OrderList).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
orderList: res.data.data
});
}
});
},
payOrder(){
wx.redirectTo({
url: '/pages/pay/pay',
})
},
onReady:function(){
// 页面渲染完成
},
onShow:function(){
// 页面显示
},
onHide:function(){
// 页面隐藏
},
onUnload:function(){
// 页面关闭
}
})
================================================
FILE: pages/ucenter/order/order.json
================================================
{}
================================================
FILE: pages/ucenter/order/order.wxml
================================================
订单编号:{{item.order_sn}}
{{item.order_status_text}}
{{gitem.goods_name}}
共{{gitem.number}}件商品
实付:¥{{item.actual_price}}
================================================
FILE: pages/ucenter/order/order.wxss
================================================
page{
height: 100%;
width: 100%;
background: #f4f4f4;
}
.orders{
height: auto;
width: 100%;
overflow: hidden;
}
.order{
margin-top: 20rpx;
background: #fff;
}
.order .h{
height: 83.3rpx;
line-height: 83.3rpx;
margin-left: 31.25rpx;
padding-right: 31.25rpx;
border-bottom: 1px solid #f4f4f4;
font-size: 30rpx;
color: #333;
}
.order .h .l{
float: left;
}
.order .h .r{
float: right;
color: #b4282d;
font-size: 24rpx;
}
.order .goods{
display: flex;
align-items: center;
height: 199rpx;
margin-left: 31.25rpx;
}
.order .goods .img{
height:145.83rpx;
width:145.83rpx;
background: #f4f4f4;
}
.order .goods .img image{
height:145.83rpx;
width:145.83rpx;
}
.order .goods .info{
height: 145.83rpx;
flex: 1;
padding-left: 20rpx;
}
.order .goods .name{
margin-top: 30rpx;
display: block;
height: 44rpx;
line-height: 44rpx;
color: #333;
font-size: 30rpx;
}
.order .goods .number{
display: block;
height: 37rpx;
line-height: 37rpx;
color: #666;
font-size: 25rpx;
}
.order .goods .status{
width:105rpx;
color: #b4282d;
font-size: 25rpx;
}
.order .b{
height: 103rpx;
line-height: 103rpx;
margin-left: 31.25rpx;
padding-right: 31.25rpx;
border-top: 1px solid #f4f4f4;
font-size: 30rpx;
color: #333;
}
.order .b .l{
float: left;
}
.order .b .r{
float: right;
}
.order .b .btn{
margin-top: 19rpx;
height: 64.5rpx;
line-height: 64.5rpx;
text-align: center;
padding: 0 20rpx;
border-radius: 5rpx;
font-size: 28rpx;
color: #fff;
background: #b4282d;
}
================================================
FILE: pages/ucenter/orderDetail/orderDetail.js
================================================
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({
data: {
orderId: 0,
orderInfo: {},
orderGoods: [],
handleOption: {}
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.setData({
orderId: options.id
});
this.getOrderDetail();
},
getOrderDetail() {
let that = this;
util.request(api.OrderDetail, {
orderId: that.data.orderId
}).then(function (res) {
if (res.errno === 0) {
console.log(res.data);
that.setData({
orderInfo: res.data.orderInfo,
orderGoods: res.data.orderGoods,
handleOption: res.data.handleOption
});
//that.payTimer();
}
});
},
payTimer() {
let that = this;
let orderInfo = that.data.orderInfo;
setInterval(() => {
console.log(orderInfo);
orderInfo.add_time -= 1;
that.setData({
orderInfo: orderInfo,
});
}, 1000);
},
payOrder() {
let that = this;
util.request(api.PayPrepayId, {
orderId: that.data.orderId || 15
}).then(function (res) {
if (res.errno === 0) {
const payParam = res.data;
wx.requestPayment({
'timeStamp': payParam.timeStamp,
'nonceStr': payParam.nonceStr,
'package': payParam.package,
'signType': payParam.signType,
'paySign': payParam.paySign,
'success': function (res) {
console.log(res)
},
'fail': function (res) {
console.log(res)
}
});
}
});
},
onReady: function () {
// 页面渲染完成
},
onShow: function () {
// 页面显示
},
onHide: function () {
// 页面隐藏
},
onUnload: function () {
// 页面关闭
}
})
================================================
FILE: pages/ucenter/orderDetail/orderDetail.json
================================================
{
}
================================================
FILE: pages/ucenter/orderDetail/orderDetail.wxml
================================================
下单时间:{{orderInfo.add_time}}
订单编号:{{orderInfo.order_sn}}
实付:¥{{orderInfo.actual_price}}
取消订单
去付款
商品信息
{{orderInfo.order_status_text}}
{{item.goods_name}}
x{{item.number}}
{{item.goods_specifition_name_value}}
¥{{item.retail_price}}
{{orderInfo.consignee}}
{{orderInfo.mobile}}
{{orderInfo.full_region + orderInfo.address}}
商品合计:
¥{{orderInfo.goods_price}}
运费:
¥{{orderInfo.freight_price}}
实付:
¥{{orderInfo.actual_price}}
================================================
FILE: pages/ucenter/orderDetail/orderDetail.wxss
================================================
page{
height: 100%;
width: 100%;
background: #f4f4f4;
}
.order-info{
padding-top: 25rpx;
background: #fff;
height: auto;
overflow: hidden;
}
.item-a{
padding-left: 31.25rpx;
height: 42.5rpx;
padding-bottom: 12.5rpx;
line-height: 30rpx;
font-size: 30rpx;
color: #666;
}
.item-b{
padding-left: 31.25rpx;
height: 29rpx;
line-height: 29rpx;
margin-top: 12.5rpx;
margin-bottom: 41.5rpx;
font-size: 30rpx;
color: #666;
}
.item-c{
margin-left: 31.25rpx;
border-top: 1px solid #f4f4f4;
height: 103rpx;
line-height: 103rpx;
}
.item-c .l{
float: left;
}
.item-c .r{
height: 103rpx;
float: right;
display: flex;
align-items: center;
padding-right: 16rpx;
}
.item-c .r .btn{
float: right;
}
.item-c .cost{
color: #b4282d;
}
.item-c .btn{
line-height: 66rpx;
border-radius: 5rpx;
text-align: center;
margin: 0 15rpx;
padding: 0 20rpx;
height: 66rpx;
}
.item-c .btn.active{
background: #b4282d;
color: #fff;
}
.order-goods{
margin-top: 20rpx;
background: #fff;
}
.order-goods .h{
height: 93.75rpx;
line-height: 93.75rpx;
margin-left: 31.25rpx;
border-bottom: 1px solid #f4f4f4;
padding-right: 31.25rpx;
}
.order-goods .h .label{
float: left;
font-size: 30rpx;
color: #333;
}
.order-goods .h .status{
float: right;
font-size: 30rpx;
color: #b4282d;
}
.order-goods .item{
display: flex;
align-items: center;
height: 192rpx;
margin-left: 31.25rpx;
padding-right: 31.25rpx;
border-bottom: 1px solid #f4f4f4;
}
.order-goods .item:last-child{
border-bottom: none;
}
.order-goods .item .img{
height: 145.83rpx;
width: 145.83rpx;
background: #f4f4f4;
}
.order-goods .item .img image{
height: 145.83rpx;
width: 145.83rpx;
}
.order-goods .item .info{
flex: 1;
height: 145.83rpx;
margin-left: 20rpx;
}
.order-goods .item .t{
margin-top: 8rpx;
height: 33rpx;
line-height: 33rpx;
margin-bottom: 10.5rpx;
}
.order-goods .item .t .name{
display: block;
float: left;
height: 33rpx;
line-height: 33rpx;
color: #333;
font-size: 30rpx;
}
.order-goods .item .t .number{
display: block;
float: right;
height: 33rpx;
text-align: right;
line-height: 33rpx;
color: #333;
font-size: 30rpx;
}
.order-goods .item .attr{
height: 29rpx;
line-height: 29rpx;
color: #666;
margin-bottom: 25rpx;
font-size: 25rpx;
}
.order-goods .item .price{
height: 30rpx;
line-height: 30rpx;
color: #333;
font-size: 30rpx;
}
.order-bottom{
margin-top: 20rpx;
padding-left: 31.25rpx;
height: auto;
overflow: hidden;
background: #fff;
}
.order-bottom .address{
height: 128rpx;
padding-top: 25rpx;
border-bottom: 1px solid #f4f4f4;
}
.order-bottom .address .t{
height: 35rpx;
line-height: 35rpx;
margin-bottom: 7.5rpx;
}
.order-bottom .address .name{
display: inline-block;
height: 35rpx;
width: 140rpx;
line-height: 35rpx;
font-size: 25rpx;
}
.order-bottom .address .mobile{
display: inline-block;
height: 35rpx;
line-height: 35rpx;
font-size: 25rpx;
}
.order-bottom .address .b{
height: 35rpx;
line-height: 35rpx;
font-size: 25rpx;
}
.order-bottom .total{
height: 106rpx;
padding-top: 20rpx;
border-bottom: 1px solid #f4f4f4;
}
.order-bottom .total .t{
height: 25rpx;
line-height: 25rpx;
margin-bottom: 7.5rpx;
display: flex;
}
.order-bottom .total .label{
width: 140rpx;
display: inline-block;
height: 35rpx;
line-height: 35rpx;
font-size: 25rpx;
}
.order-bottom .total .txt{
flex: 1;
display: inline-block;
height: 35rpx;
line-height: 35rpx;
font-size: 25rpx;
}
.order-bottom .pay-fee{
height: 81rpx;
line-height: 81rpx;
}
.order-bottom .pay-fee .label{
display: inline-block;
width: 140rpx;
color: #b4282d;
}
.order-bottom .pay-fee .txt{
display: inline-block;
width: 140rpx;
color: #b4282d;
}
================================================
FILE: services/pay.js
================================================
/**
* 支付相关服务
*/
const util = require('../utils/util.js');
const api = require('../config/api.js');
/**
* 判断用户是否登录
*/
function payOrder(orderId) {
return new Promise(function (resolve, reject) {
util.request(api.PayPrepayId, {
orderId: orderId
}).then((res) => {
console.log(res)
if (res.errno === 0) {
const payParam = res.data;
wx.requestPayment({
'timeStamp': payParam.timeStamp,
'nonceStr': payParam.nonceStr,
'package': payParam.package,
'signType': payParam.signType,
'paySign': payParam.paySign,
'success': function (res) {
resolve(res);
},
'fail': function (res) {
reject(res);
},
'complete': function (res) {
reject(res);
}
});
} else {
reject(res);
}
});
});
}
module.exports = {
payOrder,
};
================================================
FILE: services/user.js
================================================
/**
* 用户相关服务
*/
const util = require('../utils/util.js');
const api = require('../config/api.js');
/**
* 调用微信登录
*/
function loginByWeixin() {
let code = null;
return new Promise(function (resolve, reject) {
return util.login().then((res) => {
code = res.code;
return util.getUserInfo();
}).then((userInfo) => {
//登录远程服务器
util.request(api.AuthLoginByWeixin, { code: code, userInfo: userInfo }, 'POST').then(res => {
if (res.errno === 0) {
//存储用户信息
wx.setStorageSync('userInfo', res.data.userInfo);
wx.setStorageSync('token', res.data.token);
resolve(res);
} else {
reject(res);
}
}).catch((err) => {
reject(err);
});
}).catch((err) => {
reject(err);
})
});
}
/**
* 判断用户是否登录
*/
function checkLogin() {
return new Promise(function (resolve, reject) {
if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
util.checkSession().then(() => {
resolve(true);
}).catch(() => {
reject(false);
});
} else {
reject(false);
}
});
}
module.exports = {
loginByWeixin,
checkLogin,
};
================================================
FILE: utils/util.js
================================================
var api = require('../config/api.js')
function formatTime(date) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}
/**
* 封封微信的的request
*/
function request(url, data = {}, method = "GET") {
return new Promise(function (resolve, reject) {
wx.request({
url: url,
data: data,
method: method,
header: {
'Content-Type': 'application/json',
'X-Nideshop-Token': wx.getStorageSync('token')
},
success: function (res) {
console.log("success");
if (res.statusCode == 200) {
if (res.data.errno == 401) {
//需要登录后才可以操作
let code = null;
return login().then((res) => {
code = res.code;
return getUserInfo();
}).then((userInfo) => {
//登录远程服务器
request(api.AuthLoginByWeixin, { code: code, userInfo: userInfo }, 'POST').then(res => {
if (res.errno === 0) {
//存储用户信息
wx.setStorageSync('userInfo', res.data.userInfo);
wx.setStorageSync('token', res.data.token);
resolve(res);
} else {
reject(res);
}
}).catch((err) => {
reject(err);
});
}).catch((err) => {
reject(err);
})
} else {
resolve(res.data);
}
} else {
reject(res.errMsg);
}
},
fail: function (err) {
reject(err)
console.log("failed")
}
})
});
}
function get(url, data = {}) {
return request(url, data, 'GET')
}
function post(url, data = {}) {
return request(url, data, 'POST')
}
/**
* 检查微信会话是否过期
*/
function checkSession() {
return new Promise(function (resolve, reject) {
wx.checkSession({
success: function () {
resolve(true);
},
fail: function () {
reject(false);
}
})
});
}
/**
* 调用微信登录
*/
function login() {
return new Promise(function (resolve, reject) {
wx.login({
success: function (res) {
if (res.code) {
resolve(res.code);
} else {
reject(res);
}
},
fail: function (err) {
reject(err);
}
});
});
}
function getUserInfo() {
return new Promise(function (resolve, reject) {
wx.getUserInfo({
withCredentials: true,
success: function (res) {
if (res.detail.errMsg === 'getUserInfo:ok') {
resolve(res);
} else {
reject(res)
}
},
fail: function (err) {
reject(err);
}
})
});
}
function redirect(url) {
//判断页面是否需要登录
if (false) {
wx.redirectTo({
url: '/pages/auth/login/login'
});
return false;
} else {
wx.redirectTo({
url: url
});
}
}
function showErrorToast(msg) {
wx.showToast({
title: msg,
image: '/static/images/icon_error.png'
})
}
module.exports = {
formatTime,
request,
get,
post,
redirect,
showErrorToast,
checkSession,
login,
getUserInfo,
}