├── pages
├── index
│ ├── index.json
│ ├── index.js
│ ├── index.wxss
│ └── index.wxml
├── auth
│ └── login
│ │ ├── login.json
│ │ ├── login.wxml
│ │ ├── login.wxss
│ │ └── login.js
├── goods
│ ├── detail
│ │ ├── detail.json
│ │ ├── detail.wxml
│ │ ├── detail.js
│ │ └── detail.wxss
│ └── list
│ │ ├── list.json
│ │ ├── list.wxml
│ │ ├── list.wxss
│ │ └── list.js
├── member
│ └── index
│ │ ├── index.json
│ │ ├── index.js
│ │ ├── index.wxml
│ │ └── index.wxss
├── shopping
│ └── cart
│ │ ├── cart.json
│ │ ├── cart.wxml
│ │ ├── cart.wxss
│ │ └── cart.js
└── catalog
│ ├── catalog.json
│ ├── catalog.wxml
│ ├── catalog.wxss
│ └── catalog.js
├── images
├── 天猫提示-出错.png
├── icon_bouns.png
├── icon_cart.png
├── icon_delete.png
├── icon_error.png
├── icon_goods.png
├── icon_help.png
├── icon_home.png
├── icon_member.png
├── icon_notice.png
├── icon_right.png
├── icon_search.png
├── icon_address.png
├── icon_catalog.png
├── icon_collect.png
├── icon_integral.png
├── icon_success.png
├── icon_warning.png
├── icon_cart_active.png
├── icon_cart_empty.png
├── icon_home_active.png
├── icon_order_paid.png
├── icon_member_active.png
├── icon_order_comment.png
├── icon_catalog_active.png
├── icon_collect_selected.png
├── icon_order_deliveried.png
└── icon_order_delivering.png
├── app.wxss
├── app.js
├── README.md
├── app.json
├── utils
└── util.js
└── libs
└── wxParse
├── wxParse.wxss
├── wxParse.js
├── htmlparser.js
├── wxDiscode.js
├── html2json.js
└── wxParse.wxml
/pages/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/auth/login/login.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/goods/detail/detail.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/member/index/index.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/shopping/cart/cart.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/catalog/catalog.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "分类"
3 | }
--------------------------------------------------------------------------------
/pages/goods/list/list.json:
--------------------------------------------------------------------------------
1 | {
2 | "navigationBarTitleText": "商品列表"
3 | }
--------------------------------------------------------------------------------
/images/天猫提示-出错.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/天猫提示-出错.png
--------------------------------------------------------------------------------
/images/icon_bouns.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_bouns.png
--------------------------------------------------------------------------------
/images/icon_cart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_cart.png
--------------------------------------------------------------------------------
/images/icon_delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_delete.png
--------------------------------------------------------------------------------
/images/icon_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_error.png
--------------------------------------------------------------------------------
/images/icon_goods.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_goods.png
--------------------------------------------------------------------------------
/images/icon_help.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_help.png
--------------------------------------------------------------------------------
/images/icon_home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_home.png
--------------------------------------------------------------------------------
/images/icon_member.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_member.png
--------------------------------------------------------------------------------
/images/icon_notice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_notice.png
--------------------------------------------------------------------------------
/images/icon_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_right.png
--------------------------------------------------------------------------------
/images/icon_search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_search.png
--------------------------------------------------------------------------------
/images/icon_address.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_address.png
--------------------------------------------------------------------------------
/images/icon_catalog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_catalog.png
--------------------------------------------------------------------------------
/images/icon_collect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_collect.png
--------------------------------------------------------------------------------
/images/icon_integral.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_integral.png
--------------------------------------------------------------------------------
/images/icon_success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_success.png
--------------------------------------------------------------------------------
/images/icon_warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_warning.png
--------------------------------------------------------------------------------
/images/icon_cart_active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_cart_active.png
--------------------------------------------------------------------------------
/images/icon_cart_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_cart_empty.png
--------------------------------------------------------------------------------
/images/icon_home_active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_home_active.png
--------------------------------------------------------------------------------
/images/icon_order_paid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_order_paid.png
--------------------------------------------------------------------------------
/images/icon_member_active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_member_active.png
--------------------------------------------------------------------------------
/images/icon_order_comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_order_comment.png
--------------------------------------------------------------------------------
/images/icon_catalog_active.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_catalog_active.png
--------------------------------------------------------------------------------
/images/icon_collect_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_collect_selected.png
--------------------------------------------------------------------------------
/images/icon_order_deliveried.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_order_deliveried.png
--------------------------------------------------------------------------------
/images/icon_order_delivering.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tumobi/eweapp/HEAD/images/icon_order_delivering.png
--------------------------------------------------------------------------------
/pages/auth/login/login.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
13 |
14 |
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | page{
3 | background: #f4f4f4;
4 | color: #333;
5 | font-size: 14px;
6 | min-height: 100%;
7 | }
8 |
9 | view, text, image, navigator, input, button{
10 | box-sizing: border-box;
11 | }
12 |
13 | .container {
14 | min-height: 100%;
15 | box-sizing: border-box;
16 | background: #f4f4f4;
17 | }
18 |
19 | .list-empty{
20 | height: 100%;
21 | width: 100%;
22 | display: flex;
23 | justify-content: center;
24 | flex-direction: column;
25 | align-items: center;
26 | }
27 |
28 | .list-empty .icon{
29 | height: 200rpx;
30 | width: 200rpx;
31 | }
32 |
33 | .list-empty .msg{
34 | line-height: 40rpx;
35 | font-size: 12px;
36 | color: #999;
37 | }
38 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function() {
4 | //调用API从本地缓存中获取数据
5 | var logs = wx.getStorageSync('logs') || []
6 | logs.unshift(Date.now())
7 | wx.setStorageSync('logs', logs)
8 | },
9 |
10 | getUserInfo: function(cb) {
11 | var that = this
12 | if (this.globalData.userInfo) {
13 | typeof cb == "function" && cb(this.globalData.userInfo)
14 | } else {
15 | //调用登录接口
16 | wx.getUserInfo({
17 | withCredentials: false,
18 | success: function(res) {
19 | that.globalData.userInfo = res.userInfo
20 | typeof cb == "function" && cb(that.globalData.userInfo)
21 | }
22 | })
23 | }
24 | },
25 |
26 | globalData: {
27 | userInfo: null
28 | }
29 | })
30 |
--------------------------------------------------------------------------------
/pages/catalog/catalog.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | {{item.name}}
11 |
12 | {{sitem.name}}
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/pages/auth/login/login.wxss:
--------------------------------------------------------------------------------
1 | /* login.wxss */
2 | page, .container{
3 | height: 100%;
4 | background: #fff;
5 | }
6 |
7 | .login{
8 | padding: 100rpx 30rpx 0 30rpx;
9 | width: 100%;
10 | height: 100%;
11 | overflow: hidden;
12 | background: #fff;
13 | }
14 |
15 | .login .input-item{
16 | width: 690rpx;
17 | height: 68rpx;
18 | border: 1px solid #e6e6e6;
19 | margin: 40rpx 0;
20 | padding-left: 20rpx;
21 | line-height: 68rpx;
22 | font-size: 14px;
23 | color: #666;
24 | }
25 |
26 | .login .btn-item{
27 | width: 690rpx;
28 | height: 68rpx;
29 | background: #d81e06;
30 | margin-top: 40rpx;
31 | text-align: center;
32 | line-height: 68rpx;
33 | font-size: 14px;
34 | color: #fff;
35 | border-radius: 0;
36 | border: none;
37 | }
38 |
39 | .login .link-item{
40 | margin-top: 20rpx;
41 | height: 40rpx;
42 | line-height: 40rpx;
43 | color: #999;
44 | font-size: 12px;
45 | }
46 |
47 | .login .link-item .l{
48 | float: left;
49 | }
50 |
51 | .login .link-item .r{
52 | float: right;
53 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # eweapp
2 | ECShop非官方版微信小程序商城,基于3.6版本appserver接口,100%兼容原有程序,没有对原有程序代码进行过任何改动。
3 | > 注意:本项目还在开发中,功能还未完善,请匆商用。
4 |
5 | # 实时更新地址
6 | GitHub: https://github.com/tumobi/eweapp
7 | 如果您觉得不错,欢迎star。
8 |
9 | # 功能列表
10 | + [x] 首页: 轮播图、商城滚动公告、精品推荐、新品上市、销量排行
11 | + [x] 分类:商品搜索功能、分类目录展示
12 | + [x] 我的:退出登录功能、用户信息显示、订单统计
13 | + [x] 商品列表:排序功能、底部加载更多商品
14 | + [x] 商品详情:规格数量选择、加入购物车、收藏功能、关联商品
15 | + [ ] 登录:用户名或邮箱登录、用户注册、找回密码
16 | + [ ] 购物车:购物车商品规格数量修改、删除、下单支付
17 | + [ ] 订单中心:订单列表、详单详情、物流信息
18 | + [ ] 红包/优惠券
19 | + [ ] 收货地址
20 | + [ ] 其它功能正在开发中...
21 |
22 | # 界面预览
23 |
24 | 
25 |
26 | 
27 |
28 | 
29 |
30 | # 交流反馈
31 | QQ 群:490201793
32 |
33 | 公众号:nideshop
34 |
35 | # 关于商用
36 | 由于本项目使用到ECShop 3.6 appserver接口开发,如要用于商业用途,请先取得ECShop的授权。
37 |
--------------------------------------------------------------------------------
/pages/catalog/catalog.wxss:
--------------------------------------------------------------------------------
1 | /* catalog.wxss */
2 | page{
3 | background: #f4f4f4;
4 | }
5 |
6 | .search{
7 | width: 100%;
8 | height: 150rpx;
9 | background: #fff;
10 | display: flex;
11 | justify-content: center;
12 | align-items: center;
13 | }
14 |
15 | .search .form{
16 | height: 60rpx;
17 | width: 690rpx;
18 | background: #f4f4f4;
19 | border-radius: 30rpx;
20 | display: flex;
21 | justify-content: center;
22 | align-items: center;
23 | }
24 |
25 | .search .input{
26 | height: 40rpx;
27 | width: 600rpx;
28 | }
29 |
30 | .search .btn{
31 | height: 40rpx;
32 | width: 40rpx;
33 | }
34 |
35 | .catalog{
36 | margin-top: 20rpx;
37 | background: #f4f4f4;
38 | }
39 |
40 | .catalog .item{
41 | margin-bottom: 20rpx;
42 | background: #fff;
43 | }
44 |
45 | .catalog .item .h{
46 | height: 100rpx;
47 | text-align: center;
48 | line-height: 100rpx;
49 | }
50 |
51 | .catalog .item .b{
52 | height: auto;
53 | overflow: hidden;
54 | padding: 0 10rpx;
55 | }
56 |
57 | .catalog .item .a{
58 | display: block;
59 | float: left;
60 | font-size: 12px;
61 | color: #666;
62 | margin: 0 10rpx 20rpx 10rpx;
63 | border: 1px solid #f4f4f4;
64 | padding:10rpx 20rpx;
65 | }
--------------------------------------------------------------------------------
/pages/index/index.js:
--------------------------------------------------------------------------------
1 | //index.js
2 | const util = require('../../utils/util.js');
3 |
4 | //获取应用实例
5 | var app = getApp()
6 | Page({
7 | data: {
8 | banners: [],
9 | notices: [],
10 | goodProducts: [],
11 | hotProducts: [],
12 | recentlyProducts: [],
13 | },
14 |
15 | onLoad: function () {
16 | wx.showLoading({
17 | title: '',
18 | });
19 | this.getBanner();
20 | this.getNotices();
21 | this.getPorducts();
22 | },
23 | getBanner() {
24 | util.request(util.apiUrl + 'ecapi.banner.list', 'POST').then((res) => {
25 | this.setData({
26 | banners: res.banners
27 | })
28 | });
29 | },
30 | getNotices() {
31 | util.request(util.apiUrl + 'ecapi.notice.list', 'POST', {
32 | page: 1,
33 | per_page: 5
34 | }).then((res) => {
35 | this.setData({
36 | notices: res.notices
37 | });
38 | });
39 | },
40 | getPorducts() {
41 | util.request(util.apiUrl + 'ecapi.home.product.list', 'POST').then((res) => {
42 | this.setData({
43 | goodProducts: res.good_products,
44 | hotProducts: res.hot_products,
45 | recentlyProducts: res.recently_products
46 | });
47 | wx.hideLoading();
48 | }).catch(err => {
49 | wx.hideLoading();
50 | });
51 | }
52 | })
53 |
--------------------------------------------------------------------------------
/pages/goods/list/list.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 综合
7 |
8 |
9 | 销量
10 |
11 |
12 | 新品
13 |
14 |
15 | 价格
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | {{item.name}}
24 | ¥{{item.current_price}}
25 |
26 |
27 |
28 |
29 |
30 | 找到不商品
31 |
32 |
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/index/index",
4 | "pages/goods/detail/detail",
5 | "pages/member/index/index",
6 | "pages/goods/list/list",
7 | "pages/catalog/catalog",
8 | "pages/shopping/cart/cart",
9 | "pages/auth/login/login"
10 | ],
11 | "window": {
12 | "backgroundTextStyle": "light",
13 | "navigationBarBackgroundColor": "#fafafa",
14 | "navigationBarTitleText": "ecshop小程序商城",
15 | "navigationBarTextStyle": "black"
16 | },
17 | "tabBar": {
18 | "color": "#2c2c2c",
19 | "selectedColor": "#d81e06",
20 | "backgroundColor": "#fafafa",
21 | "borderStyle": "white",
22 | "list": [
23 | {
24 | "pagePath": "pages/index/index",
25 | "text": "首页",
26 | "iconPath": "images/icon_home.png",
27 | "selectedIconPath": "images/icon_home_active.png"
28 | },
29 | {
30 | "pagePath": "pages/catalog/catalog",
31 | "text": "分类",
32 | "iconPath": "images/icon_catalog.png",
33 | "selectedIconPath": "images/icon_catalog_active.png"
34 | },
35 | {
36 | "pagePath": "pages/shopping/cart/cart",
37 | "text": "购物车",
38 | "iconPath": "images/icon_cart.png",
39 | "selectedIconPath": "images/icon_cart_active.png"
40 | },
41 | {
42 | "pagePath": "pages/member/index/index",
43 | "text": "我的",
44 | "iconPath": "images/icon_member.png",
45 | "selectedIconPath": "images/icon_member_active.png"
46 | }
47 | ]
48 | }
49 | }
--------------------------------------------------------------------------------
/pages/catalog/catalog.js:
--------------------------------------------------------------------------------
1 | // catalog.js
2 | const util = require('../../utils/util.js')
3 |
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | keyword: '',
11 | categories: []
12 | },
13 |
14 | /**
15 | * 生命周期函数--监听页面加载
16 | */
17 | onLoad: function (options) {
18 | this.getCategories();
19 | },
20 |
21 | bindKeywordConfirm(event){
22 | this.setData({
23 | keyword: event.detail.value
24 | })
25 |
26 | this.bindSearchTap();
27 | },
28 |
29 | bindKeywordInput(event){
30 | this.setData({
31 | keyword: event.detail.value
32 | })
33 | },
34 |
35 | /**
36 | * 点击搜索
37 | */
38 | bindSearchTap(){
39 | wx.navigateTo({
40 | url: '/pages/goods/list/list?keyword='+ this.data.keyword,
41 | })
42 | },
43 |
44 | getCategories() {
45 | util.request(util.apiUrl + 'ecapi.category.list', 'POST', {
46 | page: 1,
47 | per_page: 100
48 | }).then((res) => {
49 | console.log(res.categories)
50 | this.setData({
51 | categories: res.categories
52 | })
53 | });
54 | },
55 |
56 | /**
57 | * 生命周期函数--监听页面初次渲染完成
58 | */
59 | onReady: function () {
60 |
61 | },
62 |
63 | /**
64 | * 生命周期函数--监听页面显示
65 | */
66 | onShow: function () {
67 |
68 | },
69 |
70 | /**
71 | * 生命周期函数--监听页面隐藏
72 | */
73 | onHide: function () {
74 |
75 | },
76 |
77 | /**
78 | * 生命周期函数--监听页面卸载
79 | */
80 | onUnload: function () {
81 |
82 | },
83 |
84 | /**
85 | * 页面相关事件处理函数--监听用户下拉动作
86 | */
87 | onPullDownRefresh: function () {
88 |
89 | },
90 |
91 | /**
92 | * 页面上拉触底事件的处理函数
93 | */
94 | onReachBottom: function () {
95 |
96 | },
97 |
98 | /**
99 | * 用户点击右上角分享
100 | */
101 | onShareAppMessage: function () {
102 |
103 | }
104 | })
--------------------------------------------------------------------------------
/pages/shopping/cart/cart.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 您的购物车没有商品
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | {{item.product.name}}
18 |
19 |
20 | {{item.property}}
21 |
22 | ¥{{item.price}}
23 |
24 | -
25 |
26 | +
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | 全选({{cartTotal.checkedGoodsCount}})
37 | {{'¥' + cartTotal.checkedGoodsAmount}}
38 | 去结算
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/utils/util.js:
--------------------------------------------------------------------------------
1 | const apiUrl = 'http://api.ecshop.dev/v2/'; //接口地址
2 |
3 | function formatTime(date) {
4 | var year = date.getFullYear()
5 | var month = date.getMonth() + 1
6 | var day = date.getDate()
7 |
8 | var hour = date.getHours()
9 | var minute = date.getMinutes()
10 | var second = date.getSeconds()
11 |
12 |
13 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
14 | }
15 |
16 | function formatNumber(n) {
17 | n = n.toString()
18 | return n[1] ? n : '0' + n
19 | }
20 |
21 |
22 | function request(url, method = 'GET', data = {}) {
23 |
24 | let header = {
25 | 'content-type': 'application/json',
26 | 'X-ECAPI-Sign': '',
27 | 'X-ECAPI-UDID': '',
28 | 'X-ECAPI-UserAgent': 'Platform/Wechat',
29 | 'X-ECAPI-Ver': '1.1.0'
30 | };
31 |
32 | let token = wx.getStorageSync('token') || '';
33 | if (token) {
34 | header['X-ECAPI-Authorization'] = token
35 | }
36 |
37 | return new Promise(function (resolve, reject) {
38 | wx.request({
39 | url: url,
40 | method: method,
41 | data: data,
42 | header: header,
43 | success: function (res) {
44 | if (res.data.error_code === 0) {
45 | resolve(res.data);
46 | } else {
47 | reject(res.data);
48 | }
49 | },
50 | fail: function (err) {
51 | wx.showToast({
52 | title: '网络加载失败',
53 | });
54 | }
55 | });
56 | });
57 | }
58 |
59 |
60 | function showToast(title, type = 'error') {
61 | let image = '';
62 | switch (type) {
63 | case 'error':
64 | image = '/images/icon_error.png'
65 | break;
66 | case 'success':
67 | image = '/images/icon_success.png'
68 | break;
69 | case 'warning':
70 | image = '/images/icon_warning.png'
71 | break;
72 | }
73 | wx.showToast({
74 | title: title,
75 | image: image,
76 | duration: 0,
77 | mask: true,
78 | success: function (res) { },
79 | fail: function (res) { },
80 | complete: function (res) { },
81 | })
82 | }
83 |
84 | module.exports = {
85 | formatTime: formatTime,
86 | request: request,
87 | showToast: showToast,
88 | apiUrl: apiUrl,
89 | }
90 |
91 |
--------------------------------------------------------------------------------
/pages/auth/login/login.js:
--------------------------------------------------------------------------------
1 | // login.js
2 | const util = require('../../../utils/util.js');
3 |
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | username: '',
11 | password: ''
12 | },
13 |
14 | /**
15 | * 生命周期函数--监听页面加载
16 | */
17 | onLoad: function (options) {
18 | },
19 |
20 | formSubmit: function (e) {
21 | this.login();
22 | },
23 |
24 | bindUsernameInput: function (e) {
25 | this.setData({
26 | username: e.detail.value
27 | })
28 | },
29 |
30 | bindPasswordInput: function (e) {
31 | this.setData({
32 | password: e.detail.value
33 | })
34 | },
35 |
36 | login() {
37 |
38 | if (this.data.username.length <=0) {
39 | util.showToast('请输入用户名')
40 | return false;
41 | }
42 |
43 | if (this.data.password.length <= 0) {
44 | util.showToast('请输入密码')
45 | return false;
46 | }
47 |
48 | util.request(util.apiUrl + 'ecapi.auth.signin', 'POST', {
49 | username: this.data.username,
50 | password: this.data.password
51 | }).then((res) => {
52 | this.setData({
53 | token: res.token,
54 | user: res.user
55 | });
56 |
57 | wx.setStorageSync('token', res.token);
58 | wx.setStorageSync('user', res.user);
59 |
60 | //跳转到一个页面
61 | wx.navigateBack({
62 |
63 | })
64 |
65 | }).catch(err => {
66 | util.showToast('登录失败')
67 | });
68 | },
69 |
70 | /**
71 | * 生命周期函数--监听页面初次渲染完成
72 | */
73 | onReady: function () {
74 |
75 | },
76 |
77 | /**
78 | * 生命周期函数--监听页面显示
79 | */
80 | onShow: function () {
81 |
82 | },
83 |
84 | /**
85 | * 生命周期函数--监听页面隐藏
86 | */
87 | onHide: function () {
88 |
89 | },
90 |
91 | /**
92 | * 生命周期函数--监听页面卸载
93 | */
94 | onUnload: function () {
95 |
96 | },
97 |
98 | /**
99 | * 页面相关事件处理函数--监听用户下拉动作
100 | */
101 | onPullDownRefresh: function () {
102 |
103 | },
104 |
105 | /**
106 | * 页面上拉触底事件的处理函数
107 | */
108 | onReachBottom: function () {
109 |
110 | },
111 |
112 | /**
113 | * 用户点击右上角分享
114 | */
115 | onShareAppMessage: function () {
116 |
117 | }
118 | })
--------------------------------------------------------------------------------
/pages/member/index/index.js:
--------------------------------------------------------------------------------
1 | // index.js
2 | const util = require('../../../utils/util.js');
3 |
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | user: {
11 | id: 0,
12 | username: 'Hi 你好',
13 | avatar: ''
14 | },
15 | orderTotal: {
16 | "created": 0,
17 | "paid": 0,
18 | "delivering": 0,
19 | "deliveried": 0,
20 | "finished": 0,
21 | "cancelled": 0
22 | }
23 | },
24 |
25 | /**
26 | * 生命周期函数--监听页面加载
27 | */
28 | onLoad: function (options) {
29 |
30 | },
31 |
32 | logout (){
33 | wx.removeStorageSync('token');
34 | wx.removeStorageSync('user');
35 | util.showToast('退出登录成功', 'success');
36 | setTimeout(function(){
37 | wx.switchTab({
38 | url: '/pages/index/index',
39 | })
40 | }, 1500)
41 | },
42 |
43 | /**
44 | * 设置会员信息
45 | */
46 | setUserInfo() {
47 | let user = wx.getStorageSync('user');
48 | this.setData({
49 | user: user
50 | })
51 | },
52 |
53 | /**
54 | * 获取订单数量
55 | */
56 | getOrderTotal() {
57 | util.request(util.apiUrl + 'ecapi.order.subtotal', 'POST').then((res) => {
58 | this.setData({
59 | orderTotal: res.subtotal,
60 | });
61 | });
62 | },
63 |
64 | /**
65 | * 绑定用用户名和头像的事件
66 | */
67 | bindUserTap() {
68 |
69 | if (wx.getStorageSync('token')) {
70 | //个人信息页面
71 | } else {
72 | //跳转到登录页面
73 | wx.navigateTo({
74 | url: '/pages/auth/login/login',
75 | });
76 | }
77 |
78 |
79 | },
80 |
81 | /**
82 | * 生命周期函数--监听页面初次渲染完成
83 | */
84 | onReady: function () {
85 |
86 | },
87 |
88 | /**
89 | * 生命周期函数--监听页面显示
90 | */
91 | onShow: function () {
92 | this.setUserInfo();
93 | this.getOrderTotal();
94 | },
95 |
96 | /**
97 | * 生命周期函数--监听页面隐藏
98 | */
99 | onHide: function () {
100 |
101 | },
102 |
103 | /**
104 | * 生命周期函数--监听页面卸载
105 | */
106 | onUnload: function () {
107 |
108 | },
109 |
110 | /**
111 | * 页面相关事件处理函数--监听用户下拉动作
112 | */
113 | onPullDownRefresh: function () {
114 |
115 | },
116 |
117 | /**
118 | * 页面上拉触底事件的处理函数
119 | */
120 | onReachBottom: function () {
121 |
122 | },
123 |
124 | /**
125 | * 用户点击右上角分享
126 | */
127 | onShareAppMessage: function () {
128 |
129 | }
130 | })
--------------------------------------------------------------------------------
/pages/goods/list/list.wxss:
--------------------------------------------------------------------------------
1 | /* list.wxss */
2 | page, .container{
3 | background: #fff;
4 | min-height: 100%;
5 | }
6 | .sort{
7 | position: fixed;
8 | background: #fff;
9 | width: 100%;
10 | height: 78rpx;
11 | }
12 |
13 | .sort-box{
14 | background: #fff;
15 | width: 100%;
16 | height: 78rpx;
17 | overflow: hidden;
18 | padding: 0 30rpx;
19 | display: flex;
20 | border-bottom: 1px solid #d9d9d9;
21 | }
22 |
23 | .sort-box .item{
24 | height: 78rpx;
25 | line-height: 78rpx;
26 | text-align: center;
27 | flex:1;
28 | color: #333;
29 | font-size: 30rpx;
30 | }
31 |
32 | .sort-box .item .txt{
33 | display: block;
34 | width: 100%;
35 | height: 100%;
36 | color: #333;
37 | }
38 |
39 | .sort-box .item.active .txt{
40 | color: #b4282d;
41 | }
42 |
43 | .sort-box .item.by-price{
44 | background: url(//yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/no-3127092a69.png) 155rpx center no-repeat;
45 | background-size: 15rpx 21rpx;
46 | }
47 |
48 | .sort-box .item.by-price.active.asc{
49 | background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/up-636b92c0a5.png) 155rpx center no-repeat;
50 | background-size: 15rpx 21rpx;
51 | }
52 |
53 | .sort-box .item.by-price.active.desc{
54 | background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/down-95e035f3e5.png) 155rpx center no-repeat;
55 | background-size: 15rpx 21rpx;
56 | }
57 |
58 | .goods-section{
59 | padding-top: 88rpx;
60 | background: #fff;
61 | height: auto;
62 | overflow: hidden;
63 | }
64 |
65 | .goods-section .b{
66 | padding: 10rpx;
67 |
68 | }
69 |
70 | .goods-section .item{
71 | float: left;
72 | width: 345rpx;
73 | margin: 0 10rpx 40rpx 10rpx;
74 | }
75 |
76 | .goods-section .thumb{
77 | width: 345rpx;
78 | height: 345rpx;
79 | }
80 |
81 | .goods-section .name{
82 | margin-top: 10rpx;
83 | width: 345rpx;
84 | height: 26px;
85 | line-height: 26px;
86 | overflow: hidden;
87 | text-overflow: ellipsis;
88 | white-space: nowrap;
89 | font-size: 14px;
90 | color: #333;
91 | text-align: center;
92 | }
93 |
94 | .goods-section .price{
95 | width: 345rpx;
96 | height: 20px;
97 | line-height: 20px;
98 | text-align: center;
99 | font-size: 14px;
100 | color: #d81e06;
101 | }
102 |
103 | .list-empty{
104 | margin-top: 40%;
105 | }
--------------------------------------------------------------------------------
/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | /**index.wxss**/
2 | .banner{
3 | height: 378rpx;
4 | width: 100%;
5 | }
6 |
7 | .banner .slide-image{
8 | height: 378rpx;
9 | width: 750rpx;
10 | }
11 |
12 | .menu{
13 | width: 100%;
14 | height: 180rpx;
15 | background: #fff;
16 | display: flex;
17 | justify-content: space-around;
18 | align-items: center;
19 | flex-direction: row;
20 | }
21 |
22 | .menu .item{
23 | height: 100%;
24 | display: flex;
25 | justify-content: center;
26 | align-items: center;
27 | flex-direction: column;
28 | }
29 |
30 | .menu .icon{
31 | height: 88rpx;
32 | width: 88rpx;
33 | }
34 |
35 | .menu .name{
36 | line-height: 24px;
37 | font-size: 14px;
38 | }
39 |
40 | .notice{
41 | /* border-top: 1rpx solid #ececec; */
42 | height: 80rpx;
43 | width: 100%;
44 | background: #fff;
45 | display: flex;
46 | flex-direction: row;
47 | align-items: center;
48 | padding: 0 20rpx;
49 | margin-bottom: 20rpx;
50 | }
51 |
52 | .notice .icon{
53 | height: 44rpx;
54 | width: 44rpx;
55 | }
56 |
57 | .notice-list {
58 | width: 80vw;
59 | margin-left: 20rpx;
60 | border-left: 1px solid #f4f4f4;
61 | height: 30rpx;
62 | flex: 1;
63 | font-size: 12px;
64 | padding-left: 20rpx;
65 | color: #333;
66 | }
67 |
68 | .notice-list .swiper_item {
69 | font-size: 14px;
70 | overflow: hidden;
71 | text-overflow: ellipsis;
72 | white-space: nowrap;
73 | }
74 |
75 | .goods-section{
76 | width: 100%;
77 | height: auto;
78 | overflow: hidden;
79 | background: #fff;
80 | margin-bottom: 20rpx;
81 | }
82 |
83 | .goods-section .h{
84 | height: 120rpx;
85 | line-height: 120rpx;
86 | color: #333;
87 | font-size: 14px;
88 | text-align: center;
89 | }
90 |
91 | .goods-section .b{
92 | padding: 10rpx;
93 | }
94 |
95 | .goods-section .item{
96 | float: left;
97 | width: 345rpx;
98 | margin: 0 10rpx 40rpx 10rpx;
99 | }
100 |
101 | .goods-section .thumb{
102 | width: 345rpx;
103 | height: 345rpx;
104 | }
105 |
106 | .goods-section .name{
107 | margin-top: 10rpx;
108 | width: 345rpx;
109 | height: 26px;
110 | line-height: 26px;
111 | overflow: hidden;
112 | text-overflow: ellipsis;
113 | white-space: nowrap;
114 | font-size: 14px;
115 | color: #333;
116 | text-align: center;
117 | }
118 |
119 | .goods-section .price{
120 | width: 345rpx;
121 | height: 20px;
122 | line-height: 20px;
123 | text-align: center;
124 | font-size: 14px;
125 | color: #d81e06;
126 | }
--------------------------------------------------------------------------------
/pages/member/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {{user.username || 'Hi 你好'}}
6 |
7 |
8 |
9 | 我的订单
10 |
11 |
12 |
13 |
14 |
15 | 待付款
16 | {{orderTotal.paid}}
17 |
18 |
19 |
20 | 待发货
21 | {{orderTotal.delivering}}
22 |
23 |
24 |
25 | 待收货
26 | {{orderTotal.deliveried}}
27 |
28 |
29 |
30 | 待评论
31 | {{orderTotal.finished}}
32 |
33 |
34 |
35 |
57 | 退出登录
58 |
--------------------------------------------------------------------------------
/pages/member/index/index.wxss:
--------------------------------------------------------------------------------
1 | /* index.wxss */
2 | .container{
3 | height: 100%;
4 | overflow: hidden;
5 | }
6 | .user-box{
7 | background: #333;
8 | height: 400rpx;
9 | display: flex;
10 | flex-direction: column;
11 | align-items: center;
12 | justify-content: center;
13 | }
14 |
15 | .user-box .avatar{
16 | width: 140rpx;
17 | height: 140rpx;
18 | border-radius: 50%;
19 | }
20 |
21 | .user-box .username{
22 | margin-top: 30rpx;
23 | font-size: 14px;
24 | color: #fff;
25 | }
26 |
27 | .order{
28 | height: auto;
29 | overflow: hidden;
30 | background: #fff;
31 | }
32 |
33 | .order .h{
34 | height: 108rpx;
35 | padding-left: 30rpx;
36 | padding-right: 20rpx;
37 | border-bottom: 1px solid #e6e6e6;
38 | display: flex;
39 | align-items: center;
40 | }
41 |
42 | .order .h .label{
43 | flex: 1;
44 | }
45 |
46 | .order .h .icon-go{
47 | width: 44rpx;
48 | height: 44rpx;
49 | }
50 |
51 | .order .b{
52 | height: 168rpx;
53 | display: flex;
54 | }
55 |
56 | .order .b .item{
57 | width: 25%;
58 | height: 100%;
59 | position: relative;
60 | display: flex;
61 | flex-direction: column;
62 | justify-content: center;
63 | align-items: center;
64 | }
65 |
66 | .order .b .icon{
67 | width: 72rpx;
68 | height: 72rpx;
69 | }
70 |
71 | .order .b .label{
72 | font-size: 12px;
73 | color: #666;
74 | }
75 |
76 | .order .b .count{
77 | position: absolute;
78 | top: 20rpx;
79 | display: block;
80 | right: 40rpx;
81 | font-size: 12px;
82 | min-width: 16px;
83 | height: 16px;
84 | text-align: center;
85 | line-height: 14px;
86 | border-radius: 8px;
87 | border: 1px solid #d81e06;
88 | color: #d81e06;
89 | }
90 |
91 | .section-menu{
92 | background: #fff;
93 | height: auto;
94 | overflow: hidden;
95 | margin-top: 20rpx;
96 | margin-bottom: 20rpx;
97 | }
98 |
99 | .section-menu .item{
100 | height: 108rpx;
101 | width: 100%;
102 | display: flex;
103 | align-items: center;
104 | border-bottom: 1px solid #e6e6e6;
105 | padding: 0 20rpx;
106 | }
107 |
108 | .section-menu .item:last-child{
109 | border-bottom: 1px solid #fff;
110 | }
111 |
112 | .section-menu .item .icon{
113 | width: 44rpx;
114 | height: 44rpx;
115 | }
116 |
117 | .section-menu .item .label{
118 | margin-left: 10rpx;
119 | flex: 1;
120 | font-size: 12px;
121 | }
122 |
123 | .section-menu .item .icon-go{
124 | width: 44rpx;
125 | height: 44rpx;
126 | }
127 |
128 | .logout{
129 | margin-bottom: 20rpx;
130 | width: 100%;
131 | height: 108rpx;
132 | background: #fff;
133 | text-align: center;
134 | line-height: 108rpx;
135 | }
--------------------------------------------------------------------------------
/pages/goods/list/list.js:
--------------------------------------------------------------------------------
1 | // list.js
2 | const util = require('../../../utils/util.js');
3 |
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | requestLoading: true,
11 | category: 0,
12 | keyword: '',
13 | products: [],
14 | paged: {
15 | page: 1,
16 | size: 10
17 | },
18 | sort_key: 0,
19 | sort_value: 0,
20 | },
21 |
22 | /**
23 | * 排序事件
24 | */
25 | bindSorderTap(event) {
26 | let sort_key = event.currentTarget.id
27 | this.setData({
28 | 'paged.page': 1,
29 | sort_key: sort_key
30 | });
31 |
32 | if (sort_key == 1) {
33 | this.setData({
34 | sort_value: this.data.sort_value == 1 ? 2 : 1
35 | })
36 | }
37 |
38 | this.getPorducts();
39 | },
40 |
41 | getPorducts(loadMore = false) {
42 | wx.showLoading({
43 | title: '加载中...',
44 | })
45 | util.request(util.apiUrl + 'ecapi.product.list', 'POST', {
46 | category: this.data.category,
47 | page: this.data.paged.page,
48 | keyword: this.data.keyword,
49 | per_page: this.data.paged.size,
50 | sort_key: this.data.sort_key,
51 | sort_value: this.data.sort_value
52 | }).then((res) => {
53 |
54 | let products = [];
55 | if (loadMore == true) {
56 | products = this.data.products;
57 | } else {
58 | //重置使用页面回到顶部
59 | this.setData({
60 | products: [],
61 | })
62 | products = [];
63 | }
64 |
65 | let newPorducts = products.concat(res.products);
66 | this.setData({
67 | products: newPorducts,
68 | paged: res.paged,
69 | requestLoading: false
70 | })
71 | wx.hideLoading();
72 | });
73 | },
74 |
75 | /**
76 | * 生命周期函数--监听页面加载
77 | */
78 | onLoad: function (options) {
79 | this.setData({
80 | category: options.category || '',
81 | keyword: options.keyword || ''
82 | })
83 | this.getPorducts();
84 | },
85 |
86 | /**
87 | * 生命周期函数--监听页面初次渲染完成
88 | */
89 | onReady: function () {
90 |
91 | },
92 |
93 | /**
94 | * 生命周期函数--监听页面显示
95 | */
96 | onShow: function () {
97 |
98 | },
99 |
100 | /**
101 | * 生命周期函数--监听页面隐藏
102 | */
103 | onHide: function () {
104 |
105 | },
106 |
107 | /**
108 | * 生命周期函数--监听页面卸载
109 | */
110 | onUnload: function () {
111 |
112 | },
113 |
114 | /**
115 | * 页面相关事件处理函数--监听用户下拉动作
116 | */
117 | onPullDownRefresh: function () {
118 |
119 | },
120 |
121 | /**
122 | * 页面上拉触底事件的处理函数
123 | */
124 | onReachBottom: function () {
125 |
126 | if (this.data.paged.more === 1) {
127 | this.setData({
128 | 'paged.page': parseInt(this.data.paged.page) + 1
129 | })
130 | this.getPorducts(true);
131 | }
132 |
133 |
134 | },
135 |
136 | /**
137 | * 用户点击右上角分享
138 | */
139 | onShareAppMessage: function () {
140 |
141 | }
142 | })
--------------------------------------------------------------------------------
/pages/goods/detail/detail.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | {{goods.name}}
10 | ¥{{goods.current_price}}
11 |
12 |
13 |
14 | 请选择规格数量
15 |
16 |
17 |
18 |
19 | {{item.name}}
20 |
21 | {{vitem.attr_name}}
22 |
23 |
24 |
25 | 购买数量
26 |
27 | -
28 |
29 | +
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | 商品详情
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | 大家都在看
49 |
50 |
51 |
52 |
53 |
54 | {{item.name}}
55 | ¥{{item.retail_price}}
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | {{cartGoodsCount}}
68 |
69 |
70 |
71 | 立即购买
72 | 加入购物车
73 |
--------------------------------------------------------------------------------
/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | {{item.title}}
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | 精品推荐
53 |
54 |
55 |
56 | {{item.name}}
57 | ¥{{item.current_price}}
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | 新品上市
66 |
67 |
68 |
69 | {{item.name}}
70 | ¥{{item.current_price}}
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | 销量排行
79 |
80 |
81 |
82 | {{item.name}}
83 | ¥{{item.current_price}}
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/libs/wxParse/wxParse.wxss:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * author: Di (微信小程序开发工程师)
4 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
5 | * 垂直微信小程序开发交流社区
6 | *
7 | * github地址: https://github.com/icindy/wxParse
8 | *
9 | * for: 微信小程序富文本解析
10 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
11 | */
12 |
13 | .wxParse{
14 | margin: 0 5px;
15 | font-family: Helvetica,sans-serif;
16 | font-size: 28rpx;
17 | color: #666;
18 | line-height: 1.8;
19 | }
20 | view{
21 | word-break:break-all; overflow:auto;
22 | }
23 | .wxParse-inline{
24 | display: inline;
25 | margin: 0;
26 | padding: 0;
27 | }
28 | /*//标题 */
29 | .wxParse-div{margin: 0;padding: 0;}
30 | .wxParse-h1{ font-size:2em; margin: .67em 0 }
31 | .wxParse-h2{ font-size:1.5em; margin: .75em 0 }
32 | .wxParse-h3{ font-size:1.17em; margin: .83em 0 }
33 | .wxParse-h4{ margin: 1.12em 0}
34 | .wxParse-h5 { font-size:.83em; margin: 1.5em 0 }
35 | .wxParse-h6{ font-size:.75em; margin: 1.67em 0 }
36 |
37 | .wxParse-h1 {
38 | font-size: 18px;
39 | font-weight: 400;
40 | margin-bottom: .9em;
41 | }
42 | .wxParse-h2 {
43 | font-size: 16px;
44 | font-weight: 400;
45 | margin-bottom: .34em;
46 | }
47 | .wxParse-h3 {
48 | font-weight: 400;
49 | font-size: 15px;
50 | margin-bottom: .34em;
51 | }
52 | .wxParse-h4 {
53 | font-weight: 400;
54 | font-size: 14px;
55 | margin-bottom: .24em;
56 | }
57 | .wxParse-h5 {
58 | font-weight: 400;
59 | font-size: 13px;
60 | margin-bottom: .14em;
61 | }
62 | .wxParse-h6 {
63 | font-weight: 400;
64 | font-size: 12px;
65 | margin-bottom: .04em;
66 | }
67 |
68 | .wxParse-h1, .wxParse-h2, .wxParse-h3, .wxParse-h4, .wxParse-h5, .wxParse-h6, .wxParse-b, .wxParse-strong { font-weight: bolder }
69 |
70 | .wxParse-i,.wxParse-cite,.wxParse-em,.wxParse-var,.wxParse-address{font-style:italic}
71 | .wxParse-pre,.wxParse-tt,.wxParse-code,.wxParse-kbd,.wxParse-samp{font-family:monospace}
72 | .wxParse-pre{white-space:pre}
73 | .wxParse-big{font-size:1.17em}
74 | .wxParse-small,.wxParse-sub,.wxParse-sup{font-size:.83em}
75 | .wxParse-sub{vertical-align:sub}
76 | .wxParse-sup{vertical-align:super}
77 | .wxParse-s,.wxParse-strike,.wxParse-del{text-decoration:line-through}
78 | /*wxparse-自定义个性化的css样式*/
79 | /*增加video的css样式*/
80 | .wxParse-strong,.wxParse-s{display: inline}
81 | .wxParse-a{
82 | color: deepskyblue;
83 | word-break:break-all;
84 | overflow:auto;
85 | }
86 |
87 | .wxParse-video{
88 | text-align: center;
89 | margin: 10px 0;
90 | }
91 |
92 | .wxParse-video-video{
93 | width:100%;
94 | }
95 |
96 | .wxParse-img{
97 | /*background-color: #efefef;*/
98 | overflow: hidden;
99 | }
100 |
101 | .wxParse-blockquote {
102 | margin: 0;
103 | padding:10px 0 10px 5px;
104 | font-family:Courier, Calibri,"宋体";
105 | background:#f5f5f5;
106 | border-left: 3px solid #dbdbdb;
107 | }
108 |
109 | .wxParse-code,.wxParse-wxxxcode-style{
110 | display: inline;
111 | background:#f5f5f5;
112 | }
113 | .wxParse-ul{
114 | margin: 20rpx 10rpx;
115 | }
116 |
117 | .wxParse-li,.wxParse-li-inner{
118 | display: flex;
119 | align-items: baseline;
120 | margin: 10rpx 0;
121 | }
122 | .wxParse-li-text{
123 |
124 | align-items: center;
125 | line-height: 20px;
126 | }
127 |
128 | .wxParse-li-circle{
129 | display: inline-flex;
130 | width: 5px;
131 | height: 5px;
132 | background-color: #333;
133 | margin-right: 5px;
134 | }
135 |
136 | .wxParse-li-square{
137 | display: inline-flex;
138 | width: 10rpx;
139 | height: 10rpx;
140 | background-color: #333;
141 | margin-right: 5px;
142 | }
143 | .wxParse-li-ring{
144 | display: inline-flex;
145 | width: 10rpx;
146 | height: 10rpx;
147 | border: 2rpx solid #333;
148 | border-radius: 50%;
149 | background-color: #fff;
150 | margin-right: 5px;
151 | }
152 |
153 | /*.wxParse-table{
154 | width: 100%;
155 | height: 400px;
156 | }
157 | .wxParse-thead,.wxParse-tfoot,.wxParse-tr{
158 | display: flex;
159 | flex-direction: row;
160 | }
161 | .wxParse-th,.wxParse-td{
162 | display: flex;
163 | width: 580px;
164 | overflow: auto;
165 | }*/
166 |
167 | .wxParse-u {
168 | text-decoration: underline;
169 | }
170 | .wxParse-hide{
171 | display: none;
172 | }
173 | .WxEmojiView{
174 | align-items: center;
175 | }
176 | .wxEmoji{
177 | width: 16px;
178 | height:16px;
179 | }
180 | .wxParse-tr{
181 | display: flex;
182 | border-right:1px solid #e0e0e0;
183 | border-bottom:1px solid #e0e0e0;
184 | border-top:1px solid #e0e0e0;
185 | }
186 | .wxParse-th,
187 | .wxParse-td{
188 | flex:1;
189 | padding:5px;
190 | font-size:28rpx;
191 | border-left:1px solid #e0e0e0;
192 | word-break: break-all;
193 | }
194 | .wxParse-td:last{
195 | border-top:1px solid #e0e0e0;
196 | }
197 | .wxParse-th{
198 | background:#f0f0f0;
199 | border-top:1px solid #e0e0e0;
200 | }
201 | .wxParse-del{
202 | display: inline;
203 | }
204 | .wxParse-figure {
205 | overflow: hidden;
206 | }
207 |
--------------------------------------------------------------------------------
/libs/wxParse/wxParse.js:
--------------------------------------------------------------------------------
1 | /**
2 | * author: Di (微信小程序开发工程师)
3 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
4 | * 垂直微信小程序开发交流社区
5 | *
6 | * github地址: https://github.com/icindy/wxParse
7 | *
8 | * for: 微信小程序富文本解析
9 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
10 | */
11 |
12 | /**
13 | * utils函数引入
14 | **/
15 | import showdown from './showdown.js';
16 | import HtmlToJson from './html2json.js';
17 | /**
18 | * 配置及公有属性
19 | **/
20 | var realWindowWidth = 0;
21 | var realWindowHeight = 0;
22 | wx.getSystemInfo({
23 | success: function (res) {
24 | realWindowWidth = res.windowWidth
25 | realWindowHeight = res.windowHeight
26 | }
27 | })
28 | /**
29 | * 主函数入口区
30 | **/
31 | function wxParse(bindName = 'wxParseData', type='html', data='
数据不能为空
', target,imagePadding) {
32 | var that = target;
33 | var transData = {};//存放转化后的数据
34 | if (type == 'html') {
35 | transData = HtmlToJson.html2json(data, bindName);
36 | console.log(JSON.stringify(transData, ' ', ' '));
37 | } else if (type == 'md' || type == 'markdown') {
38 | var converter = new showdown.Converter();
39 | var html = converter.makeHtml(data);
40 | transData = HtmlToJson.html2json(html, bindName);
41 | console.log(JSON.stringify(transData, ' ', ' '));
42 | }
43 | transData.view = {};
44 | transData.view.imagePadding = 0;
45 | if(typeof(imagePadding) != 'undefined'){
46 | transData.view.imagePadding = imagePadding
47 | }
48 | var bindData = {};
49 | bindData[bindName] = transData;
50 | that.setData(bindData)
51 | that.wxParseImgLoad = wxParseImgLoad;
52 | that.wxParseImgTap = wxParseImgTap;
53 | }
54 | // 图片点击事件
55 | function wxParseImgTap(e) {
56 | var that = this;
57 | var nowImgUrl = e.target.dataset.src;
58 | var tagFrom = e.target.dataset.from;
59 | if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
60 | wx.previewImage({
61 | current: nowImgUrl, // 当前显示图片的http链接
62 | urls: that.data[tagFrom].imageUrls // 需要预览的图片http链接列表
63 | })
64 | }
65 | }
66 |
67 | /**
68 | * 图片视觉宽高计算函数区
69 | **/
70 | function wxParseImgLoad(e) {
71 | var that = this;
72 | var tagFrom = e.target.dataset.from;
73 | var idx = e.target.dataset.idx;
74 | if (typeof (tagFrom) != 'undefined' && tagFrom.length > 0) {
75 | calMoreImageInfo(e, idx, that, tagFrom)
76 | }
77 | }
78 | // 假循环获取计算图片视觉最佳宽高
79 | function calMoreImageInfo(e, idx, that, bindName) {
80 | var temData = that.data[bindName];
81 | if (!temData || temData.images.length == 0) {
82 | return;
83 | }
84 | var temImages = temData.images;
85 | //因为无法获取view宽度 需要自定义padding进行计算,稍后处理
86 | var recal = wxAutoImageCal(e.detail.width, e.detail.height,that,bindName);
87 | // temImages[idx].width = recal.imageWidth;
88 | // temImages[idx].height = recal.imageheight;
89 | // temData.images = temImages;
90 | // var bindData = {};
91 | // bindData[bindName] = temData;
92 | // that.setData(bindData);
93 | var index = temImages[idx].index
94 | var key = `${bindName}`
95 | for (var i of index.split('.')) key+=`.nodes[${i}]`
96 | var keyW = key + '.width'
97 | var keyH = key + '.height'
98 | that.setData({
99 | [keyW]: recal.imageWidth,
100 | [keyH]: recal.imageheight,
101 | })
102 | }
103 |
104 | // 计算视觉优先的图片宽高
105 | function wxAutoImageCal(originalWidth, originalHeight,that,bindName) {
106 | //获取图片的原始长宽
107 | var windowWidth = 0, windowHeight = 0;
108 | var autoWidth = 0, autoHeight = 0;
109 | var results = {};
110 | var padding = that.data[bindName].view.imagePadding;
111 | windowWidth = realWindowWidth-2*padding;
112 | windowHeight = realWindowHeight;
113 | //判断按照那种方式进行缩放
114 | // console.log("windowWidth" + windowWidth);
115 | if (originalWidth > windowWidth) {//在图片width大于手机屏幕width时候
116 | autoWidth = windowWidth;
117 | // console.log("autoWidth" + autoWidth);
118 | autoHeight = (autoWidth * originalHeight) / originalWidth;
119 | // console.log("autoHeight" + autoHeight);
120 | results.imageWidth = autoWidth;
121 | results.imageheight = autoHeight;
122 | } else {//否则展示原来的数据
123 | results.imageWidth = originalWidth;
124 | results.imageheight = originalHeight;
125 | }
126 | return results;
127 | }
128 |
129 | function wxParseTemArray(temArrayName,bindNameReg,total,that){
130 | var array = [];
131 | var temData = that.data;
132 | var obj = null;
133 | for(var i = 0; i < total; i++){
134 | var simArr = temData[bindNameReg+i].nodes;
135 | array.push(simArr);
136 | }
137 |
138 | temArrayName = temArrayName || 'wxParseTemArray';
139 | obj = JSON.parse('{"'+ temArrayName +'":""}');
140 | obj[temArrayName] = array;
141 | that.setData(obj);
142 | }
143 |
144 | /**
145 | * 配置emojis
146 | *
147 | */
148 |
149 | function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
150 | HtmlToJson.emojisInit(reg,baseSrc,emojis);
151 | }
152 |
153 | module.exports = {
154 | wxParse: wxParse,
155 | wxParseTemArray:wxParseTemArray,
156 | emojisInit:emojisInit
157 | }
158 |
159 |
160 |
--------------------------------------------------------------------------------
/libs/wxParse/htmlparser.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * htmlParser改造自: https://github.com/blowsie/Pure-JavaScript-HTML5-Parser
4 | *
5 | * author: Di (微信小程序开发工程师)
6 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
7 | * 垂直微信小程序开发交流社区
8 | *
9 | * github地址: https://github.com/icindy/wxParse
10 | *
11 | * for: 微信小程序富文本解析
12 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
13 | */
14 | // Regular Expressions for parsing tags and attributes
15 | var startTag = /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
16 | endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
17 | attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
18 |
19 | // Empty Elements - HTML 5
20 | var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
21 |
22 | // Block Elements - HTML 5
23 | 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");
24 |
25 | // Inline Elements - HTML 5
26 | 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");
27 |
28 | // Elements that you can, intentionally, leave open
29 | // (and which close themselves)
30 | var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
31 |
32 | // Attributes that have their values filled in disabled="disabled"
33 | var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
34 |
35 | // Special Elements (can contain anything)
36 | var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
37 |
38 | function HTMLParser(html, handler) {
39 | var index, chars, match, stack = [], last = html;
40 | stack.last = function () {
41 | return this[this.length - 1];
42 | };
43 |
44 | while (html) {
45 | chars = true;
46 |
47 | // Make sure we're not in a script or style element
48 | if (!stack.last() || !special[stack.last()]) {
49 |
50 | // Comment
51 | if (html.indexOf("");
53 |
54 | if (index >= 0) {
55 | if (handler.comment)
56 | handler.comment(html.substring(4, index));
57 | html = html.substring(index + 3);
58 | chars = false;
59 | }
60 |
61 | // end tag
62 | } else if (html.indexOf("") == 0) {
63 | match = html.match(endTag);
64 |
65 | if (match) {
66 | html = html.substring(match[0].length);
67 | match[0].replace(endTag, parseEndTag);
68 | chars = false;
69 | }
70 |
71 | // start tag
72 | } else if (html.indexOf("<") == 0) {
73 | match = html.match(startTag);
74 |
75 | if (match) {
76 | html = html.substring(match[0].length);
77 | match[0].replace(startTag, parseStartTag);
78 | chars = false;
79 | }
80 | }
81 |
82 | if (chars) {
83 | index = html.indexOf("<");
84 | var text = ''
85 | while (index === 0) {
86 | text += "<";
87 | html = html.substring(1);
88 | index = html.indexOf("<");
89 | }
90 | text += index < 0 ? html : html.substring(0, index);
91 | html = index < 0 ? "" : html.substring(index);
92 |
93 | if (handler.chars)
94 | handler.chars(text);
95 | }
96 |
97 | } else {
98 |
99 | html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
100 | text = text.replace(/|/g, "$1$2");
101 | if (handler.chars)
102 | handler.chars(text);
103 |
104 | return "";
105 | });
106 |
107 |
108 | parseEndTag("", stack.last());
109 | }
110 |
111 | if (html == last)
112 | throw "Parse Error: " + html;
113 | last = html;
114 | }
115 |
116 | // Clean up any remaining tags
117 | parseEndTag();
118 |
119 | function parseStartTag(tag, tagName, rest, unary) {
120 | tagName = tagName.toLowerCase();
121 |
122 | if (block[tagName]) {
123 | while (stack.last() && inline[stack.last()]) {
124 | parseEndTag("", stack.last());
125 | }
126 | }
127 |
128 | if (closeSelf[tagName] && stack.last() == tagName) {
129 | parseEndTag("", tagName);
130 | }
131 |
132 | unary = empty[tagName] || !!unary;
133 |
134 | if (!unary)
135 | stack.push(tagName);
136 |
137 | if (handler.start) {
138 | var attrs = [];
139 |
140 | rest.replace(attr, function (match, name) {
141 | var value = arguments[2] ? arguments[2] :
142 | arguments[3] ? arguments[3] :
143 | arguments[4] ? arguments[4] :
144 | fillAttrs[name] ? name : "";
145 |
146 | attrs.push({
147 | name: name,
148 | value: value,
149 | escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
150 | });
151 | });
152 |
153 | if (handler.start) {
154 | handler.start(tagName, attrs, unary);
155 | }
156 |
157 | }
158 | }
159 |
160 | function parseEndTag(tag, tagName) {
161 | // If no tag name is provided, clean shop
162 | if (!tagName)
163 | var pos = 0;
164 |
165 | // Find the closest opened tag of the same type
166 | else {
167 | tagName = tagName.toLowerCase();
168 | for (var pos = stack.length - 1; pos >= 0; pos--)
169 | if (stack[pos] == tagName)
170 | break;
171 | }
172 | if (pos >= 0) {
173 | // Close all the open elements, up the stack
174 | for (var i = stack.length - 1; i >= pos; i--)
175 | if (handler.end)
176 | handler.end(stack[i]);
177 |
178 | // Remove the open elements from the stack
179 | stack.length = pos;
180 | }
181 | }
182 | };
183 |
184 |
185 | function makeMap(str) {
186 | var obj = {}, items = str.split(",");
187 | for (var i = 0; i < items.length; i++)
188 | obj[items[i]] = true;
189 | return obj;
190 | }
191 |
192 | module.exports = HTMLParser;
193 |
--------------------------------------------------------------------------------
/pages/shopping/cart/cart.wxss:
--------------------------------------------------------------------------------
1 | /* cart.wxss */
2 | page, .container{
3 | height: 100%;
4 | }
5 |
6 |
7 | .cart-view{
8 | width: 100%;
9 | height: auto;
10 | overflow: hidden;
11 |
12 | }
13 |
14 | .cart-view .list{
15 | height: auto;
16 | width: 100%;
17 | overflow: hidden;
18 | margin-bottom: 120rpx;
19 | }
20 |
21 | .cart-view .group-item{
22 | height: auto;
23 | width: 100%;
24 | background: #fff;
25 | margin-bottom: 18rpx;
26 | }
27 |
28 | .cart-view .item{
29 | height: 200rpx;
30 | width: 100%;
31 | overflow: hidden;
32 | }
33 | .cart-view .item .checkbox{
34 | float: left;
35 | height: 40rpx;
36 | width: 40rpx;
37 | margin: 80rpx 10rpx 65rpx 25rpx;
38 | background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-0e09baa37e.png) no-repeat;
39 | background-size: 40rpx;
40 | }
41 |
42 | .cart-view .item .checkbox.checked{
43 | background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-checked-822e54472a.png) no-repeat;
44 | background-size: 40rpx;
45 | }
46 |
47 | .cart-view .item .cart-goods{
48 | float: left;
49 | height: 200rpx;
50 | width: 672rpx;
51 | border-bottom: 1px solid #f4f4f4;
52 | }
53 |
54 | .cart-view .item .img{
55 | float: left;
56 | height:160rpx;
57 | width: 160rpx;
58 | background: #f4f4f4;
59 | margin: 19.5rpx 18rpx 19.5rpx 0;
60 | }
61 |
62 | .cart-view .item .info{
63 | float: left;
64 | height: 160rpx;
65 | width: 466rpx;
66 | margin: 19.5rpx 26rpx 19.5rpx 0;
67 | }
68 |
69 | .cart-view .item .t{
70 | margin: 8rpx 0;
71 | height: 36rpx;
72 | line-height: 36rpx;
73 | font-size: 32rpx;
74 | color: #333;
75 | overflow: hidden;
76 | }
77 |
78 |
79 | .cart-view .item .name{
80 | height: 30rpx;
81 | max-width: 310rpx;
82 | line-height: 30rpx;
83 | font-size: 25rpx;
84 | display: block;
85 | color: #333;
86 | overflow: hidden;
87 | float: left;
88 | }
89 |
90 | .cart-view .item .del{
91 | height: 36rpx;
92 | width: 36rpx;
93 | display: block;
94 | float: right;
95 | }
96 |
97 | .cart-view .item .attr{
98 | margin-bottom: 20rpx;
99 | height: 24rpx;
100 | line-height: 24rpx;
101 | font-size: 22rpx;
102 | color: #666;
103 | overflow: hidden;
104 | }
105 |
106 | .cart-view .item .b{
107 | height: 52rpx;
108 | line-height: 52rpx;
109 | font-size: 25rpx;
110 | color: #333;
111 | overflow: hidden;
112 | }
113 |
114 | .cart-view .item .price{
115 | float: left;
116 | }
117 |
118 | .cart-view .item .open{
119 | height: 28rpx;
120 | width: 150rpx;
121 | display: block;
122 | float: right;
123 | background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/arrowDown-d48093db25.png) right center no-repeat;
124 | background-size: 25rpx;
125 | font-size: 25rpx;
126 | color: #333;
127 | }
128 |
129 | .cart-view .item .selnum{
130 | float: right;
131 | width: 235rpx;
132 | height: 52rpx;
133 | border: 1rpx solid #ccc;
134 | display: flex;
135 | }
136 |
137 | .selnum .cut{
138 | width: 70rpx;
139 | height: 100%;
140 | text-align: center;
141 | line-height: 50rpx;
142 | }
143 |
144 | .selnum .number{
145 | flex: 1;
146 | height: 100%;
147 | text-align: center;
148 | line-height: 68.75rpx;
149 | border-left: 1px solid #ccc;
150 | border-right: 1px solid #ccc;
151 | float: left;
152 | }
153 |
154 | .selnum .add{
155 | width: 80rpx;
156 | height: 100%;
157 | text-align: center;
158 | line-height: 50rpx;
159 | }
160 |
161 |
162 | .cart-view .group-item .header{
163 | width: 100%;
164 | height: 94rpx;
165 | line-height: 94rpx;
166 | padding: 0 26rpx;
167 | border-bottom: 1px solid #f4f4f4;
168 | }
169 |
170 | .cart-view .promotion .icon{
171 | display: inline-block;
172 | height: 24rpx;
173 | width: 15rpx;
174 | }
175 |
176 | .cart-view .promotion{
177 | margin-top: 25.5rpx;
178 | float: left;
179 | height: 43rpx;
180 | width: 480rpx;
181 | /*margin-right: 84rpx;*/
182 | line-height: 43rpx;
183 | font-size: 0;
184 | }
185 |
186 | .cart-view .promotion .tag{
187 | border: 1px solid #f48f18;
188 | height: 37rpx;
189 | line-height: 31rpx;
190 | padding: 0 9rpx;
191 | margin-right: 10rpx;
192 | color: #f48f18;
193 | font-size: 24.5rpx;
194 | }
195 |
196 | .cart-view .promotion .txt{
197 | height: 43rpx;
198 | line-height: 43rpx;
199 | padding-right: 10rpx;
200 | color: #333;
201 | font-size: 29rpx;
202 | overflow: hidden;
203 | }
204 |
205 | .cart-view .get{
206 | margin-top: 18rpx;
207 | float: right;
208 | height: 58rpx;
209 | padding-left: 14rpx;
210 | border-left: 1px solid #d9d9d9;
211 | line-height: 58rpx;
212 | font-size: 29rpx;
213 | color: #333;
214 | }
215 |
216 | .cart-bottom{
217 | position: fixed;
218 | bottom:0;
219 | left:0;
220 | height: 100rpx;
221 | width: 100%;
222 | background: #fff;
223 | display: flex;
224 | }
225 |
226 | .cart-bottom .checkbox{
227 | height: 34rpx;
228 |
229 | padding-left: 60rpx;
230 | line-height: 34rpx;
231 | margin: 33rpx 18rpx 33rpx 26rpx;
232 | background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-0e09baa37e.png) no-repeat;
233 | background-size: 34rpx;
234 | font-size: 29rpx;
235 | }
236 |
237 | .cart-bottom .checkbox.checked{
238 | background: url(http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/checkbox-checked-822e54472a.png) no-repeat;
239 | background-size: 34rpx;
240 | }
241 |
242 | .cart-bottom .total{
243 | height: 34rpx;
244 | flex: 1;
245 | margin: 33rpx 10rpx;
246 | font-size: 29rpx;
247 | }
248 |
249 |
250 | .cart-bottom .delete{
251 | height: 34rpx;
252 | width: auto;
253 | margin: 33rpx 18rpx;
254 | font-size: 29rpx;
255 | }
256 |
257 | .cart-bottom .checkout{
258 | height: 100rpx;
259 | width: 210rpx;
260 | text-align: center;
261 | line-height: 100rpx;
262 | font-size: 29rpx;
263 | background: #d81e06;
264 | color: #fff;
265 | }
--------------------------------------------------------------------------------
/pages/shopping/cart/cart.js:
--------------------------------------------------------------------------------
1 | // cart.js
2 | const util = require('../../../utils/util.js');
3 |
4 | Page({
5 | data: {
6 | requestLoading: true,
7 | cartGoods: [],
8 | cartTotal: {
9 | "checkedGoodsCount": 0,
10 | "checkedGoodsAmount": 0.00
11 | },
12 | checkedAllStatus: true,
13 | editCartList: []
14 | },
15 | onLoad: function (options) {
16 | // 页面初始化 options为页面跳转所带来的参数
17 | },
18 | onReady: function () {
19 | // 页面渲染完成
20 | },
21 | onShow: function () {
22 | // 页面显示
23 | this.getCartList();
24 | },
25 | onHide: function () {
26 | // 页面隐藏
27 |
28 | },
29 | onUnload: function () {
30 | // 页面关闭
31 |
32 | },
33 | onDeleteGoods(event) {
34 | let itemIndex = event.target.dataset.itemIndex;
35 | //ecapi.cart.delete
36 | let goods = this.data.cartGoods[itemIndex];
37 | console.log(goods)
38 |
39 | let that = this;
40 | wx.showModal({
41 | title: '提示',
42 | content: '是否要删除选择中商品?',
43 | success: function (res) {
44 | if (res.confirm) {
45 | util.request(util.apiUrl + 'ecapi.cart.delete', 'POST', {
46 | good: goods.id
47 | }).then((res) => {
48 | console.log(res)
49 | util.showToast('商品已删除', 'success');
50 | that.getCartList();
51 | })
52 | }
53 | }
54 | })
55 |
56 | },
57 | getCartList: function () {
58 | util.request(util.apiUrl + 'ecapi.cart.get', 'POST').then((res) => {
59 | if (res.error_code === 0) {
60 | let cartGoodsInfo = res.goods_groups[0];
61 | let goodsList = cartGoodsInfo.goods.map(item => {
62 | item.checked = true;
63 | return item;
64 | });
65 | this.setData({
66 | cartGoods: goodsList,
67 | cartTotal: {
68 | checkedGoodsCount: cartGoodsInfo.total_amount,
69 | checkedGoodsAmount: cartGoodsInfo.total_price,
70 | }
71 | });
72 | }
73 |
74 | this.setData({
75 | checkedAllStatus: this.isCheckedAll(),
76 | requestLoading: false
77 | });
78 |
79 |
80 | });
81 | },
82 | isCheckedAll: function () {
83 | //判断购物车商品已全选
84 | return this.data.cartGoods.every(function (element, index, array) {
85 | if (element.checked == true) {
86 | return true;
87 | } else {
88 | return false;
89 | }
90 | });
91 | },
92 | getCheckedGoodsCount: function () {
93 | let checkedGoodsCount = 0;
94 | this.data.cartGoods.forEach(function (v) {
95 | if (v.checked === true) {
96 | checkedGoodsCount += v.amount;
97 | }
98 | });
99 | console.log(checkedGoodsCount);
100 | return checkedGoodsCount;
101 | },
102 | getCheckedGoodsAmount: function () {
103 | let checkedGoodsCount = 0;
104 | this.data.cartGoods.forEach(function (v) {
105 | if (v.checked === true) {
106 | checkedGoodsCount += v.price * v.amount;
107 | }
108 | });
109 | console.log(checkedGoodsCount);
110 | return checkedGoodsCount;
111 | },
112 | checkedItem: function (event) {
113 | let itemIndex = event.target.dataset.itemIndex;
114 | let that = this;
115 |
116 | //编辑状态
117 | let tmpCartData = this.data.cartGoods.map(function (element, index, array) {
118 | if (index == itemIndex) {
119 | element.checked = !element.checked;
120 | }
121 | return element;
122 | });
123 |
124 | that.setData({
125 | cartGoods: tmpCartData,
126 | checkedAllStatus: that.isCheckedAll(),
127 | 'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount(),
128 | 'cartTotal.checkedGoodsAmount': that.getCheckedGoodsAmount()
129 | });
130 | },
131 | checkedAll: function () {
132 | let that = this;
133 |
134 | let isCheckedAll = that.isCheckedAll();
135 |
136 | let tmpCartData = this.data.cartGoods.map(function (element, index, array) {
137 | element.checked = !isCheckedAll;
138 | return element;
139 | });
140 |
141 | that.setData({
142 | cartGoods: tmpCartData,
143 | checkedAllStatus: !isCheckedAll,
144 | 'cartTotal.checkedGoodsCount': that.getCheckedGoodsCount(),
145 | 'cartTotal.checkedGoodsAmount': that.getCheckedGoodsAmount()
146 | });
147 |
148 | },
149 | updateNumber(good, amount) {
150 | let that = this;
151 | util.request(util.apiUrl + 'ecapi.cart.update', 'POST', {
152 | amount: amount,
153 | good: good
154 | }).then((res) => {
155 | if (res.error_code === 0) {
156 | that.getCartList();
157 | }
158 | });
159 | },
160 | updateCart: function (productId, goodsId, amount, id) {
161 | let that = this;
162 |
163 | util.request(api.CartUpdate, {
164 | productId: productId,
165 | goodsId: goodsId,
166 | amount: amount,
167 | id: id
168 | }, 'POST').then(function (res) {
169 | if (res.errno === 0) {
170 | console.log(res.data);
171 | that.setData({
172 | //cartGoods: res.data.cartList,
173 | //cartTotal: res.data.cartTotal
174 | });
175 | }
176 |
177 | that.setData({
178 | checkedAllStatus: that.isCheckedAll()
179 | });
180 | });
181 |
182 | },
183 | cutNumber: function (event) {
184 |
185 | let itemIndex = event.target.dataset.itemIndex;
186 | let cartItem = this.data.cartGoods[itemIndex];
187 | let amount = (cartItem.amount - 1 > 1) ? cartItem.amount - 1 : 1;
188 | cartItem.amount = amount;
189 | this.setData({
190 | cartGoods: this.data.cartGoods
191 | });
192 | this.updateNumber(cartItem.id, amount);
193 | },
194 | addNumber: function (event) {
195 | let itemIndex = event.target.dataset.itemIndex;
196 | let cartItem = this.data.cartGoods[itemIndex];
197 | let amount = cartItem.amount + 1;
198 | cartItem.amount = amount;
199 | this.setData({
200 | cartGoods: this.data.cartGoods
201 | });
202 | this.updateNumber(cartItem.id, amount);
203 | },
204 | checkoutOrder: function () {
205 | //获取已选择的商品
206 | let that = this;
207 |
208 | var checkedGoods = this.data.cartGoods.filter(function (element, index, array) {
209 | if (element.checked == true) {
210 | return true;
211 | } else {
212 | return false;
213 | }
214 | });
215 |
216 | if (checkedGoods.length <= 0) {
217 | return false;
218 | }
219 |
220 |
221 | wx.navigateTo({
222 | url: '../shopping/checkout/checkout'
223 | })
224 | },
225 | })
--------------------------------------------------------------------------------
/pages/goods/detail/detail.js:
--------------------------------------------------------------------------------
1 | var app = getApp();
2 | var util = require('../../../utils/util.js');
3 | var WxParse = require('../../../libs/wxParse/wxParse.js');
4 |
5 | Page({
6 | data: {
7 | id: 0,
8 | goods: {},
9 | gallery: [],
10 | specificationList: [],
11 | productList: [],
12 | relatedGoods: [],
13 | cartGoodsCount: 0,
14 | userHasCollect: 0,
15 | number: 1,
16 | },
17 | getProductInfo: function () {
18 | wx.showLoading({
19 | title: '加载中...',
20 | });
21 | let that = this;
22 | util.request(util.apiUrl + 'ecapi.product.get', 'POST', { product: that.data.id }).then(function (res) {
23 | if (res.error_code === 0) {
24 |
25 | let specificationList = [];
26 | if (res.product.properties) {
27 | specificationList = res.product.properties.map(v => {
28 | v.checked = false;
29 | return v;
30 | });
31 | }
32 |
33 | that.setData({
34 | goods: res.product,
35 | gallery: res.product.photos,
36 | specificationList: specificationList,
37 | productList: res.product.stock,
38 | userHasCollect: res.product.is_liked
39 | });
40 | WxParse.wxParse('goodsDetail', 'html', res.product.goods_desc, that);
41 | //that.getGoodsRelated();
42 | }
43 | wx.hideLoading();
44 | });
45 |
46 | },
47 | getGoodsRelated: function () {
48 | let that = this;
49 | util.request(api.GoodsRelated, { id: that.data.id }).then(function (res) {
50 | if (res.errno === 0) {
51 | that.setData({
52 | relatedGoods: res.data.goodsList,
53 | });
54 | }
55 | });
56 |
57 | },
58 | clickSkuValue: function (event) {
59 | let that = this;
60 | let specNameId = event.currentTarget.dataset.nameId;
61 | let specValueId = event.currentTarget.dataset.valueId;
62 |
63 | //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
64 | let _specificationList = this.data.specificationList;
65 | for (let i = 0; i < _specificationList.length; i++) {
66 | if (_specificationList[i].id == specNameId) {
67 | for (let j = 0; j < _specificationList[i].attrs.length; j++) {
68 | if (_specificationList[i].attrs[j].id == specValueId) {
69 | //如果已经选中,则反选
70 | if (_specificationList[i].attrs[j].checked) {
71 | _specificationList[i].attrs[j].checked = false;
72 | } else {
73 | _specificationList[i].attrs[j].checked = true;
74 | }
75 | } else {
76 | _specificationList[i].attrs[j].checked = false;
77 | }
78 | }
79 | }
80 | }
81 | this.setData({
82 | 'specificationList': _specificationList
83 | });
84 | },
85 |
86 | //获取选中的规格信息
87 | getCheckedSpecValue: function () {
88 | let checkedValues = [];
89 | let _specificationList = this.data.specificationList;
90 | for (let i = 0; i < _specificationList.length; i++) {
91 | let _checkedObj = {
92 | nameId: _specificationList[i].id,
93 | valueId: 0,
94 | valueText: ''
95 | };
96 | for (let j = 0; j < _specificationList[i].attrs.length; j++) {
97 | if (_specificationList[i].attrs[j].checked) {
98 | _checkedObj.valueId = _specificationList[i].attrs[j].id;
99 | _checkedObj.valueText = _specificationList[i].attrs[j].attr_name;
100 | }
101 | }
102 | checkedValues.push(_checkedObj);
103 | }
104 |
105 | return checkedValues;
106 |
107 | },
108 |
109 | //判断规格是否选择完整
110 | isCheckedAllSpec: function () {
111 | return !this.getCheckedSpecValue().some(function (v) {
112 | if (v.valueId == 0) {
113 | return true;
114 | }
115 | });
116 | },
117 | getCheckedSpecKey: function () {
118 | let checkedValue = this.getCheckedSpecValue().map(function (v) {
119 | return v.valueId;
120 | });
121 |
122 | return checkedValue.join('|');
123 | },
124 |
125 | getCheckedProductItem: function (key) {
126 | return this.data.productList.filter(function (v) {
127 | if (v.goods_attr == key) {
128 | return true;
129 | } else {
130 | return false;
131 | }
132 | });
133 | },
134 | onLoad: function (options) {
135 | // 页面初始化 options为页面跳转所带来的参数
136 | this.setData({
137 | id: parseInt(options.id)
138 | });
139 |
140 | this.getProductInfo();
141 | this.getCartCount();
142 | },
143 | getCartCount(){
144 | var that = this;
145 | util.request(util.apiUrl + 'ecapi.cart.get', 'POST').then(function (res) {
146 | that.setData({
147 | cartGoodsCount: res.goods_groups[0].total_amount || 0
148 | });
149 | });
150 | },
151 | onReady: function () {
152 | // 页面渲染完成
153 |
154 | },
155 | onShow: function () {
156 | // 页面显示
157 |
158 | },
159 | onHide: function () {
160 | // 页面隐藏
161 |
162 | },
163 | onUnload: function () {
164 | // 页面关闭
165 | },
166 | goodsCollect: function () {
167 | let that = this;
168 | let collectUrl = that.data.userHasCollect === false ? 'ecapi.product.like' : 'ecapi.product.unlike';
169 | util.request(util.apiUrl + collectUrl, 'POST', { product: this.data.id }, "POST")
170 | .then(function (res) {
171 | that.setData({
172 | userHasCollect: res.is_liked
173 | })
174 | });
175 | },
176 | addToCart: function () {
177 | var that = this;
178 |
179 | if (this.data.specificationList.length > 0 ) {
180 |
181 | //提示选择完整规格
182 | if (this.isCheckedAllSpec()) {
183 | util.showToast('请选择规格', 'error');
184 | return false;
185 | }
186 |
187 | //根据选中的规格,判断是否有对应的sku信息
188 | let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey());
189 | if (!checkedProduct || checkedProduct.length <= 0) {
190 | //找不到对应的product信息,提示没有库存
191 | util.showToast('规格不存在', 'error');
192 | return false;
193 | }
194 |
195 | //验证库存
196 | if (checkedProduct.stock_number < this.data.number) {
197 | //找不到对应的product信息,提示没有库存
198 | util.showToast('商品售完', 'error');
199 | return false;
200 | }
201 | let property = checkedProduct[0].goods_attr;
202 | property = '[' + property.replace("|", ",") + ']';
203 | //添加到购物车
204 | util.request(util.apiUrl + 'ecapi.cart.add', "POST", { amount: this.data.number, product: this.data.goods.id, property: property })
205 | .then(function (res) {
206 | util.showToast('加入购物车成功', 'success')
207 | this.getCartCount();
208 | }).catch(err => {
209 | util.showToast(err.error_desc, 'error')
210 | });
211 | } else {
212 | //验证库存
213 |
214 | if (this.data.goods.good_stock < this.data.number) {
215 | //找不到对应的product信息,提示没有库存
216 | util.showToast('商品售完', 'error');
217 | return false;
218 | }
219 |
220 | //添加到购物车
221 | util.request(util.apiUrl + 'ecapi.cart.add', "POST", { amount: this.data.number, product: this.data.goods.id, property: "[]" })
222 | .then(function (res) {
223 | util.showToast('加入购物车成功', 'success')
224 | this.getCartCount();
225 | }).catch(err => {
226 | util.showToast(err.error_desc, 'error')
227 | });
228 | }
229 |
230 | },
231 | cutNumber: function () {
232 | this.setData({
233 | number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
234 | });
235 | },
236 | addNumber: function () {
237 | this.setData({
238 | number: this.data.number + 1
239 | });
240 | }
241 | })
--------------------------------------------------------------------------------
/libs/wxParse/wxDiscode.js:
--------------------------------------------------------------------------------
1 | // HTML 支持的数学符号
2 | function strNumDiscode(str){
3 | str = str.replace(/∀/g, '∀');
4 | str = str.replace(/∂/g, '∂');
5 | str = str.replace(/&exists;/g, '∃');
6 | str = str.replace(/∅/g, '∅');
7 | str = str.replace(/∇/g, '∇');
8 | str = str.replace(/∈/g, '∈');
9 | str = str.replace(/∉/g, '∉');
10 | str = str.replace(/∋/g, '∋');
11 | str = str.replace(/∏/g, '∏');
12 | str = str.replace(/∑/g, '∑');
13 | str = str.replace(/−/g, '−');
14 | str = str.replace(/∗/g, '∗');
15 | str = str.replace(/√/g, '√');
16 | str = str.replace(/∝/g, '∝');
17 | str = str.replace(/∞/g, '∞');
18 | str = str.replace(/∠/g, '∠');
19 | str = str.replace(/∧/g, '∧');
20 | str = str.replace(/∨/g, '∨');
21 | str = str.replace(/∩/g, '∩');
22 | str = str.replace(/∩/g, '∪');
23 | str = str.replace(/∫/g, '∫');
24 | str = str.replace(/∴/g, '∴');
25 | str = str.replace(/∼/g, '∼');
26 | str = str.replace(/≅/g, '≅');
27 | str = str.replace(/≈/g, '≈');
28 | str = str.replace(/≠/g, '≠');
29 | str = str.replace(/≤/g, '≤');
30 | str = str.replace(/≥/g, '≥');
31 | str = str.replace(/⊂/g, '⊂');
32 | str = str.replace(/⊃/g, '⊃');
33 | str = str.replace(/⊄/g, '⊄');
34 | str = str.replace(/⊆/g, '⊆');
35 | str = str.replace(/⊇/g, '⊇');
36 | str = str.replace(/⊕/g, '⊕');
37 | str = str.replace(/⊗/g, '⊗');
38 | str = str.replace(/⊥/g, '⊥');
39 | str = str.replace(/⋅/g, '⋅');
40 | return str;
41 | }
42 |
43 | //HTML 支持的希腊字母
44 | function strGreeceDiscode(str){
45 | str = str.replace(/Α/g, 'Α');
46 | str = str.replace(/Β/g, 'Β');
47 | str = str.replace(/Γ/g, 'Γ');
48 | str = str.replace(/Δ/g, 'Δ');
49 | str = str.replace(/Ε/g, 'Ε');
50 | str = str.replace(/Ζ/g, 'Ζ');
51 | str = str.replace(/Η/g, 'Η');
52 | str = str.replace(/Θ/g, 'Θ');
53 | str = str.replace(/Ι/g, 'Ι');
54 | str = str.replace(/Κ/g, 'Κ');
55 | str = str.replace(/Λ/g, 'Λ');
56 | str = str.replace(/Μ/g, 'Μ');
57 | str = str.replace(/Ν/g, 'Ν');
58 | str = str.replace(/Ξ/g, 'Ν');
59 | str = str.replace(/Ο/g, 'Ο');
60 | str = str.replace(/Π/g, 'Π');
61 | str = str.replace(/Ρ/g, 'Ρ');
62 | str = str.replace(/Σ/g, 'Σ');
63 | str = str.replace(/Τ/g, 'Τ');
64 | str = str.replace(/Υ/g, 'Υ');
65 | str = str.replace(/Φ/g, 'Φ');
66 | str = str.replace(/Χ/g, 'Χ');
67 | str = str.replace(/Ψ/g, 'Ψ');
68 | str = str.replace(/Ω/g, 'Ω');
69 |
70 | str = str.replace(/α/g, 'α');
71 | str = str.replace(/β/g, 'β');
72 | str = str.replace(/γ/g, 'γ');
73 | str = str.replace(/δ/g, 'δ');
74 | str = str.replace(/ε/g, 'ε');
75 | str = str.replace(/ζ/g, 'ζ');
76 | str = str.replace(/η/g, 'η');
77 | str = str.replace(/θ/g, 'θ');
78 | str = str.replace(/ι/g, 'ι');
79 | str = str.replace(/κ/g, 'κ');
80 | str = str.replace(/λ/g, 'λ');
81 | str = str.replace(/μ/g, 'μ');
82 | str = str.replace(/ν/g, 'ν');
83 | str = str.replace(/ξ/g, 'ξ');
84 | str = str.replace(/ο/g, 'ο');
85 | str = str.replace(/π/g, 'π');
86 | str = str.replace(/ρ/g, 'ρ');
87 | str = str.replace(/ς/g, 'ς');
88 | str = str.replace(/σ/g, 'σ');
89 | str = str.replace(/τ/g, 'τ');
90 | str = str.replace(/υ/g, 'υ');
91 | str = str.replace(/φ/g, 'φ');
92 | str = str.replace(/χ/g, 'χ');
93 | str = str.replace(/ψ/g, 'ψ');
94 | str = str.replace(/ω/g, 'ω');
95 | str = str.replace(/ϑ/g, 'ϑ');
96 | str = str.replace(/ϒ/g, 'ϒ');
97 | str = str.replace(/ϖ/g, 'ϖ');
98 | str = str.replace(/·/g, '·');
99 | return str;
100 | }
101 |
102 | //
103 |
104 | function strcharacterDiscode(str){
105 | // 加入常用解析
106 | str = str.replace(/ /g, ' ');
107 | str = str.replace(/"/g, "'");
108 | str = str.replace(/&/g, '&');
109 | // str = str.replace(/</g, '‹');
110 | // str = str.replace(/>/g, '›');
111 |
112 | str = str.replace(/</g, '<');
113 | str = str.replace(/>/g, '>');
114 | str = str.replace(/•/g, '•');
115 |
116 | return str;
117 | }
118 |
119 | // HTML 支持的其他实体
120 | function strOtherDiscode(str){
121 | str = str.replace(/Œ/g, 'Œ');
122 | str = str.replace(/œ/g, 'œ');
123 | str = str.replace(/Š/g, 'Š');
124 | str = str.replace(/š/g, 'š');
125 | str = str.replace(/Ÿ/g, 'Ÿ');
126 | str = str.replace(/ƒ/g, 'ƒ');
127 | str = str.replace(/ˆ/g, 'ˆ');
128 | str = str.replace(/˜/g, '˜');
129 | str = str.replace(/ /g, '');
130 | str = str.replace(/ /g, '');
131 | str = str.replace(/ /g, '');
132 | str = str.replace(//g, '');
133 | str = str.replace(//g, '');
134 | str = str.replace(//g, '');
135 | str = str.replace(//g, '');
136 | str = str.replace(/–/g, '–');
137 | str = str.replace(/—/g, '—');
138 | str = str.replace(/‘/g, '‘');
139 | str = str.replace(/’/g, '’');
140 | str = str.replace(/‚/g, '‚');
141 | str = str.replace(/“/g, '“');
142 | str = str.replace(/”/g, '”');
143 | str = str.replace(/„/g, '„');
144 | str = str.replace(/†/g, '†');
145 | str = str.replace(/‡/g, '‡');
146 | str = str.replace(/•/g, '•');
147 | str = str.replace(/…/g, '…');
148 | str = str.replace(/‰/g, '‰');
149 | str = str.replace(/′/g, '′');
150 | str = str.replace(/″/g, '″');
151 | str = str.replace(/‹/g, '‹');
152 | str = str.replace(/›/g, '›');
153 | str = str.replace(/‾/g, '‾');
154 | str = str.replace(/€/g, '€');
155 | str = str.replace(/™/g, '™');
156 |
157 | str = str.replace(/←/g, '←');
158 | str = str.replace(/↑/g, '↑');
159 | str = str.replace(/→/g, '→');
160 | str = str.replace(/↓/g, '↓');
161 | str = str.replace(/↔/g, '↔');
162 | str = str.replace(/↵/g, '↵');
163 | str = str.replace(/⌈/g, '⌈');
164 | str = str.replace(/⌉/g, '⌉');
165 |
166 | str = str.replace(/⌊/g, '⌊');
167 | str = str.replace(/⌋/g, '⌋');
168 | str = str.replace(/◊/g, '◊');
169 | str = str.replace(/♠/g, '♠');
170 | str = str.replace(/♣/g, '♣');
171 | str = str.replace(/♥/g, '♥');
172 |
173 | str = str.replace(/♦/g, '♦');
174 | str = str.replace(/'/g, '\'');
175 | return str;
176 | }
177 |
178 | function strMoreDiscode(str){
179 | str = str.replace(/\r\n/g,"");
180 | str = str.replace(/\n/g,"");
181 |
182 | str = str.replace(/code/g,"wxxxcode-style");
183 | return str;
184 | }
185 |
186 | function strDiscode(str){
187 | str = strNumDiscode(str);
188 | str = strGreeceDiscode(str);
189 | str = strcharacterDiscode(str);
190 | str = strOtherDiscode(str);
191 | str = strMoreDiscode(str);
192 | return str;
193 | }
194 | function urlToHttpUrl(url,rep){
195 |
196 | var patt1 = new RegExp("^//");
197 | var result = patt1.test(url);
198 | if(result){
199 | url = rep+":"+url;
200 | }
201 | return url;
202 | }
203 |
204 | module.exports = {
205 | strDiscode:strDiscode,
206 | urlToHttpUrl:urlToHttpUrl
207 | }
--------------------------------------------------------------------------------
/pages/goods/detail/detail.wxss:
--------------------------------------------------------------------------------
1 | .container{
2 | margin-bottom: 100rpx;
3 | }
4 | .goodsimgs{
5 | width: 750rpx;
6 | height: 750rpx;
7 | }
8 |
9 | .goodsimgs image{
10 | width: 750rpx;
11 | height: 750rpx;
12 | }
13 |
14 | .goods-info{
15 | width: 750rpx;
16 | height: auto;
17 | overflow: hidden;
18 | background: #fff;
19 | }
20 |
21 | .goods-info .c{
22 | display: block;
23 | width: 718.75rpx;
24 | height: 100%;
25 | margin-left: 31.25rpx;
26 | padding: 38rpx 31.25rpx 38rpx 0;
27 | }
28 |
29 | .goods-info .c text{
30 | display: block;
31 | width: 687.5rpx;
32 | text-align: center;
33 | }
34 |
35 | .goods-info .name{
36 | height: auto;
37 | margin-bottom: 20rpx;
38 | font-size: 41rpx;
39 | line-height: 50rpx;
40 | overflow: hidden;
41 | }
42 |
43 | .goods-info .price{
44 | height: 35rpx;
45 | font-size: 35rpx;
46 | line-height: 35rpx;
47 | color: #b4282d;
48 | }
49 |
50 | .section-nav{
51 | width: 750rpx;
52 | height: auto;
53 | overflow: hidden;
54 | background: #fff;
55 | margin-bottom: 20rpx;
56 | }
57 |
58 | .section-nav .t{
59 | float: left;
60 | width: 750rpx;
61 | height: 108rpx;
62 | line-height: 108rpx;
63 | font-size: 38.5rpx;
64 | color: #333;
65 | margin-left: 31.25rpx;
66 | border-bottom: 1px solid #f4f4f4;
67 | }
68 |
69 | .section-nav .i{
70 | float: right;
71 | width: 52rpx;
72 | height: 52rpx;
73 | margin-right: 16rpx;
74 | margin-top: 28rpx;
75 | }
76 |
77 | .section-nav.section-attr{
78 | margin: 20rpx 0;
79 | }
80 |
81 | .goods-attr{
82 | width: 750rpx;
83 | height: auto;
84 | overflow: hidden;
85 | background: #fff;
86 | }
87 |
88 | .goods-attr .t{
89 | width: 687.5rpx;
90 | height: 104rpx;
91 | line-height: 104rpx;
92 | font-size: 38.5rpx;
93 | padding: 0 31.25rpx 25rpx 31.25rpx;
94 | border-bottom: 1px solid #f4f4f4;
95 | }
96 |
97 | /* @import "../../../libs/wxParse/wxParse.wxss"; */
98 |
99 |
100 | .detail{
101 | width: 750rpx;
102 | height: auto;
103 | overflow: hidden;
104 | padding: 30rpx;
105 | }
106 |
107 | .detail image{
108 | max-width: 690rpx;
109 | display: block;
110 | }
111 |
112 | .related-goods{
113 | width: 750rpx;
114 | height: auto;
115 | overflow: hidden;
116 | }
117 |
118 | .related-goods .h{
119 | position: relative;
120 | height: 145.5rpx;
121 | width: 750rpx;
122 | padding: 56.25rpx 0;
123 | background: #fff;
124 | text-align: center;
125 | border-bottom: 1px solid #f4f4f4;
126 | }
127 |
128 | .related-goods .h .line{
129 | display: inline-block;
130 | position: absolute;
131 | top: 72rpx;
132 | left: 0;
133 | z-index: 2;
134 | height: 1px;
135 | margin-left: 225rpx;
136 | width: 300rpx;
137 | background: #ccc;
138 | }
139 |
140 | .related-goods .h .title{
141 | display: inline-block;
142 | position: absolute;
143 | top: 56.125rpx;
144 | left: 0;
145 | z-index: 3;
146 | height: 33rpx;
147 | margin-left: 285rpx;
148 | width: 180rpx;
149 | background: #fff;
150 | }
151 |
152 | .related-goods .b{
153 | width: 750rpx;
154 | height: auto;
155 | overflow: hidden;
156 | }
157 |
158 | .related-goods .b .item{
159 | float: left;
160 | background: #fff;
161 | width: 375rpx;
162 | height: auto;
163 | overflow: hidden;
164 | text-align: center;
165 | padding: 15rpx 31.25rpx;
166 | border-right: 1px solid #f4f4f4;
167 | border-bottom: 1px solid #f4f4f4;
168 | }
169 |
170 | .related-goods .item .img{
171 | width: 311.45rpx;
172 | height: 311.45rpx;
173 | }
174 |
175 | .related-goods .item .name{
176 | display: block;
177 | width: 311.45rpx;
178 | height: 35rpx;
179 | margin: 11.5rpx 0 15rpx 0;
180 | text-align: center;
181 | overflow: hidden;
182 | font-size: 30rpx;
183 | color: #333;
184 | }
185 |
186 | .related-goods .item .price{
187 | display: block;
188 | width: 311.45rpx;
189 | height: 30rpx;
190 | text-align: center;
191 | font-size: 30rpx;
192 | color: #b4282d;
193 | }
194 |
195 | .bottom-btn{
196 | position: fixed;
197 | left:0;
198 | bottom:0;
199 | z-index: 10;
200 | width: 750rpx;
201 | height: 100rpx;
202 | display: flex;
203 | background: #fff;
204 | }
205 |
206 | .bottom-btn .l{
207 | float: left;
208 | height: 100rpx;
209 | width: 162rpx;
210 | border: 1px solid #f4f4f4;
211 | display: flex;
212 | align-items: center;
213 | justify-content: center;
214 |
215 | }
216 |
217 | .bottom-btn .l.l-collect{
218 | border-right: none;
219 | border-left: none;
220 | text-align: center;
221 | }
222 |
223 |
224 | .bottom-btn .l.l-cart .box{
225 | position: relative;
226 | height: 60rpx;
227 | width: 60rpx;
228 | }
229 |
230 | .bottom-btn .l.l-cart .cart-count{
231 | height: 28rpx;
232 | width: 28rpx;
233 | z-index: 10;
234 | position: absolute;
235 | top: 0;
236 | right:0;
237 | background: #d81e06;
238 | text-align: center;
239 | font-size: 18rpx;
240 | color: #fff;
241 | line-height: 28rpx;
242 | border-radius: 50%;
243 |
244 | }
245 |
246 | .bottom-btn .l.l-cart .icon{
247 |
248 | position: absolute;
249 | top: 10rpx;
250 | left:0;
251 |
252 | }
253 |
254 |
255 | .bottom-btn .l .icon{
256 | display: block;
257 | height: 44rpx;
258 | width: 44rpx;
259 | }
260 |
261 |
262 | .bottom-btn .c{
263 | float: left;
264 | height: 100rpx;
265 | line-height: 96rpx;
266 | flex: 1;
267 | text-align: center;
268 | color: #333;
269 | border-top: 1px solid #f4f4f4;
270 | border-bottom: 1px solid #f4f4f4;
271 | }
272 |
273 | .bottom-btn .r{
274 | border:1px solid #d81e06;
275 | background: #d81e06;
276 | float: left;
277 | height: 100rpx;
278 | line-height: 96rpx;
279 | flex: 1;
280 | text-align: center;
281 | color: #fff;
282 | }
283 |
284 | .attr-pop{
285 | width: 100%;
286 | height: auto;
287 | overflow: hidden;
288 | padding: 31.25rpx;
289 | background: #fff;
290 | }
291 |
292 | .spec-con{
293 | width: 100%;
294 | height: auto;
295 | overflow: hidden;
296 | }
297 |
298 | .spec-con .name{
299 | height: 32rpx;
300 | margin-bottom: 22rpx;
301 | font-size: 29rpx;
302 | color: #333;
303 | }
304 |
305 | .spec-con .values{
306 | height: auto;
307 | margin-bottom: 31.25rpx;
308 | font-size: 0;
309 | }
310 |
311 | .spec-con .value{
312 | display: inline-block;
313 | height: 62rpx;
314 | padding: 0 35rpx;
315 | line-height: 56rpx;
316 | text-align: center;
317 | margin-right: 25rpx;
318 | margin-bottom: 16.5rpx;
319 | border: 1px solid #333;
320 | font-size: 25rpx;
321 | color: #333;
322 | }
323 |
324 | .spec-con .value.disable{
325 | border: 1px solid #ccc;
326 | color: #ccc;
327 | }
328 |
329 | .spec-con .value.selected{
330 | border: 1px solid #b4282d;
331 | color: #b4282d;
332 | }
333 |
334 | .number-item .selnum{
335 | width: 322rpx;
336 | height: 71rpx;
337 | border: 1px solid #ccc;
338 | display: flex;
339 | }
340 |
341 | .number-item .cut{
342 | width: 93.75rpx;
343 | height: 100%;
344 | text-align: center;
345 | line-height: 65rpx;
346 | }
347 |
348 | .number-item .number{
349 | flex: 1;
350 | height: 100%;
351 | text-align: center;
352 | line-height: 68.75rpx;
353 | border-left: 1px solid #ccc;
354 | border-right: 1px solid #ccc;
355 | float: left;
356 | }
357 |
358 | .number-item .add{
359 | width: 93.75rpx;
360 | height: 100%;
361 | text-align: center;
362 | line-height: 65rpx;
363 | }
364 |
365 |
366 |
--------------------------------------------------------------------------------
/libs/wxParse/html2json.js:
--------------------------------------------------------------------------------
1 | /**
2 | * html2Json 改造来自: https://github.com/Jxck/html2json
3 | *
4 | *
5 | * author: Di (微信小程序开发工程师)
6 | * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
7 | * 垂直微信小程序开发交流社区
8 | *
9 | * github地址: https://github.com/icindy/wxParse
10 | *
11 | * for: 微信小程序富文本解析
12 | * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
13 | */
14 |
15 | var __placeImgeUrlHttps = "https";
16 | var __emojisReg = '';
17 | var __emojisBaseSrc = '';
18 | var __emojis = {};
19 | var wxDiscode = require('./wxDiscode.js');
20 | var HTMLParser = require('./htmlparser.js');
21 | // Empty Elements - HTML 5
22 | var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr");
23 | // Block Elements - HTML 5
24 | var block = makeMap("br,a,code,address,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");
25 |
26 | // Inline Elements - HTML 5
27 | var inline = makeMap("abbr,acronym,applet,b,basefont,bdo,big,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");
28 |
29 | // Elements that you can, intentionally, leave open
30 | // (and which close themselves)
31 | var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
32 |
33 | // Attributes that have their values filled in disabled="disabled"
34 | var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");
35 |
36 | // Special Elements (can contain anything)
37 | var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
38 | function makeMap(str) {
39 | var obj = {}, items = str.split(",");
40 | for (var i = 0; i < items.length; i++)
41 | obj[items[i]] = true;
42 | return obj;
43 | }
44 |
45 | function q(v) {
46 | return '"' + v + '"';
47 | }
48 |
49 | function removeDOCTYPE(html) {
50 | return html
51 | .replace(/<\?xml.*\?>\n/, '')
52 | .replace(/<.*!doctype.*\>\n/, '')
53 | .replace(/<.*!DOCTYPE.*\>\n/, '');
54 | }
55 |
56 | function trimHtml(html) {
57 | return html
58 | .replace(/\n+/g, '')
59 | .replace(//ig, '')
60 | .replace(/\/\*.*?\*\//ig, '')
61 | .replace(/[ ]+
189 | // add to parents
190 | var parent = bufArray[0] || results;
191 | if (parent.nodes === undefined) {
192 | parent.nodes = [];
193 | }
194 | parent.nodes.push(node);
195 | } else {
196 | bufArray.unshift(node);
197 | }
198 | },
199 | end: function (tag) {
200 | //debug(tag);
201 | // merge into parent tag
202 | var node = bufArray.shift();
203 | if (node.tag !== tag) console.error('invalid state: mismatch end tag');
204 |
205 | //当有缓存source资源时于于video补上src资源
206 | if(node.tag === 'video' && results.source){
207 | node.attr.src = results.source;
208 | delete result.source;
209 | }
210 |
211 | if (bufArray.length === 0) {
212 | results.nodes.push(node);
213 | } else {
214 | var parent = bufArray[0];
215 | if (parent.nodes === undefined) {
216 | parent.nodes = [];
217 | }
218 | parent.nodes.push(node);
219 | }
220 | },
221 | chars: function (text) {
222 | //debug(text);
223 | var node = {
224 | node: 'text',
225 | text: text,
226 | textArray:transEmojiStr(text)
227 | };
228 |
229 | if (bufArray.length === 0) {
230 | results.nodes.push(node);
231 | } else {
232 | var parent = bufArray[0];
233 | if (parent.nodes === undefined) {
234 | parent.nodes = [];
235 | }
236 | node.index = parent.index + '.' + parent.nodes.length
237 | parent.nodes.push(node);
238 | }
239 | },
240 | comment: function (text) {
241 | //debug(text);
242 | // var node = {
243 | // node: 'comment',
244 | // text: text,
245 | // };
246 | // var parent = bufArray[0];
247 | // if (parent.nodes === undefined) {
248 | // parent.nodes = [];
249 | // }
250 | // parent.nodes.push(node);
251 | },
252 | });
253 | return results;
254 | };
255 |
256 | function transEmojiStr(str){
257 | // var eReg = new RegExp("["+__reg+' '+"]");
258 | // str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
259 |
260 | var emojiObjs = [];
261 | //如果正则表达式为空
262 | if(__emojisReg.length == 0 || !__emojis){
263 | var emojiObj = {}
264 | emojiObj.node = "text";
265 | emojiObj.text = str;
266 | array = [emojiObj];
267 | return array;
268 | }
269 | //这个地方需要调整
270 | str = str.replace(/\[([^\[\]]+)\]/g,':$1:')
271 | var eReg = new RegExp("[:]");
272 | var array = str.split(eReg);
273 | for(var i = 0; i < array.length; i++){
274 | var ele = array[i];
275 | var emojiObj = {};
276 | if(__emojis[ele]){
277 | emojiObj.node = "element";
278 | emojiObj.tag = "emoji";
279 | emojiObj.text = __emojis[ele];
280 | emojiObj.baseSrc= __emojisBaseSrc;
281 | }else{
282 | emojiObj.node = "text";
283 | emojiObj.text = ele;
284 | }
285 | emojiObjs.push(emojiObj);
286 | }
287 |
288 | return emojiObjs;
289 | }
290 |
291 | function emojisInit(reg='',baseSrc="/wxParse/emojis/",emojis){
292 | __emojisReg = reg;
293 | __emojisBaseSrc=baseSrc;
294 | __emojis=emojis;
295 | }
296 |
297 | module.exports = {
298 | html2json: html2json,
299 | emojisInit:emojisInit
300 | };
301 |
302 |
--------------------------------------------------------------------------------
/libs/wxParse/wxParse.wxml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
27 |
28 | {{item.text}}
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | \n
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 |
735 |
736 |
737 |
738 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
752 |
753 |
754 |
755 |
756 |
757 |
758 |
759 |
760 |
761 |
762 |
763 |
764 |
765 |
766 |
767 |
768 |
769 |
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
828 |
829 |
830 |
831 |
832 |
833 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 |
883 |
884 |
885 |
886 |
887 |
888 |
889 |
890 |
891 |
892 |
893 |
894 |
895 |
896 |
897 |
898 |
899 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 |
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 |
926 |
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 |
936 |
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
945 |
946 |
947 |
948 |
949 |
950 |
951 |
952 |
953 |
954 |
955 |
956 |
957 |
958 |
959 |
960 |
961 |
962 |
963 |
964 |
965 |
966 |
967 |
--------------------------------------------------------------------------------