├── public ├── favicon.ico ├── share.png └── index.html ├── static └── img │ ├── share.jpg │ ├── share.png │ ├── wyz_1.jpg │ ├── wyz_2.jpg │ ├── wyz_3.jpg │ ├── wyz_4.jpg │ ├── wyz_5.jpg │ ├── wyz_5.png │ ├── wyz_6.jpg │ ├── wyz_6.png │ ├── wyz_7.jpg │ ├── banner.jpg │ ├── banner2.jpg │ └── banner3.jpg ├── src ├── assets │ ├── img │ │ ├── back.png │ │ ├── home.png │ │ ├── link.png │ │ ├── delete.png │ │ ├── qrcode.jpg │ │ ├── search.png │ │ ├── back_top.png │ │ ├── bg_coupon.png │ │ ├── icon_fail.png │ │ ├── icon_logo.png │ │ ├── search_2.png │ │ ├── icon_qrcode.png │ │ ├── jump_coupon.png │ │ ├── nodata_img.png │ │ ├── category │ │ │ ├── jujia.png │ │ │ ├── more.png │ │ │ ├── neiyi.png │ │ │ ├── muying.png │ │ │ ├── xiebao.png │ │ │ ├── meizhuang.png │ │ │ ├── nanzhuang.png │ │ │ └── nvzhuang.png │ │ └── lazy_default.png │ ├── js │ │ ├── export.js │ │ ├── url.js │ │ ├── network.js │ │ ├── api.js │ │ ├── common.js │ │ └── fastclick.js │ └── css │ │ └── common.css ├── pages │ ├── search │ │ ├── search.js │ │ ├── search.html │ │ └── search.vue │ ├── index │ │ ├── index.js │ │ ├── index.html │ │ └── index.vue │ ├── detail │ │ ├── detail.js │ │ ├── detail.html │ │ └── detail.vue │ └── coupon │ │ ├── coupon.js │ │ ├── coupon.html │ │ └── coupon.vue ├── components │ ├── jumpCoupon.vue │ ├── backTop.vue │ ├── soldOut.vue │ ├── errNotice.vue │ ├── loading.vue │ ├── categoryList.vue │ ├── qrcodePop.vue │ └── shopList.vue └── mock │ └── index.js ├── babel.config.js ├── .editorconfig ├── .gitignore ├── vue.util.js ├── package.json ├── vue.config.js └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/public/share.png -------------------------------------------------------------------------------- /static/img/share.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/share.jpg -------------------------------------------------------------------------------- /static/img/share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/share.png -------------------------------------------------------------------------------- /static/img/wyz_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_1.jpg -------------------------------------------------------------------------------- /static/img/wyz_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_2.jpg -------------------------------------------------------------------------------- /static/img/wyz_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_3.jpg -------------------------------------------------------------------------------- /static/img/wyz_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_4.jpg -------------------------------------------------------------------------------- /static/img/wyz_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_5.jpg -------------------------------------------------------------------------------- /static/img/wyz_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_5.png -------------------------------------------------------------------------------- /static/img/wyz_6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_6.jpg -------------------------------------------------------------------------------- /static/img/wyz_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_6.png -------------------------------------------------------------------------------- /static/img/wyz_7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/wyz_7.jpg -------------------------------------------------------------------------------- /src/assets/img/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/back.png -------------------------------------------------------------------------------- /src/assets/img/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/home.png -------------------------------------------------------------------------------- /src/assets/img/link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/link.png -------------------------------------------------------------------------------- /static/img/banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/banner.jpg -------------------------------------------------------------------------------- /static/img/banner2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/banner2.jpg -------------------------------------------------------------------------------- /static/img/banner3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/static/img/banner3.jpg -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/assets/img/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/delete.png -------------------------------------------------------------------------------- /src/assets/img/qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/qrcode.jpg -------------------------------------------------------------------------------- /src/assets/img/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/search.png -------------------------------------------------------------------------------- /src/assets/img/back_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/back_top.png -------------------------------------------------------------------------------- /src/assets/img/bg_coupon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/bg_coupon.png -------------------------------------------------------------------------------- /src/assets/img/icon_fail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/icon_fail.png -------------------------------------------------------------------------------- /src/assets/img/icon_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/icon_logo.png -------------------------------------------------------------------------------- /src/assets/img/search_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/search_2.png -------------------------------------------------------------------------------- /src/assets/img/icon_qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/icon_qrcode.png -------------------------------------------------------------------------------- /src/assets/img/jump_coupon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/jump_coupon.png -------------------------------------------------------------------------------- /src/assets/img/nodata_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/nodata_img.png -------------------------------------------------------------------------------- /src/assets/img/category/jujia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/jujia.png -------------------------------------------------------------------------------- /src/assets/img/category/more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/more.png -------------------------------------------------------------------------------- /src/assets/img/category/neiyi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/neiyi.png -------------------------------------------------------------------------------- /src/assets/img/lazy_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/lazy_default.png -------------------------------------------------------------------------------- /src/assets/img/category/muying.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/muying.png -------------------------------------------------------------------------------- /src/assets/img/category/xiebao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/xiebao.png -------------------------------------------------------------------------------- /src/assets/img/category/meizhuang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/meizhuang.png -------------------------------------------------------------------------------- /src/assets/img/category/nanzhuang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/nanzhuang.png -------------------------------------------------------------------------------- /src/assets/img/category/nvzhuang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jackchen0120/woyouzhe/HEAD/src/assets/img/category/nvzhuang.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /src/assets/js/export.js: -------------------------------------------------------------------------------- 1 | import '../css/common.css' 2 | 3 | import C from './common' 4 | 5 | // 解决click点击300毫秒延时问题 6 | import FastClick from './fastclick' 7 | 8 | // FastClick.attach(document.body); 9 | !(function(){ 10 | new FastClick(document.body) 11 | }) 12 | 13 | 14 | export default C -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | *.zip 23 | -------------------------------------------------------------------------------- /src/pages/search/search.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | 5 | import Search from './search.vue' 6 | 7 | 8 | Vue.config.productionTip = false 9 | 10 | /* eslint-disable no-new */ 11 | new Vue({ 12 | data: { 13 | bottomType: new Vue() 14 | }, 15 | render: h => h(Search) 16 | }).$mount('#app') 17 | -------------------------------------------------------------------------------- /src/pages/index/index.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | 5 | import Index from './index.vue' 6 | import axios from 'axios' 7 | 8 | Vue.prototype.$http = axios 9 | 10 | Vue.config.productionTip = false 11 | 12 | /* eslint-disable no-new */ 13 | new Vue({ 14 | data: { 15 | bottomType: new Vue() 16 | }, 17 | render: h => h(Index) 18 | }).$mount('#app') 19 | 20 | -------------------------------------------------------------------------------- /src/pages/detail/detail.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | 5 | import VueClipboards from 'vue-clipboards' 6 | 7 | import Detail from './detail.vue' 8 | 9 | Vue.use(VueClipboards) 10 | 11 | Vue.config.productionTip = false 12 | 13 | /* eslint-disable no-new */ 14 | new Vue({ 15 | data: { 16 | bottomType: new Vue() 17 | }, 18 | render: h => h(Detail) 19 | }).$mount('#app') 20 | -------------------------------------------------------------------------------- /src/pages/coupon/coupon.js: -------------------------------------------------------------------------------- 1 | // The Vue build version to load with the `import` command 2 | // (runtime-only or standalone) has been set in webpack.base.conf with an alias. 3 | import Vue from 'vue' 4 | 5 | import VueClipboards from 'vue-clipboards'; 6 | 7 | import Coupon from './coupon.vue' 8 | 9 | Vue.use(VueClipboards); 10 | 11 | Vue.config.productionTip = false 12 | 13 | /* eslint-disable no-new */ 14 | new Vue({ 15 | data: { 16 | bottomType: new Vue() 17 | }, 18 | render: h => h(Coupon) 19 | }).$mount('#app') 20 | -------------------------------------------------------------------------------- /src/assets/js/url.js: -------------------------------------------------------------------------------- 1 | 2 | let baseUrl = ''; 3 | let url = ''; 4 | 5 | if (process.env.NODE_ENV == 'development') { 6 | console.log('dev') 7 | //开发、测试环境 8 | // baseUrl = '/api' // mock默认地址 9 | // baseUrl = '//yapi.demo.qunar.com/mock/95397/api' // yapi配置生成服务器地址 10 | baseUrl = '//api.xuandan.com/DataApi'; 11 | url = ''; 12 | } else if (process.env.NODE_ENV == 'production') { 13 | console.log('prod') 14 | // 生产环境 15 | baseUrl = '//api.xuandan.com/DataApi'; 16 | url = '/woyouzhe'; 17 | } 18 | 19 | export { 20 | baseUrl, 21 | url 22 | } -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/assets/js/network.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import { baseUrl } from './url' 3 | 4 | let service = axios.create({ 5 | baseURL: baseUrl, // 请求前缀 6 | timeout: 55000, // 请求超时时间 7 | }) 8 | 9 | // 设置 post 默认 Content-Type 10 | service.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' 11 | 12 | // 添加请求拦截器 13 | service.interceptors.request.use( 14 | config => { 15 | 16 | // 这里可以添加head 部分 17 | return config 18 | }, 19 | err => { 20 | 21 | // 请求错误处理 22 | return Promise.reject(err) 23 | }) 24 | 25 | // 添加响应拦截器 26 | service.interceptors.response.use( 27 | response => { 28 | 29 | let { data } = response 30 | 31 | return data 32 | }, 33 | err => { 34 | 35 | // 响应错误处理 36 | return Promise.reject(err) 37 | }) 38 | 39 | 40 | export default service -------------------------------------------------------------------------------- /vue.util.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const glob = require('glob') 3 | const startPath = '/src/pages/' 4 | const pagePath = path.resolve(__dirname, '.' + startPath) 5 | 6 | exports.pages = function () { 7 | let entryFiles = glob.sync(pagePath + '/**/*.html') 8 | let obj = {} 9 | 10 | entryFiles.forEach(filePath => { 11 | let dirPath = filePath.substring(0, filePath.lastIndexOf('/')) 12 | let dirName = dirPath.substring(dirPath.lastIndexOf('/') + 1) 13 | let filename = filePath.substring(filePath.lastIndexOf(startPath) + startPath.length, filePath.lastIndexOf('/')) 14 | 15 | if (filename.endsWith(dirName)) { 16 | obj[filename] = { 17 | entry: filePath.substring(0, filePath.lastIndexOf('.html')) + '.js', 18 | template: filePath.substring(0, filePath.lastIndexOf('.html')) + '.html' 19 | } 20 | } 21 | }) 22 | 23 | return obj 24 | } -------------------------------------------------------------------------------- /src/components/jumpCoupon.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 30 | 31 | 58 | -------------------------------------------------------------------------------- /src/pages/coupon/coupon.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 我有折 - 汇聚最全的网络优惠信息。淘宝优惠券,天猫优惠券 15 | 16 | 17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/pages/detail/detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 我有折 - 汇聚最全的网络优惠信息。淘宝优惠券,天猫优惠券 15 | 16 | 17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/pages/search/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 我有折 - 汇聚最全的网络优惠信息。淘宝优惠券,天猫优惠券 15 | 16 | 17 | 18 | 19 | 20 |
21 |
22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/components/backTop.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 43 | 44 | 60 | -------------------------------------------------------------------------------- /src/assets/js/api.js: -------------------------------------------------------------------------------- 1 | import network from './network' 2 | import { baseUrl } from './url' 3 | // import Mock from '@/mock' 4 | 5 | 6 | // 普通产品API接口 7 | export function getShopList(page, pagesize, sort, cid, key) { 8 | return network({ 9 | url: '/index?AppKey=uqd2sealrp', 10 | method: 'get', 11 | params: { 12 | page, // 页码 13 | pagesize, // 页数 14 | sort, // 1.较新商品提交时间(默认) 2.券后价高到低 3.券后价低到高 4.(券价÷原价)优惠比例 5.开始时间较早(预告到非预告)6.销量高到低 7.两小时销量 8.全天销量 15 | cid, // 0.全部 1.女装 2.男装 3.内衣 4.母婴 5.化妆品 6.居家 7.鞋包配饰 8.美食 9.文体车品 10.数码家电 16 | key 17 | } 18 | }) 19 | } 20 | 21 | // 单品详情API接口 22 | export function getShopDetail(id) { 23 | return network({ 24 | url: '/item?AppKey=uqd2sealrp', 25 | method: 'get', 26 | params: { 27 | id 28 | } 29 | }) 30 | } 31 | 32 | // mockjs 模拟商品列表接口 33 | export function getMockData() { 34 | return network({ 35 | url: '/shoplist', 36 | method: 'get' 37 | }); 38 | } 39 | 40 | // 商品分类 41 | // export function getCategoryList() { 42 | // return network({ 43 | // url: '/categoryList', 44 | // method: 'get', 45 | // }); 46 | // } 47 | 48 | // 商品详情 49 | // export function getShopDetail(id) { 50 | // return network({ 51 | // url: '/shopDetail', 52 | // method: 'get', 53 | // params: { 54 | // id 55 | // } 56 | // }) 57 | // } 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/components/soldOut.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 45 | 46 | 73 | -------------------------------------------------------------------------------- /src/mock/index.js: -------------------------------------------------------------------------------- 1 | import Mock from 'mockjs' 2 | 3 | let shopData = { 4 | 'success|1': [true, false], 5 | 'msg': function() { 6 | if (this.success) { 7 | return '调用成功'; 8 | } else { 9 | return '调用失败'; 10 | } 11 | }, 12 | 'pageNum': 1, 13 | 'pageSize': 10, 14 | 'data': function() { 15 | if (this.success) { 16 | return this.result; 17 | } else { 18 | return this.result = []; 19 | } 20 | }, 21 | 'result|1-10': [{ 22 | 'id|+1': 1, 23 | 'GoodsId': '@guid', 24 | 'GoodsName|1': ['浙江特产手工糯米糕桂花糕250g', '【买一送一】夏季冰丝男裤休闲长裤', '仁和红豆薏米祛茶湿茶饮小袋装'], 25 | 'actDate': '@now', 26 | 'sales|0-100': 10, 27 | 'ShopName|1': ['汉兰图旗舰店', '吴玉源旗舰店', '帅趣旗舰店'], 28 | 'ImgUrl': '@image("200x200", "#00405d", "#FFF", "Mock.js")', 29 | 'GoodsPrice|1-200.1': 50, 30 | 'GoodsLink': '@url' 31 | }], 32 | 'totalNum': function() { 33 | return this.data.length; 34 | }, 35 | } 36 | 37 | let categoryData = { 38 | 'userInfo|1-5': [{    //生成|num个如下格式名字的数据 39 |       'id|+1': 1,  //数字从当前数开始后续依次加一 40 |       'name': '@cname',    //名字为随机中文名字 41 |       'ago|18-28': 25,    //年龄为18-28之间的随机数字 42 |       'sex|1': ['男', '女'],    //性别是数组中的一个,随机的 43 |       'job|1': ['web', 'UI', 'python', 'java'],  //工作是数组中的一个 44 | 'img': '@image("200x100")' 45 | }] 46 | } 47 | 48 | //格式:Mock.mock(url, post/get, 返回的数据) 49 | Mock.mock('/api/shoplist', shopData) 50 | Mock.mock('/api/categoryList', categoryData) 51 | 52 | export default Mock -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wyz", 3 | "version": "0.1.0", 4 | "private": true, 5 | "author": "JackChen <278910933@qq.com>", 6 | "scripts": { 7 | "serve": "vue-cli-service serve", 8 | "build": "vue-cli-service build", 9 | "lint": "vue-cli-service lint" 10 | }, 11 | "dependencies": { 12 | "axios": "^0.19.2", 13 | "vue": "^2.6.11", 14 | "vue-clipboards": "^1.3.0" 15 | }, 16 | "devDependencies": { 17 | "@vue/cli-plugin-babel": "^4.3.0", 18 | "@vue/cli-plugin-eslint": "^4.3.0", 19 | "@vue/cli-service": "^4.3.0", 20 | "@vue/eslint-config-standard": "^5.1.2", 21 | "babel-eslint": "^10.1.0", 22 | "eslint": "^6.7.2", 23 | "eslint-plugin-import": "^2.20.2", 24 | "eslint-plugin-node": "^11.1.0", 25 | "eslint-plugin-promise": "^4.2.1", 26 | "eslint-plugin-standard": "^4.0.0", 27 | "eslint-plugin-vue": "^6.2.2", 28 | "mockjs": "^1.1.0", 29 | "node-sass": "^4.12.0", 30 | "sass-loader": "^8.0.2", 31 | "uglifyjs-webpack-plugin": "^2.2.0", 32 | "vue-template-compiler": "^2.6.11" 33 | }, 34 | "eslintConfig": { 35 | "root": true, 36 | "env": { 37 | "node": true 38 | }, 39 | "extends": [ 40 | "plugin:vue/essential", 41 | "@vue/standard" 42 | ], 43 | "parserOptions": { 44 | "parser": "babel-eslint" 45 | }, 46 | "rules": {} 47 | }, 48 | "browserslist": [ 49 | "> 1%", 50 | "last 2 versions", 51 | "not dead" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /src/components/errNotice.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 35 | 36 | 80 | -------------------------------------------------------------------------------- /src/pages/index/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 我有折 - 汇聚最全的网络优惠信息。淘宝优惠券,天猫优惠券 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 |
26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | const utils = require('./vue.util') 2 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin') 3 | const isProduction = process.env.NODE_ENV === 'production' 4 | 5 | module.exports = { 6 | pages: utils.pages(), // 多页配置 7 | publicPath: isProduction ? '/woyouzhe/' : '/', // 部署生产环境和开发环境下的URL:可对当前环境进行区分 8 | lintOnSave: false, // 是否在代码保存时进行eslint检测 9 | productionSourceMap: false, // 是否在构建生产包时生成sourceMap文件,false将提高构建速度 10 | devServer: { // webpack-dev-server 相关配置 11 | port: '8090', // 端口号 12 | https: false, // 关闭https 13 | hotOnly: false, // 取消热更新 14 | // proxy: { // 使用代理 15 | // '/api': { 16 | // target: '//www.woyouzhe.com', // 目标代理服务器地址 17 | // changeOrigin: true, // 允许跨域 18 | // pathRewrite:{ 19 | // '^/api': '' // 重写路径,需要设置重写的话,要在后面的调用接口前加上/api来代替target 20 | // } 21 | // } 22 | // } 23 | }, 24 | // webpack手动配置 25 | configureWebpack: (config) => { 26 | if (isProduction) { 27 | // 取消webpack警告的性能提示 28 | config.performance = { 29 | hints: 'error', 30 | maxAssetSize: 300000, // 生成文件的最大体积,整数类型(以字节为单位) 31 | maxEntrypointSize: 500000, // 入口起点的最大体积,整数类型(以字节为单位) 32 | assetFilter: function(assetFilename) { // 只给出js文件的性能提示 33 | return assetFilename.endsWith('.js') 34 | } 35 | } 36 | 37 | config.plugins.push( 38 | new UglifyJsPlugin({ 39 | uglifyOptions: { 40 | compress: { 41 | drop_debugger: true, // 生产环境自动删除debugger 42 | drop_console: true, // 生产环境自动删除console 43 | }, 44 | warnings: false // 删除无用代码,不提示警告 45 | }, 46 | sourceMap: false, // 关闭错误消息位置映射到模块 47 | parallel: true, // 启用多进程并行运行 48 | }) 49 | ) 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/components/loading.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 45 | 46 | -------------------------------------------------------------------------------- /src/assets/js/common.js: -------------------------------------------------------------------------------- 1 | let Rxports = { 2 | // 遍历数组与对象,回调的第一个参数为索引或键名,第二个或元素或键值 3 | each: function (obj, fn) { 4 | var me = this; 5 | if (obj) { // 排除null, undefined 6 | var i = 0 7 | if (me.isArrayLike(obj)) { 8 | for (var n = obj.length; i < n; i++) { 9 | if (fn(i, obj[i]) === false) 10 | break 11 | } 12 | } else { 13 | for (i in obj) { 14 | if (obj.hasOwnProperty(i) && fn(i, obj[i]) === false) { 15 | break 16 | } 17 | } 18 | } 19 | } 20 | }, 21 | // 获取url参数 22 | getUrlParam: function () { 23 | var url = window.location.search, // 获取url中"?"符后的字串 24 | theRequest = new Object(); 25 | if (url.indexOf("?") != -1) { 26 | var str = url.substr(1), strs = str.split("&"); 27 | for(var i = 0; i < strs.length; i ++) { 28 | theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); 29 | } 30 | } 31 | return theRequest; 32 | }, 33 | // 页面单位rem 34 | rem: function () { 35 | var docEl = document.documentElement, 36 | resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', 37 | recalc = function () { 38 | var clientWidth = docEl.clientWidth; 39 | if (!clientWidth) return; 40 | if (clientWidth >= 750) { 41 | docEl.style.fontSize = '100px'; 42 | } else { 43 | docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'; 44 | } 45 | }; 46 | recalc(); 47 | window.addEventListener(resizeEvt, recalc, false); 48 | }, 49 | // 自定义模态框 50 | modalHelper: { 51 | scrollTop: '', 52 | bodyCls: 'modal-open', 53 | srcollBody: (document.scrollingElement || document.body), 54 | afterOpen: function() { 55 | var me = this; 56 | this.scrollTop = this.srcollBody.scrollTop; 57 | document.body.classList.add(me.bodyCls); 58 | document.body.style.top = -this.scrollTop + 'px'; 59 | }, 60 | beforeClose: function () { 61 | var me = this; 62 | document.body.classList.remove(me.bodyCls); 63 | this.srcollBody.scrollTop = this.scrollTop; 64 | document.body.style.top = '0'; 65 | } 66 | }, 67 | // 去除空格 68 | trim: function (strs) { 69 | return strs.replace(/(^\s*)|(\s*$)/g, ''); 70 | } 71 | } 72 | 73 | export default Rxports -------------------------------------------------------------------------------- /src/components/categoryList.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 96 | 97 | 128 | -------------------------------------------------------------------------------- /src/components/qrcodePop.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 32 | 33 | 160 | -------------------------------------------------------------------------------- /src/assets/css/common.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | 3 | 4 | /*消除原生外观,在iOS上加上这个属性才能给按钮和输入框自定义样式*/ 5 | input, textarea { 6 | -webkit-appearance: none; 7 | } 8 | 9 | /*在iOS下禁止长按页面时弹出菜单*/ 10 | a, img { 11 | -webkit-touch-callout: none; 12 | } 13 | 14 | /*去掉点击链接和文本框对象的半透明覆盖(iOS)或者虚框(Android)*/ 15 | a, button, input, optgroup, select, textarea { 16 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 17 | } 18 | 19 | html, body { 20 | width: 100%; 21 | /*max-width: 750px;*/ 22 | margin:0 auto; 23 | -webkit-user-select: none; /*禁止页面文字选择*/ 24 | user-select: none; 25 | -webkit-box-sizing: border-box; 26 | -moz-box-sizing: border-box; 27 | box-sizing: border-box; 28 | } 29 | html { 30 | -webkit-text-size-adjust: 100%; 31 | -ms-text-size-adjust: 100%; 32 | } 33 | body { 34 | margin: 0; 35 | padding: 0; 36 | color: #333; 37 | background: #fff; 38 | font-family: "微软雅黑", "Helvetica Neue", Helvetica, STHeiTi, sans-serif; 39 | -webkit-overflow-scrolling: touch; /*局部滚动(仅iOS 5以上支持)*/ 40 | } 41 | ul,ol,dd,dl,li,dt,p,h1,h2,h3,h4,h5,h6 { 42 | list-style:none; 43 | margin: 0; 44 | padding: 0 45 | } 46 | a { 47 | color: #333; 48 | text-decoration: none; 49 | } 50 | img { 51 | width: 100%; 52 | height: 100%; 53 | border: none; 54 | } 55 | input, img { 56 | vertical-align: middle; 57 | } 58 | input, button { 59 | border: none; 60 | outline: none; 61 | -webkit-appearance: none; 62 | -moz-appearance: none; 63 | -webkit-box-sizing: border-box; 64 | box-sizing: border-box; 65 | } 66 | em, i { 67 | font-style: normal; 68 | } 69 | .left { 70 | float: left 71 | } 72 | .right { 73 | float: right 74 | } 75 | .fix:after { 76 | content: ''; 77 | display: block; 78 | clear: both; 79 | visibility: hidden; 80 | } 81 | .clear { 82 | zoom: 1; 83 | clear: both; 84 | } 85 | .of { 86 | overflow: hidden; 87 | word-wrap: break-word; 88 | word-break: break-all; 89 | white-space: nowrap; 90 | text-overflow: ellipsis; 91 | } 92 | 93 | .wb { 94 | word-wrap: break-word; 95 | word-break: break-all; 96 | text-overflow: ellipsis; 97 | } 98 | 99 | .overtouch { 100 | overflow-y: auto; 101 | -webkit-overflow-scrolling: touch; 102 | } 103 | 104 | body.modal-open { 105 | position: fixed; 106 | width: 100%; 107 | } 108 | 109 | .flex-cont { 110 | /*定义为flexbox的"父元素"*/ 111 | display: -webkit-box; 112 | display: -webkit-flex; 113 | display: flex; 114 | } 115 | 116 | .flex-item { 117 | /*给"子元素"赋予自由伸缩的能力*/ 118 | -webkit-box-flex: 1; 119 | -webkit-flex: 1; 120 | flex: 1; 121 | } 122 | 123 | /*导航*/ 124 | .flex-nav { 125 | height: .88rem; 126 | /*定义子元素垂直居中*/ 127 | -webkit-box-align: center; 128 | -webkit-align-items: center; 129 | align-items: center; 130 | /*子元素沿主轴对齐方式均分*/ 131 | /* -webkit-box-pack: justify; 132 | -webkit-justify-content: space-between; 133 | justify-content: space-between;*/ 134 | } 135 | .flex-nav .nav-middle { 136 | text-align: center; 137 | line-height: 1.2; 138 | -webkit-box-flex: 1; 139 | -webkit-flex: 1; 140 | flex: 1; 141 | } 142 | .top-hr { 143 | margin-top: .88rem; 144 | visibility: hidden; 145 | } 146 | .top-menu { 147 | position: fixed; 148 | width: 100%; 149 | /*max-width: 750px;*/ 150 | top: 0; 151 | z-index: 99; 152 | background: #fc0786; 153 | } 154 | [v-cloak] { 155 | display: none; 156 | } 157 | 158 | /*img.lazy:after { 159 | content: ''; 160 | display: inline-block; 161 | position: absolute; 162 | z-index: 2; 163 | top: 0; 164 | left: 0; 165 | width: 100%; 166 | height: auto; 167 | background: url('../img/lazy_default.png') no-repeat; 168 | background-size: 100%; 169 | background-color: #fff; 170 | }*/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 本项目是利用业余时间开发完成的简单版,加深一下对各技术知识点的实操积累经验。基于 vue-cli3.x + axios 构建多页面应用的H5移动端电商网站,采用前后端分离技术,项目中用到的API接口是通过引入mockjs模拟数据和第三方API接口,让前端开发人员独立于后端进行开发。由于涉及微信页面,建议使用[微信web开发者工具](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html)进行页面开发。 3 | 4 | 前端人员也可以开发API接口,推荐几个模拟数据的工具,注册账号,查看官网文档: 5 | * mockjs官网 [http://mockjs.com/](http://mockjs.com/) 6 | * yapi官网 [http://yapi.demo.qunar.com/](http://yapi.demo.qunar.com/) 7 | * easy-mock官网 [https://easy-mock.com/docs](https://easy-mock.com/docs) 8 | 9 | [在线DEMO演示](http://106.55.168.13:8090/woyouzhe/) 10 | 11 | # 项目架构 12 | ``` 13 | │ vue.config.js // webpack配置 14 | │ vue.util.js // 打包多页面配置 15 | ├─public 16 | │ favicon.ico // 图标 17 | │ index.html // 入口html文件 18 | │ share.png // 微信分享提示 19 | ├─src 20 | │ ├─assets 21 | │ │ ├─css 22 | │ │ │ common.css // 公共样式文件 23 | │ │ ├─img // 存放公共图片文件夹 24 | │ │ └─js 25 | │ │ api.js // 封装所有API接口调用方法 26 | │ │ common.js // 常用JS方法 27 | │ │ export.js // 外部调用统一出口 28 | │ │ fastclick.js // 移动端点击延迟事件处理 29 | │ │ network.js // axios封装与拦截器配置 30 | │ │ url.js // 自动部署服务器环境 31 | │ ├─components 32 | │ │ backTop.vue // 返回顶部组件 33 | │ │ categoryList.vue // 商品分类组件 34 | │ │ errNotice.vue // 错误弹框提示信息组件 35 | │ │ jumpCoupon.vue // 跳转优惠券 36 | │ │ loading.vue // 页面初始化加载数据的动画组件 37 | │ │ qrcodePop.vue // 生成二维码弹框 38 | │ │ shopList.vue // 商品列表组件 39 | │ │ soldOut.vue // 请求数据错误展示占位图 40 | │ ├─mock 41 | │ │ index.js // 引入mockjs模拟数据 42 | │ └─pages 43 | │ ├─coupon 44 | │ │ coupon.html // 领券页面结构 45 | │ │ coupon.js // 领券页面入口文件,加载各种公用组件 46 | │ │ coupon.vue // 领券页 47 | │ ├─detail 48 | │ │ detail.html // 商品详情结构 49 | │ │ detail.js // 商品详情入口文件,加载各种公用组件 50 | │ │ detail.vue // 商品详情页 51 | │ ├─index 52 | │ │ index.html // 首页结构 53 | │ │ index.js // 首页入口文件,加载各种公用组件 54 | │ │ index.vue // 首页 55 | │ └─search 56 | │ search.html // 商品分类/关键词搜索页面结构 57 | │ search.js // 商品搜索入口文件,加载各种公用组件 58 | │ search.vue // 商品搜索页 59 | └─static // 存放静态资源文件夹 60 | └─img // 静态图片文件夹 61 | ``` 62 | 63 | 64 | # 技术栈 65 | * vue2.6 66 | * axios 67 | * webpack 68 | * ES6/7 69 | * flex 70 | * rem 71 | * mockjs 72 | 73 | # 功能模块 74 | * 首页轮播图 75 | * 商品列表 76 | * 返回顶部 77 | * 类目、模糊搜索 78 | * 二维码公众号 79 | * 详情页展示 80 | * 猜你喜欢 81 | * 查看、领取优惠券 82 | * 复制优惠券链接 83 | * 朋友圈分享提示 84 | 85 | # 下载安装依赖 86 | ``` 87 | git clone https://github.com/jackchen0120/woyouzhe.git 88 | cd woyouzhe 89 | npm install 或 yarn 90 | ``` 91 | 92 | ## 开发模式 93 | ``` 94 | npm run serve 95 | ``` 96 | 运行之后,访问地址:http://localhost:8090 97 | 98 | ## 生产环境打包 99 | ``` 100 | npm run build 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 | -------------------------------------------------------------------------------- /src/pages/search/search.vue: -------------------------------------------------------------------------------- 1 | 46 | 47 | 148 | 149 | 206 | 207 | -------------------------------------------------------------------------------- /src/pages/index/index.vue: -------------------------------------------------------------------------------- 1 | 68 | 69 | 184 | 185 | 263 | -------------------------------------------------------------------------------- /src/pages/coupon/coupon.vue: -------------------------------------------------------------------------------- 1 | 65 | 66 | 180 | 181 | 325 | -------------------------------------------------------------------------------- /src/components/shopList.vue: -------------------------------------------------------------------------------- 1 | 55 | 56 | 260 | 261 | 487 | -------------------------------------------------------------------------------- /src/pages/detail/detail.vue: -------------------------------------------------------------------------------- 1 | 104 | 105 | 267 | 268 | 522 | -------------------------------------------------------------------------------- /src/assets/js/fastclick.js: -------------------------------------------------------------------------------- 1 | ;(function () { 2 | 'use strict'; 3 | 4 | /** 5 | * @preserve FastClick: polyfill to remove click delays on browsers with touch UIs. 6 | * 7 | * @codingstandard ftlabs-jsv2 8 | * @copyright The Financial Times Limited [All Rights Reserved] 9 | * @license MIT License (see LICENSE.txt) 10 | */ 11 | 12 | /*jslint browser:true, node:true*/ 13 | /*global define, Event, Node*/ 14 | 15 | 16 | /** 17 | * Instantiate fast-clicking listeners on the specified layer. 18 | * 19 | * @constructor 20 | * @param {Element} layer The layer to listen on 21 | * @param {Object} [options={}] The options to override the defaults 22 | */ 23 | function FastClick(layer, options) { 24 | var oldOnClick; 25 | 26 | options = options || {}; 27 | 28 | /** 29 | * Whether a click is currently being tracked. 30 | * 31 | * @type boolean 32 | */ 33 | this.trackingClick = false; 34 | 35 | 36 | /** 37 | * Timestamp for when click tracking started. 38 | * 39 | * @type number 40 | */ 41 | this.trackingClickStart = 0; 42 | 43 | 44 | /** 45 | * The element being tracked for a click. 46 | * 47 | * @type EventTarget 48 | */ 49 | this.targetElement = null; 50 | 51 | 52 | /** 53 | * X-coordinate of touch start event. 54 | * 55 | * @type number 56 | */ 57 | this.touchStartX = 0; 58 | 59 | 60 | /** 61 | * Y-coordinate of touch start event. 62 | * 63 | * @type number 64 | */ 65 | this.touchStartY = 0; 66 | 67 | 68 | /** 69 | * ID of the last touch, retrieved from Touch.identifier. 70 | * 71 | * @type number 72 | */ 73 | this.lastTouchIdentifier = 0; 74 | 75 | 76 | /** 77 | * Touchmove boundary, beyond which a click will be cancelled. 78 | * 79 | * @type number 80 | */ 81 | this.touchBoundary = options.touchBoundary || 10; 82 | 83 | 84 | /** 85 | * The FastClick layer. 86 | * 87 | * @type Element 88 | */ 89 | this.layer = layer; 90 | 91 | /** 92 | * The minimum time between tap(touchstart and touchend) events 93 | * 94 | * @type number 95 | */ 96 | this.tapDelay = options.tapDelay || 200; 97 | 98 | /** 99 | * The maximum time for a tap 100 | * 101 | * @type number 102 | */ 103 | this.tapTimeout = options.tapTimeout || 700; 104 | 105 | if (FastClick.notNeeded(layer)) { 106 | return; 107 | } 108 | 109 | // Some old versions of Android don't have Function.prototype.bind 110 | function bind(method, context) { 111 | return function() { return method.apply(context, arguments); }; 112 | } 113 | 114 | 115 | var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel']; 116 | var context = this; 117 | for (var i = 0, l = methods.length; i < l; i++) { 118 | context[methods[i]] = bind(context[methods[i]], context); 119 | } 120 | 121 | // Set up event handlers as required 122 | if (deviceIsAndroid) { 123 | layer.addEventListener('mouseover', this.onMouse, true); 124 | layer.addEventListener('mousedown', this.onMouse, true); 125 | layer.addEventListener('mouseup', this.onMouse, true); 126 | } 127 | 128 | layer.addEventListener('click', this.onClick, true); 129 | layer.addEventListener('touchstart', this.onTouchStart, false); 130 | layer.addEventListener('touchmove', this.onTouchMove, false); 131 | layer.addEventListener('touchend', this.onTouchEnd, false); 132 | layer.addEventListener('touchcancel', this.onTouchCancel, false); 133 | 134 | // Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) 135 | // which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick 136 | // layer when they are cancelled. 137 | if (!Event.prototype.stopImmediatePropagation) { 138 | layer.removeEventListener = function(type, callback, capture) { 139 | var rmv = Node.prototype.removeEventListener; 140 | if (type === 'click') { 141 | rmv.call(layer, type, callback.hijacked || callback, capture); 142 | } else { 143 | rmv.call(layer, type, callback, capture); 144 | } 145 | }; 146 | 147 | layer.addEventListener = function(type, callback, capture) { 148 | var adv = Node.prototype.addEventListener; 149 | if (type === 'click') { 150 | adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) { 151 | if (!event.propagationStopped) { 152 | callback(event); 153 | } 154 | }), capture); 155 | } else { 156 | adv.call(layer, type, callback, capture); 157 | } 158 | }; 159 | } 160 | 161 | // If a handler is already declared in the element's onclick attribute, it will be fired before 162 | // FastClick's onClick handler. Fix this by pulling out the user-defined handler function and 163 | // adding it as listener. 164 | if (typeof layer.onclick === 'function') { 165 | 166 | // Android browser on at least 3.2 requires a new reference to the function in layer.onclick 167 | // - the old one won't work if passed to addEventListener directly. 168 | oldOnClick = layer.onclick; 169 | layer.addEventListener('click', function(event) { 170 | oldOnClick(event); 171 | }, false); 172 | layer.onclick = null; 173 | } 174 | } 175 | 176 | /** 177 | * Windows Phone 8.1 fakes user agent string to look like Android and iPhone. 178 | * 179 | * @type boolean 180 | */ 181 | var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0; 182 | 183 | /** 184 | * Android requires exceptions. 185 | * 186 | * @type boolean 187 | */ 188 | var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone; 189 | 190 | 191 | /** 192 | * iOS requires exceptions. 193 | * 194 | * @type boolean 195 | */ 196 | var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone; 197 | 198 | 199 | /** 200 | * iOS 4 requires an exception for select elements. 201 | * 202 | * @type boolean 203 | */ 204 | var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent); 205 | 206 | 207 | /** 208 | * iOS 6.0-7.* requires the target element to be manually derived 209 | * 210 | * @type boolean 211 | */ 212 | var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS [6-7]_\d/).test(navigator.userAgent); 213 | 214 | /** 215 | * BlackBerry requires exceptions. 216 | * 217 | * @type boolean 218 | */ 219 | var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0; 220 | 221 | /** 222 | * Determine whether a given element requires a native click. 223 | * 224 | * @param {EventTarget|Element} target Target DOM element 225 | * @returns {boolean} Returns true if the element needs a native click 226 | */ 227 | FastClick.prototype.needsClick = function(target) { 228 | switch (target.nodeName.toLowerCase()) { 229 | 230 | // Don't send a synthetic click to disabled inputs (issue #62) 231 | case 'button': 232 | case 'select': 233 | case 'textarea': 234 | if (target.disabled) { 235 | return true; 236 | } 237 | 238 | break; 239 | case 'input': 240 | 241 | // File inputs need real clicks on iOS 6 due to a browser bug (issue #68) 242 | if ((deviceIsIOS && target.type === 'file') || target.disabled) { 243 | return true; 244 | } 245 | 246 | break; 247 | case 'label': 248 | case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames 249 | case 'video': 250 | return true; 251 | } 252 | 253 | return (/\bneedsclick\b/).test(target.className); 254 | }; 255 | 256 | 257 | /** 258 | * Determine whether a given element requires a call to focus to simulate click into element. 259 | * 260 | * @param {EventTarget|Element} target Target DOM element 261 | * @returns {boolean} Returns true if the element requires a call to focus to simulate native click. 262 | */ 263 | FastClick.prototype.needsFocus = function(target) { 264 | switch (target.nodeName.toLowerCase()) { 265 | case 'textarea': 266 | return true; 267 | case 'select': 268 | return !deviceIsAndroid; 269 | case 'input': 270 | switch (target.type) { 271 | case 'button': 272 | case 'checkbox': 273 | case 'file': 274 | case 'image': 275 | case 'radio': 276 | case 'submit': 277 | return false; 278 | } 279 | 280 | // No point in attempting to focus disabled inputs 281 | return !target.disabled && !target.readOnly; 282 | default: 283 | return (/\bneedsfocus\b/).test(target.className); 284 | } 285 | }; 286 | 287 | 288 | /** 289 | * Send a click event to the specified element. 290 | * 291 | * @param {EventTarget|Element} targetElement 292 | * @param {Event} event 293 | */ 294 | FastClick.prototype.sendClick = function(targetElement, event) { 295 | var clickEvent, touch; 296 | 297 | // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24) 298 | if (document.activeElement && document.activeElement !== targetElement) { 299 | document.activeElement.blur(); 300 | } 301 | 302 | touch = event.changedTouches[0]; 303 | 304 | // Synthesise a click event, with an extra attribute so it can be tracked 305 | clickEvent = document.createEvent('MouseEvents'); 306 | clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); 307 | clickEvent.forwardedTouchEvent = true; 308 | targetElement.dispatchEvent(clickEvent); 309 | }; 310 | 311 | FastClick.prototype.determineEventType = function(targetElement) { 312 | 313 | //Issue #159: Android Chrome Select Box does not open with a synthetic click event 314 | if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') { 315 | return 'mousedown'; 316 | } 317 | 318 | return 'click'; 319 | }; 320 | 321 | 322 | /** 323 | * @param {EventTarget|Element} targetElement 324 | */ 325 | FastClick.prototype.focus = function(targetElement) { 326 | var length; 327 | 328 | // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. 329 | if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') { 330 | length = targetElement.value.length; 331 | targetElement.setSelectionRange(length, length); 332 | } else { 333 | targetElement.focus(); 334 | } 335 | }; 336 | 337 | 338 | /** 339 | * Check whether the given target element is a child of a scrollable layer and if so, set a flag on it. 340 | * 341 | * @param {EventTarget|Element} targetElement 342 | */ 343 | FastClick.prototype.updateScrollParent = function(targetElement) { 344 | var scrollParent, parentElement; 345 | 346 | scrollParent = targetElement.fastClickScrollParent; 347 | 348 | // Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the 349 | // target element was moved to another parent. 350 | if (!scrollParent || !scrollParent.contains(targetElement)) { 351 | parentElement = targetElement; 352 | do { 353 | if (parentElement.scrollHeight > parentElement.offsetHeight) { 354 | scrollParent = parentElement; 355 | targetElement.fastClickScrollParent = parentElement; 356 | break; 357 | } 358 | 359 | parentElement = parentElement.parentElement; 360 | } while (parentElement); 361 | } 362 | 363 | // Always update the scroll top tracker if possible. 364 | if (scrollParent) { 365 | scrollParent.fastClickLastScrollTop = scrollParent.scrollTop; 366 | } 367 | }; 368 | 369 | 370 | /** 371 | * @param {EventTarget} targetElement 372 | * @returns {Element|EventTarget} 373 | */ 374 | FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) { 375 | 376 | // On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node. 377 | if (eventTarget.nodeType === Node.TEXT_NODE) { 378 | return eventTarget.parentNode; 379 | } 380 | 381 | return eventTarget; 382 | }; 383 | 384 | 385 | /** 386 | * On touch start, record the position and scroll offset. 387 | * 388 | * @param {Event} event 389 | * @returns {boolean} 390 | */ 391 | FastClick.prototype.onTouchStart = function(event) { 392 | var targetElement, touch, selection; 393 | 394 | // Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111). 395 | if (event.targetTouches.length > 1) { 396 | return true; 397 | } 398 | 399 | targetElement = this.getTargetElementFromEventTarget(event.target); 400 | touch = event.targetTouches[0]; 401 | 402 | if (deviceIsIOS) { 403 | 404 | // Only trusted events will deselect text on iOS (issue #49) 405 | selection = window.getSelection(); 406 | if (selection.rangeCount && !selection.isCollapsed) { 407 | return true; 408 | } 409 | 410 | if (!deviceIsIOS4) { 411 | 412 | // Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23): 413 | // when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched 414 | // with the same identifier as the touch event that previously triggered the click that triggered the alert. 415 | // Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an 416 | // immediately preceeding touch event (issue #52), so this fix is unavailable on that platform. 417 | // Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string, 418 | // which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long, 419 | // random integers, it's safe to to continue if the identifier is 0 here. 420 | if (touch.identifier && touch.identifier === this.lastTouchIdentifier) { 421 | event.preventDefault(); 422 | return false; 423 | } 424 | 425 | this.lastTouchIdentifier = touch.identifier; 426 | 427 | // If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and: 428 | // 1) the user does a fling scroll on the scrollable layer 429 | // 2) the user stops the fling scroll with another tap 430 | // then the event.target of the last 'touchend' event will be the element that was under the user's finger 431 | // when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check 432 | // is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42). 433 | this.updateScrollParent(targetElement); 434 | } 435 | } 436 | 437 | this.trackingClick = true; 438 | this.trackingClickStart = event.timeStamp; 439 | this.targetElement = targetElement; 440 | 441 | this.touchStartX = touch.pageX; 442 | this.touchStartY = touch.pageY; 443 | 444 | // Prevent phantom clicks on fast double-tap (issue #36) 445 | if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { 446 | event.preventDefault(); 447 | } 448 | 449 | return true; 450 | }; 451 | 452 | 453 | /** 454 | * Based on a touchmove event object, check whether the touch has moved past a boundary since it started. 455 | * 456 | * @param {Event} event 457 | * @returns {boolean} 458 | */ 459 | FastClick.prototype.touchHasMoved = function(event) { 460 | var touch = event.changedTouches[0], boundary = this.touchBoundary; 461 | 462 | if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) { 463 | return true; 464 | } 465 | 466 | return false; 467 | }; 468 | 469 | 470 | /** 471 | * Update the last position. 472 | * 473 | * @param {Event} event 474 | * @returns {boolean} 475 | */ 476 | FastClick.prototype.onTouchMove = function(event) { 477 | if (!this.trackingClick) { 478 | return true; 479 | } 480 | 481 | // If the touch has moved, cancel the click tracking 482 | if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) { 483 | this.trackingClick = false; 484 | this.targetElement = null; 485 | } 486 | 487 | return true; 488 | }; 489 | 490 | 491 | /** 492 | * Attempt to find the labelled control for the given label element. 493 | * 494 | * @param {EventTarget|HTMLLabelElement} labelElement 495 | * @returns {Element|null} 496 | */ 497 | FastClick.prototype.findControl = function(labelElement) { 498 | 499 | // Fast path for newer browsers supporting the HTML5 control attribute 500 | if (labelElement.control !== undefined) { 501 | return labelElement.control; 502 | } 503 | 504 | // All browsers under test that support touch events also support the HTML5 htmlFor attribute 505 | if (labelElement.htmlFor) { 506 | return document.getElementById(labelElement.htmlFor); 507 | } 508 | 509 | // If no for attribute exists, attempt to retrieve the first labellable descendant element 510 | // the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label 511 | return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea'); 512 | }; 513 | 514 | 515 | /** 516 | * On touch end, determine whether to send a click event at once. 517 | * 518 | * @param {Event} event 519 | * @returns {boolean} 520 | */ 521 | FastClick.prototype.onTouchEnd = function(event) { 522 | var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement; 523 | 524 | if (!this.trackingClick) { 525 | return true; 526 | } 527 | 528 | // Prevent phantom clicks on fast double-tap (issue #36) 529 | if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { 530 | this.cancelNextClick = true; 531 | return true; 532 | } 533 | 534 | if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) { 535 | return true; 536 | } 537 | 538 | // Reset to prevent wrong click cancel on input (issue #156). 539 | this.cancelNextClick = false; 540 | 541 | this.lastClickTime = event.timeStamp; 542 | 543 | trackingClickStart = this.trackingClickStart; 544 | this.trackingClick = false; 545 | this.trackingClickStart = 0; 546 | 547 | // On some iOS devices, the targetElement supplied with the event is invalid if the layer 548 | // is performing a transition or scroll, and has to be re-detected manually. Note that 549 | // for this to function correctly, it must be called *after* the event target is checked! 550 | // See issue #57; also filed as rdar://13048589 . 551 | if (deviceIsIOSWithBadTarget) { 552 | touch = event.changedTouches[0]; 553 | 554 | // In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null 555 | targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement; 556 | targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent; 557 | } 558 | 559 | targetTagName = targetElement.tagName.toLowerCase(); 560 | if (targetTagName === 'label') { 561 | forElement = this.findControl(targetElement); 562 | if (forElement) { 563 | this.focus(targetElement); 564 | if (deviceIsAndroid) { 565 | return false; 566 | } 567 | 568 | targetElement = forElement; 569 | } 570 | } else if (this.needsFocus(targetElement)) { 571 | 572 | // Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through. 573 | // Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37). 574 | if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) { 575 | this.targetElement = null; 576 | return false; 577 | } 578 | 579 | this.focus(targetElement); 580 | this.sendClick(targetElement, event); 581 | 582 | // Select elements need the event to go through on iOS 4, otherwise the selector menu won't open. 583 | // Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others) 584 | if (!deviceIsIOS || targetTagName !== 'select') { 585 | this.targetElement = null; 586 | event.preventDefault(); 587 | } 588 | 589 | return false; 590 | } 591 | 592 | if (deviceIsIOS && !deviceIsIOS4) { 593 | 594 | // Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled 595 | // and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42). 596 | scrollParent = targetElement.fastClickScrollParent; 597 | if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) { 598 | return true; 599 | } 600 | } 601 | 602 | // Prevent the actual click from going though - unless the target node is marked as requiring 603 | // real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted. 604 | if (!this.needsClick(targetElement)) { 605 | event.preventDefault(); 606 | this.sendClick(targetElement, event); 607 | } 608 | 609 | return false; 610 | }; 611 | 612 | 613 | /** 614 | * On touch cancel, stop tracking the click. 615 | * 616 | * @returns {void} 617 | */ 618 | FastClick.prototype.onTouchCancel = function() { 619 | this.trackingClick = false; 620 | this.targetElement = null; 621 | }; 622 | 623 | 624 | /** 625 | * Determine mouse events which should be permitted. 626 | * 627 | * @param {Event} event 628 | * @returns {boolean} 629 | */ 630 | FastClick.prototype.onMouse = function(event) { 631 | 632 | // If a target element was never set (because a touch event was never fired) allow the event 633 | if (!this.targetElement) { 634 | return true; 635 | } 636 | 637 | if (event.forwardedTouchEvent) { 638 | return true; 639 | } 640 | 641 | // Programmatically generated events targeting a specific element should be permitted 642 | if (!event.cancelable) { 643 | return true; 644 | } 645 | 646 | // Derive and check the target element to see whether the mouse event needs to be permitted; 647 | // unless explicitly enabled, prevent non-touch click events from triggering actions, 648 | // to prevent ghost/doubleclicks. 649 | if (!this.needsClick(this.targetElement) || this.cancelNextClick) { 650 | 651 | // Prevent any user-added listeners declared on FastClick element from being fired. 652 | if (event.stopImmediatePropagation) { 653 | event.stopImmediatePropagation(); 654 | } else { 655 | 656 | // Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2) 657 | event.propagationStopped = true; 658 | } 659 | 660 | // Cancel the event 661 | event.stopPropagation(); 662 | event.preventDefault(); 663 | 664 | return false; 665 | } 666 | 667 | // If the mouse event is permitted, return true for the action to go through. 668 | return true; 669 | }; 670 | 671 | 672 | /** 673 | * On actual clicks, determine whether this is a touch-generated click, a click action occurring 674 | * naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or 675 | * an actual click which should be permitted. 676 | * 677 | * @param {Event} event 678 | * @returns {boolean} 679 | */ 680 | FastClick.prototype.onClick = function(event) { 681 | var permitted; 682 | 683 | // It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early. 684 | if (this.trackingClick) { 685 | this.targetElement = null; 686 | this.trackingClick = false; 687 | return true; 688 | } 689 | 690 | // Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target. 691 | if (event.target.type === 'submit' && event.detail === 0) { 692 | return true; 693 | } 694 | 695 | permitted = this.onMouse(event); 696 | 697 | // Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through. 698 | if (!permitted) { 699 | this.targetElement = null; 700 | } 701 | 702 | // If clicks are permitted, return true for the action to go through. 703 | return permitted; 704 | }; 705 | 706 | 707 | /** 708 | * Remove all FastClick's event listeners. 709 | * 710 | * @returns {void} 711 | */ 712 | FastClick.prototype.destroy = function() { 713 | var layer = this.layer; 714 | 715 | if (deviceIsAndroid) { 716 | layer.removeEventListener('mouseover', this.onMouse, true); 717 | layer.removeEventListener('mousedown', this.onMouse, true); 718 | layer.removeEventListener('mouseup', this.onMouse, true); 719 | } 720 | 721 | layer.removeEventListener('click', this.onClick, true); 722 | layer.removeEventListener('touchstart', this.onTouchStart, false); 723 | layer.removeEventListener('touchmove', this.onTouchMove, false); 724 | layer.removeEventListener('touchend', this.onTouchEnd, false); 725 | layer.removeEventListener('touchcancel', this.onTouchCancel, false); 726 | }; 727 | 728 | 729 | /** 730 | * Check whether FastClick is needed. 731 | * 732 | * @param {Element} layer The layer to listen on 733 | */ 734 | FastClick.notNeeded = function(layer) { 735 | var metaViewport; 736 | var chromeVersion; 737 | var blackberryVersion; 738 | var firefoxVersion; 739 | 740 | // Devices that don't support touch don't need FastClick 741 | if (typeof window.ontouchstart === 'undefined') { 742 | return true; 743 | } 744 | 745 | // Chrome version - zero for other browsers 746 | chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; 747 | 748 | if (chromeVersion) { 749 | 750 | if (deviceIsAndroid) { 751 | metaViewport = document.querySelector('meta[name=viewport]'); 752 | 753 | if (metaViewport) { 754 | // Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89) 755 | if (metaViewport.content.indexOf('user-scalable=no') !== -1) { 756 | return true; 757 | } 758 | // Chrome 32 and above with width=device-width or less don't need FastClick 759 | if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) { 760 | return true; 761 | } 762 | } 763 | 764 | // Chrome desktop doesn't need FastClick (issue #15) 765 | } else { 766 | return true; 767 | } 768 | } 769 | 770 | if (deviceIsBlackBerry10) { 771 | blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/); 772 | 773 | // BlackBerry 10.3+ does not require Fastclick library. 774 | // https://github.com/ftlabs/fastclick/issues/251 775 | if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) { 776 | metaViewport = document.querySelector('meta[name=viewport]'); 777 | 778 | if (metaViewport) { 779 | // user-scalable=no eliminates click delay. 780 | if (metaViewport.content.indexOf('user-scalable=no') !== -1) { 781 | return true; 782 | } 783 | // width=device-width (or less than device-width) eliminates click delay. 784 | if (document.documentElement.scrollWidth <= window.outerWidth) { 785 | return true; 786 | } 787 | } 788 | } 789 | } 790 | 791 | // IE10 with -ms-touch-action: none or manipulation, which disables double-tap-to-zoom (issue #97) 792 | if (layer.style.msTouchAction === 'none' || layer.style.touchAction === 'manipulation') { 793 | return true; 794 | } 795 | 796 | // Firefox version - zero for other browsers 797 | firefoxVersion = +(/Firefox\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1]; 798 | 799 | if (firefoxVersion >= 27) { 800 | // Firefox 27+ does not have tap delay if the content is not zoomable - https://bugzilla.mozilla.org/show_bug.cgi?id=922896 801 | 802 | metaViewport = document.querySelector('meta[name=viewport]'); 803 | if (metaViewport && (metaViewport.content.indexOf('user-scalable=no') !== -1 || document.documentElement.scrollWidth <= window.outerWidth)) { 804 | return true; 805 | } 806 | } 807 | 808 | // IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version 809 | // http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx 810 | if (layer.style.touchAction === 'none' || layer.style.touchAction === 'manipulation') { 811 | return true; 812 | } 813 | 814 | return false; 815 | }; 816 | 817 | 818 | /** 819 | * Factory method for creating a FastClick object 820 | * 821 | * @param {Element} layer The layer to listen on 822 | * @param {Object} [options={}] The options to override the defaults 823 | */ 824 | FastClick.attach = function(layer, options) { 825 | return new FastClick(layer, options); 826 | }; 827 | 828 | 829 | if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { 830 | 831 | // AMD. Register as an anonymous module. 832 | define(function() { 833 | return FastClick; 834 | }); 835 | } else if (typeof module !== 'undefined' && module.exports) { 836 | module.exports = FastClick.attach; 837 | module.exports.FastClick = FastClick; 838 | } else { 839 | window.FastClick = FastClick; 840 | } 841 | }()); 842 | --------------------------------------------------------------------------------