├── .editorconfig
├── .gitignore
├── .prettierrc
├── .vscode
├── launch.json
└── settings.json
├── .wepycache
├── .wepyignore
├── README.md
├── min.config.json
├── package.json
├── preview
├── preview.jpg
└── qq.jpg
├── project.config.json
├── src
├── apis
│ └── api.js
├── app.wpy
├── components
│ ├── Placeholder.wpy
│ ├── av_list.wpy
│ ├── bottom_load_more.wpy
│ ├── counter.wpy
│ ├── group.wpy
│ ├── groupitem.wpy
│ ├── list.wpy
│ ├── myheader.wpy
│ ├── panel.wpy
│ ├── swiper_img.wpy
│ └── wepy-list.wpy
├── config
│ └── default.js
├── index.template.html
├── mixins
│ ├── base.js
│ ├── http.js
│ ├── test.js
│ └── toast.js
├── pages
│ ├── home.wpy
│ ├── index.wpy
│ └── login.wpy
├── store
│ ├── actions
│ │ ├── counter.js
│ │ └── index.js
│ ├── index.js
│ ├── reducers
│ │ ├── counter.js
│ │ └── index.js
│ └── types
│ │ ├── counter.js
│ │ └── index.js
├── styles
│ ├── icon
│ │ ├── empty.png
│ │ ├── error.png
│ │ ├── loadding.gif
│ │ ├── logo-mobile.png
│ │ └── success.png
│ └── less
│ │ └── config.less
└── utils
│ ├── db.js
│ ├── md5.js
│ ├── tip.js
│ ├── util.js
│ └── wxRequest.js
└── wepy.config.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .DB_store
4 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // 使用 IntelliSense 了解相关属性。
3 | // 悬停以查看现有属性的描述。
4 | // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "node",
9 | "request": "launch",
10 | "name": "启动程序",
11 | "program": "${workspaceFolder}\\dist\\app.js"
12 | }
13 | ]
14 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | }
--------------------------------------------------------------------------------
/.wepycache:
--------------------------------------------------------------------------------
1 | {"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\wepy.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy-async-function\\index.js":1517302333000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy-redux\\lib\\index.js":1519786759000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\index.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\index.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-promise\\lib\\index.js":1458072063000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\app.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\page.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\component.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\event.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\base.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\util.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\mixin.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy-async-function\\global.js":1517302333000,"E:\\demo\\wepy\\mydemo\\node_modules\\promise-polyfill\\promise.js":1511627065000,"E:\\demo\\wepy\\mydemo\\node_modules\\regenerator-runtime\\runtime.js":1512675310000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy-redux\\lib\\connect\\index.js":1521081958000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy-redux\\lib\\store.js":1519786759000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy-redux\\lib\\helpers\\index.js":1519786759000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\createAction.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\handleAction.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\handleActions.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\combineActions.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\createActions.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\createStore.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\combineReducers.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\bindActionCreators.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\applyMiddleware.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\compose.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux\\lib\\utils\\warning.js":1499904787000,"E:\\demo\\wepy\\mydemo\\node_modules\\flux-standard-action\\lib\\index.js":1454443066000,"E:\\demo\\wepy\\mydemo\\node_modules\\wepy\\lib\\native.js":1519786782000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\identity.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isFunction.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isNull.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\invariant\\browser.js":1520965460000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isPlainObject.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isNil.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isUndefined.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\includes.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isMap.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\reduce-reducers\\lib\\index.js":1454442973000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\ownKeys.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\flattenUtils.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isString.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isEmpty.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\toString.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isSymbol.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\camelCase.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isArray.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\last.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\arrayToObject.js":1520420384000,"E:\\demo\\wepy\\mydemo\\node_modules\\symbol-observable\\lib\\index.js":1516988507000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash.isplainobject\\index.js":1435677344000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseGetTag.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isObject.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_getPrototype.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isObjectLike.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseIndexOf.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isArrayLike.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\toInteger.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\values.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseIsMap.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseUnary.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_nodeUtil.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\redux-actions\\lib\\hasGeneratorInterface.js":1520420385000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseKeys.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_getTag.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isArguments.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isBuffer.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_isPrototype.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isTypedArray.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseToString.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\symbol-observable\\lib\\ponyfill.js":1516988507000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash._basefor\\index.js":1452676959000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash.isarguments\\index.js":1471109416000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash.keysin\\index.js":1432605162000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_Symbol.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_getRawTag.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_objectToString.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_overArg.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseFindIndex.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseIsNaN.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_strictIndexOf.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\isLength.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\toFinite.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseValues.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\keys.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_freeGlobal.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_nativeKeys.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_DataView.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_Map.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_Promise.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_Set.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_WeakMap.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_toSource.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseIsArguments.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_root.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\stubFalse.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseIsTypedArray.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_arrayMap.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash.isarray\\index.js":1435677344000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\toNumber.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_arrayLikeKeys.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_getNative.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseTimes.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_isIndex.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_baseIsNative.js":1517704208000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_getValue.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_isMasked.js":1517704209000,"E:\\demo\\wepy\\mydemo\\node_modules\\lodash\\_coreJsData.js":1517704209000}
--------------------------------------------------------------------------------
/.wepyignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .DB_store
4 | *.wpy___jb_tmp___
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 仿B站微信小程序
2 |
3 | > 这是一个模仿BILIBILI网站风格的微信小程序
4 | > 目前小程序在积极开发阶段,代码结构以及API随时可能改变,稳定版本出来之后会整理一份API
5 |
6 | 此小程序采用wepy框架开发,同时我也编写了对应的后端程序来提供数据:[eggjs后端](https://github.com/GitHubAFeng/EggJsForAsBiLi)
7 | > 每次学习新技术时,都会惯例地模仿B站或网易云音乐做DEMO,例如:[非鱼 APP](https://github.com/GitHubAFeng/AFengAndroid)
8 |
9 | ## 预览
10 | > 部分页面
11 |
12 | 
13 |
14 |
15 | ## 联系我
16 | > 扫码加我QQ
17 |
18 | 
19 |
20 |
--------------------------------------------------------------------------------
/min.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilers": {
3 | "babel": {
4 | "sourceMaps": "inline",
5 | "presets": [
6 | "env"
7 | ],
8 | "plugins": [
9 | "syntax-export-extensions",
10 | "transform-class-properties",
11 | "transform-decorators-legacy",
12 | "transform-export-extensions"
13 | ]
14 | }
15 | },
16 | "npm": {
17 | "dest": "dist/packages"
18 | }
19 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mydemo",
3 | "version": "0.0.1",
4 | "description": "A WePY project",
5 | "main": "dist/app.js",
6 | "scripts": {
7 | "dev": "wepy build --watch",
8 | "build": "cross-env NODE_ENV=production wepy build --no-cache",
9 | "dev:web": "wepy build --output web",
10 | "clean": "find ./dist -maxdepth 1 -not -name 'project.config.json' -not -name 'dist' | xargs rm -rf",
11 | "test": "echo \"Error: no test specified\" && exit 1"
12 | },
13 | "wepy": {
14 | "module-a": false,
15 | "./src/components/list": "./src/components/wepy-list.wpy"
16 | },
17 | "author": "afeng",
18 | "license": "MIT",
19 | "dependencies": {
20 | "@minui/wxc-flex": "^1.0.5",
21 | "@minui/wxc-tab": "^1.0.7",
22 | "@minui/wxc-toast": "^1.0.8",
23 | "redux": "^3.7.2",
24 | "redux-actions": "^2.2.1",
25 | "redux-promise": "^0.5.3",
26 | "wepy": "^1.6.0",
27 | "wepy-async-function": "^1.4.4",
28 | "wepy-com-toast": "^1.0.2",
29 | "wepy-redux": "^1.5.3"
30 | },
31 | "devDependencies": {
32 | "babel-eslint": "^7.2.1",
33 | "babel-plugin-transform-class-properties": "^6.24.1",
34 | "babel-plugin-transform-decorators-legacy": "^1.3.4",
35 | "babel-plugin-transform-export-extensions": "^6.22.0",
36 | "babel-plugin-transform-object-rest-spread": "^6.26.0",
37 | "babel-preset-env": "^1.6.1",
38 | "cross-env": "^5.1.3",
39 | "wepy-compiler-babel": "^1.5.1",
40 | "wepy-compiler-less": "^1.3.10"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/preview/preview.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/preview/preview.jpg
--------------------------------------------------------------------------------
/preview/qq.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/preview/qq.jpg
--------------------------------------------------------------------------------
/project.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "description": "A WePY project",
3 | "setting": {
4 | "urlCheck": true,
5 | "es6": false,
6 | "postcss": false,
7 | "minified": false
8 | },
9 | "compileType": "miniprogram",
10 | "appid": "touristappid",
11 | "projectname": "mydemo",
12 | "miniprogramRoot": "./dist"
13 | }
14 |
--------------------------------------------------------------------------------
/src/apis/api.js:
--------------------------------------------------------------------------------
1 | import { wxRequest,request } from '../utils/wxRequest';
2 | import { domain } from '../config/default';
3 |
4 | const apitest = 'https://www.bilibili.com/index/ding.json'
5 |
6 | //查询列表
7 | // const getIndexList = (url) => request(domain + 'index/list');
8 | const getIndexList = (params) => wxRequest(params, domain + 'index/list');
9 | // const getIndexList = (params={}) => wxRequest(params, apitest);
10 |
11 |
12 | module.exports = {
13 | getIndexList,
14 |
15 | }
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/app.wpy:
--------------------------------------------------------------------------------
1 |
11 |
12 |
97 |
--------------------------------------------------------------------------------
/src/components/Placeholder.wpy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{message}}
5 |
6 |
7 |
21 |
46 |
--------------------------------------------------------------------------------
/src/components/av_list.wpy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | {{item.title}}
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
50 |
117 |
--------------------------------------------------------------------------------
/src/components/bottom_load_more.wpy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{message}}
5 |
6 |
7 |
21 |
39 |
--------------------------------------------------------------------------------
/src/components/counter.wpy:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | {{num}}
25 | {{stateNum}}
26 | {{asyncNum}}
27 |
28 |
29 |
88 |
--------------------------------------------------------------------------------
/src/components/group.wpy:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 | {{grouplist.id}}.
7 | {{grouplist.name}}
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
36 |
--------------------------------------------------------------------------------
/src/components/groupitem.wpy:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | --{{gitem.childid}}.
8 | {{gitem.childname}}
9 |
10 |
11 |
28 |
--------------------------------------------------------------------------------
/src/components/list.wpy:
--------------------------------------------------------------------------------
1 |
25 |
26 |
27 |
28 | 1
29 | 2
30 | 3
31 | 4
32 | 5
33 |
34 |
35 |
36 |
58 |
--------------------------------------------------------------------------------
/src/components/myheader.wpy:
--------------------------------------------------------------------------------
1 |
50 |
51 |
52 |
53 |
54 | {{title}}
55 |
56 |
57 | {{desc}}
58 |
59 |
60 |
61 |
62 |
77 |
--------------------------------------------------------------------------------
/src/components/panel.wpy:
--------------------------------------------------------------------------------
1 |
29 |
30 |
31 |
32 | Title
33 |
34 |
35 |
36 |
37 |
38 |
44 |
--------------------------------------------------------------------------------
/src/components/swiper_img.wpy:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
64 |
65 |
79 |
--------------------------------------------------------------------------------
/src/components/wepy-list.wpy:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | {{item.id}}: {{item.title}}
17 |
18 |
19 |
20 |
21 |
56 |
--------------------------------------------------------------------------------
/src/config/default.js:
--------------------------------------------------------------------------------
1 | //获取进程启动方式,在系统环境变量设置,临时也就是指 npm run dev 和 npm run build
2 | //暂时不知为什么在此获取不了process
3 | // const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev';
4 | const env = 'dev_egg';
5 | const domains = {
6 | dev_php: 'http://127.0.0.1:8096/',
7 | dev_egg: 'http://127.0.0.1:7001/'
8 | }
9 | export const domain = domains[env];
10 | export const version = '0.0.1';
11 | export default {
12 | env
13 | }
--------------------------------------------------------------------------------
/src/index.template.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 转 WEB DEMO
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/mixins/base.js:
--------------------------------------------------------------------------------
1 | import wepy from 'wepy'
2 |
3 | export default class baseMixin extends wepy.mixin {
4 | /**
5 | * [公共方法]
6 | * @param {[type]} item [description]
7 | * @return {Boolean} [description]
8 | */
9 | noop() {
10 | return null;
11 | }
12 | hasOwn(obj, type) {
13 | return Object.prototype.hasOwnProperty.call(obj, type);
14 | }
15 |
16 | /**
17 | * [isXXX 基础方法]
18 | * @param {[type]} item [description]
19 | * @return {Boolean} [description]
20 | */
21 | isUndefined(item) {
22 | return typeof item === 'undefined';
23 | }
24 | isDefined(item) {
25 | return !this.isUndefined(item);
26 | }
27 | isString(item) {
28 | return typeof item === 'string';
29 | }
30 | isNumber(item) {
31 | return typeof item === 'number';
32 | }
33 | isArray(item) {
34 | return Object.prototype.toString.apply(item) === '[object Array]';
35 | }
36 | isObject(item) {
37 | return typeof item === 'object' && !this.isArray(item);
38 | }
39 | isFunction(item) {
40 | return typeof item === 'function';
41 | }
42 |
43 | /**
44 | * [getXXX 增强方法]
45 | * @param {[type]} item [description]
46 | * @return {Boolean} [description]
47 | */
48 | getString(item, defaultStr) {
49 | if (this.isString(item)) return item.trim();
50 | if (this.isNumber(item)) return `${item}`.trim();
51 | return defaultStr || '';
52 | }
53 | getNumber(item, defaultNum) {
54 | var matches = this.getString(item).match(/\d+/);
55 | return this.isNumber(matches && +matches[0]) ? +matches[0] : defaultNum;
56 | }
57 | getArray(item, defaultArr) {
58 | return this.isArray(item) ? item : (defaultArr || []);
59 | }
60 | getObject(item, defaultObj) {
61 | return this.isObject(item) ? item : (defaultObj || {});
62 | }
63 | getFunction(item) {
64 | return this.isFunction(item) ? item : noop;
65 | }
66 |
67 | /**
68 | * [JSON方法]
69 | * @param {[type]} item [description]
70 | * @return {Boolean} [description]
71 | */
72 | $json(item) {
73 | let str = {type: Object.prototype.toString.call(item)}
74 | try {
75 | str = JSON.stringify(item)
76 | } catch (e) {
77 | str.error = e && e.stack || ''
78 | }
79 | return this.isString(str) ? str : this.$json(str)
80 | }
81 | $parse(item) {
82 | let obj = {type: Object.prototype.toString.call(item)}
83 | try {
84 | obj = JSON.parse(item)
85 | } catch (e) {
86 | obj.error = e && e.stack || ''
87 | }
88 | return this.isObject(obj) ? obj : this.$parse(obj)
89 | }
90 |
91 | /**
92 | * [功能方法]
93 | * @param {[type]} item [description]
94 | * @return {Boolean} [description]
95 | */
96 | isPhone(str) {
97 | return /^1\d{10}$/.test(str)
98 | }
99 | $alert(item = '标题', item2) {
100 | const param = this.isObject(item) ? Object.assign({
101 | // 首参数为obj
102 | title: 'title', content: 'content'
103 | }, item) : this.isString(item) ? this.isString(item2) ? {
104 | // 俩参数均为字符串
105 | title: item, content: item2
106 | } : {
107 | // 只有首参为字符串
108 | title: '', content: item
109 | } : {
110 | // 尝试转换字符串
111 | title: item.toString ? item.toString() : '参数异常'
112 | }
113 | wx.showModal(Object.assign({
114 | showCancel: false
115 | }, param))
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/mixins/http.js:
--------------------------------------------------------------------------------
1 | import wepy from 'wepy'
2 | import { domain } from '../config/default'
3 | import db from '../utils/db'
4 |
5 |
6 | export default class HttpMixin extends wepy.mixin{
7 |
8 | GetWithBind(url, params = {}, showToast = false, handler = {}) {
9 | return this.requestWithBind('GET', url, params, showToast, handler)
10 | }
11 |
12 | PostWithBind(url, params = {}, showToast = false, handler = {}) {
13 | return this.requestWithBind('POST', url, params, showToast, handler)
14 | }
15 |
16 | //验证登录,用户登录成功后会在cookie设置verify = 1
17 | async requestWithBind(method, url, params = {}, showToast = true, handler = {}) {
18 | if (db.Get('verify') === 0) {
19 | wepy.showModal({
20 | title: '登录',
21 | content: '账号或密码错误,是否跳转到登录页面?',
22 | success: function (res) {
23 | if (res.confirm) {
24 | wepy.navigateTo({
25 | url: '/pages/login'
26 | })
27 | } else if (res.cancel) {
28 | wepy.navigateBack({
29 | delta: 1
30 | })
31 | }
32 | }
33 | })
34 | throw '用户验证失败'
35 | } else {
36 | return this.request(method, url, params, showToast, handler)
37 | }
38 | }
39 |
40 | //请求时带上token , 而用户token在服务端响应设置在cookie ,后端获取在请求头token判断权限
41 | request(method, url, params = {}, showToast = false, handler = {}) {
42 | handler.url = domain + url
43 | handler.data = params
44 | handler.header = {
45 | 'Authorization': db.Get('token')
46 | }
47 | handler.method = method
48 | if (method === 'POST') {
49 | handler.header['content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
50 | }
51 |
52 | wepy.showLoading && wepy.showLoading({
53 | title: '加载中...'
54 | })
55 |
56 | return new Promise((resolve, reject) => {
57 | handler.success = res => {
58 | wepy.hideLoading && wepy.hideLoading();
59 | if (showToast) this.ShowToast(res.data.msg, 'success')
60 | resolve(res.data)
61 | }
62 | handler.fail = () => {
63 | wepy.hideLoading && wepy.hideLoading()
64 | if (showToast) this.ShowToast('网络错误', 'error', 3000)
65 | reject('Network request failed')
66 | }
67 | wepy.request(handler)
68 | })
69 | }
70 |
71 | // GET请求
72 | GET(url, params = {}, showToast = false, handler = {}) {
73 | return this.request('GET', url, params, showToast, handler)
74 | }
75 |
76 | // POST请求
77 | POST(url, params = {}, showToast = false, handler = {}) {
78 | return this.request('POST', url, params, showToast, handler)
79 | }
80 |
81 |
82 | }
83 |
84 |
85 |
--------------------------------------------------------------------------------
/src/mixins/test.js:
--------------------------------------------------------------------------------
1 | import wepy from 'wepy'
2 |
3 | export default class testMixin extends wepy.mixin {
4 | data = {
5 | mixin: 'This is mixin data.'
6 | }
7 | methods = {
8 | tap () {
9 | this.mixin = 'mixin data was changed'
10 | console.log('mixin method tap')
11 | }
12 | }
13 |
14 | onShow() {
15 | console.log('mixin onShow')
16 | }
17 |
18 | onLoad() {
19 | console.log('mixin onLoad')
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/mixins/toast.js:
--------------------------------------------------------------------------------
1 | import wepy from 'wepy'
2 |
3 | export default class ToastMixin extends wepy.mixin {
4 | ShowToast(msg, type = 'error', time = 2000) {
5 | wepy.showToast({
6 | title: msg,
7 | image: "../styles/icon/" + type + ".png",
8 | duration: time
9 | })
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/pages/home.wpy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | {{item.title}}
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
198 |
199 |
265 |
--------------------------------------------------------------------------------
/src/pages/index.wpy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
19 | {{tab.content}}
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
93 |
94 |
97 |
--------------------------------------------------------------------------------
/src/pages/login.wpy:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
21 |
22 |
70 |
71 |
--------------------------------------------------------------------------------
/src/store/actions/counter.js:
--------------------------------------------------------------------------------
1 | import { ASYNC_INCREMENT } from '../types/counter'
2 | import { createAction } from 'redux-actions'
3 |
4 | export const asyncInc = createAction(ASYNC_INCREMENT, () => {
5 | return new Promise(resolve => {
6 | setTimeout(() => {
7 | resolve(1)
8 | }, 1000)
9 | })
10 | })
--------------------------------------------------------------------------------
/src/store/actions/index.js:
--------------------------------------------------------------------------------
1 | export * from './counter'
--------------------------------------------------------------------------------
/src/store/index.js:
--------------------------------------------------------------------------------
1 | import { createStore, applyMiddleware } from 'redux'
2 | import promiseMiddleware from 'redux-promise'
3 | import rootReducer from './reducers'
4 |
5 | export default function configStore () {
6 | const store = createStore(rootReducer, applyMiddleware(promiseMiddleware))
7 | return store
8 | }
--------------------------------------------------------------------------------
/src/store/reducers/counter.js:
--------------------------------------------------------------------------------
1 | import { handleActions } from 'redux-actions'
2 | import { INCREMENT, DECREMENT, ASYNC_INCREMENT } from '../types/counter'
3 |
4 | export default handleActions({
5 | [INCREMENT] (state) {
6 | return {
7 | ...state,
8 | num: state.num + 1
9 | }
10 | },
11 | [DECREMENT] (state) {
12 | return {
13 | ...state,
14 | num: state.num - 1
15 | }
16 | },
17 | [ASYNC_INCREMENT] (state, action) {
18 | return {
19 | ...state,
20 | asyncNum: state.asyncNum + action.payload
21 | }
22 | }
23 | }, {
24 | num: 0,
25 | asyncNum: 0
26 | })
--------------------------------------------------------------------------------
/src/store/reducers/index.js:
--------------------------------------------------------------------------------
1 | import { combineReducers } from 'redux'
2 | import counter from './counter'
3 |
4 | export default combineReducers({
5 | counter
6 | })
--------------------------------------------------------------------------------
/src/store/types/counter.js:
--------------------------------------------------------------------------------
1 | export const INCREMENT = 'INCREMENT'
2 |
3 | export const DECREMENT = 'DECREMENT'
4 |
5 | export const ASYNC_INCREMENT = 'ASYNC_INCREMENT'
--------------------------------------------------------------------------------
/src/store/types/index.js:
--------------------------------------------------------------------------------
1 | export * from './counter'
--------------------------------------------------------------------------------
/src/styles/icon/empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/src/styles/icon/empty.png
--------------------------------------------------------------------------------
/src/styles/icon/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/src/styles/icon/error.png
--------------------------------------------------------------------------------
/src/styles/icon/loadding.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/src/styles/icon/loadding.gif
--------------------------------------------------------------------------------
/src/styles/icon/logo-mobile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/src/styles/icon/logo-mobile.png
--------------------------------------------------------------------------------
/src/styles/icon/success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GitHubAFeng/AsBiLi/032453917a9e077c5e7b42e53df9fea0d888a4f5/src/styles/icon/success.png
--------------------------------------------------------------------------------
/src/styles/less/config.less:
--------------------------------------------------------------------------------
1 | @base-color: #f06292;
2 | @white: #fff;
3 | @bg-color: #f8f8f5;
4 | @black: #555;
5 |
6 | //#b92c18 锦绣红
7 | //#87a1a1 优雅灰
8 |
9 |
10 | //阿里图标库,把ttf文件转换为base64位图后再使用,因为不允许外链
11 | @font-face {
12 | font-family: 'iconfont';
13 | src: url(data:font/truetype;charset=utf-8;base64,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) format('truetype');
14 | font-weight: normal;
15 | font-style: normal;
16 | }
17 |
18 |
19 | .iconfont {
20 | font-family:"iconfont" !important;
21 | font-size:16px;
22 | font-style:normal;
23 | -webkit-font-smoothing: antialiased;
24 | -moz-osx-font-smoothing: grayscale;
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/src/utils/db.js:
--------------------------------------------------------------------------------
1 |
2 | import {env} from '../config/default'
3 | let prefix = ""; //前缀
4 | if (env == "prod") {
5 | prefix = ""
6 | }
7 |
8 | const Set = (key, value) => {
9 | wx.setStorageSync(prefix + key, value)
10 | }
11 |
12 | const Get = (key) => {
13 | return wx.getStorageSync(prefix + key)
14 | }
15 |
16 | module.exports = {
17 | Set,
18 | Get
19 | }
20 |
--------------------------------------------------------------------------------
/src/utils/md5.js:
--------------------------------------------------------------------------------
1 | var hexcase=0;var b64pad="";var chrsz=8;function hex_md5(s){return binl2hex(core_md5(str2binl(s),s.length*chrsz))}function b64_md5(s){return binl2b64(core_md5(str2binl(s),s.length*chrsz))}function str_md5(s){return binl2str(core_md5(str2binl(s),s.length*chrsz))}function hex_hmac_md5(key,data){return binl2hex(core_hmac_md5(key,data))}function b64_hmac_md5(key,data){return binl2b64(core_hmac_md5(key,data))}function str_hmac_md5(key,data){return binl2str(core_hmac_md5(key,data))}function md5_vm_test(){return hex_md5("abc")=="900150983cd24fb0d6963f7d28e17f72"}function core_md5(x,len){x[len>>5]|=0x80<<((len)%32);x[(((len+64)>>>9)<<4)+14]=len;var a=1732584193;var b=-271733879;var c=-1732584194;var d=271733878;for(var i=0;i16)bkey=core_md5(bkey,key.length*chrsz);var ipad=Array(16),opad=Array(16);for(var i=0;i<16;i++){ipad[i]=bkey[i]^0x36363636;opad[i]=bkey[i]^0x5C5C5C5C}var hash=core_md5(ipad.concat(str2binl(data)),512+data.length*chrsz);return core_md5(opad.concat(hash),512+128)}function safe_add(x,y){var lsw=(x&0xFFFF)+(y&0xFFFF);var msw=(x>>16)+(y>>16)+(lsw>>16);return(msw<<16)|(lsw&0xFFFF)}function bit_rol(num,cnt){return(num<>>(32-cnt))}function str2binl(str){var bin=Array();var mask=(1<>5]|=(str.charCodeAt(i/chrsz)&mask)<<(i%32);return bin}function binl2str(bin){var str="";var mask=(1<>5]>>>(i%32))&mask);return str}function binl2hex(binarray){var hex_tab=hexcase?"0123456789ABCDEF":"0123456789abcdef";var str="";for(var i=0;i>2]>>((i%4)*8+4))&0xF)+hex_tab.charAt((binarray[i>>2]>>((i%4)*8))&0xF)}return str}function binl2b64(binarray){var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var str="";for(var i=0;i>2]>>8*(i%4))&0xFF)<<16)|(((binarray[i+1>>2]>>8*((i+1)%4))&0xFF)<<8)|((binarray[i+2>>2]>>8*((i+2)%4))&0xFF);for(var j=0;j<4;j++){if(i*8+j*6>binarray.length*32)str+=b64pad;else str+=tab.charAt((triplet>>6*(3-j))&0x3F)}}return str}module.exports={hex_md5:hex_md5}
--------------------------------------------------------------------------------
/src/utils/tip.js:
--------------------------------------------------------------------------------
1 | /**
2 | * 提示与加载工具类
3 | */
4 | export default class Tips {
5 | constructor() {
6 | this.isLoading = false;
7 | }
8 | /**
9 | * 弹出提示框
10 | */
11 |
12 | static success(title, duration = 500) {
13 | setTimeout(() => {
14 | wx.showToast({
15 | title: title,
16 | icon: "success",
17 | mask: true,
18 | duration: duration
19 | });
20 | }, 300);
21 | if (duration > 0) {
22 | return new Promise((resolve, reject) => {
23 | setTimeout(() => {
24 | resolve();
25 | }, duration);
26 | });
27 | }
28 | }
29 |
30 | /**
31 | * 弹出确认窗口
32 | */
33 | static confirm(text, payload = {}, title = "提示") {
34 | return new Promise((resolve, reject) => {
35 | wx.showModal({
36 | title: title,
37 | content: text,
38 | showCancel: true,
39 | success: res => {
40 | if (res.confirm) {
41 | resolve(payload);
42 | } else if (res.cancel) {
43 | reject(payload);
44 | }
45 | },
46 | fail: res => {
47 | reject(payload);
48 | }
49 | });
50 | });
51 | }
52 |
53 | static toast(title, onHide, icon = "success") {
54 | setTimeout(() => {
55 | wx.showToast({
56 | title: title,
57 | icon: icon,
58 | mask: true,
59 | duration: 500
60 | });
61 | }, 300);
62 |
63 | // 隐藏结束回调
64 | if (onHide) {
65 | setTimeout(() => {
66 | onHide();
67 | }, 500);
68 | }
69 | }
70 |
71 | /**
72 | * 警告框
73 | */
74 | static alert(title) {
75 | wx.showToast({
76 | title: title,
77 | image: "../images/alert.png",
78 | mask: true,
79 | duration: 1500
80 | });
81 | }
82 |
83 | /**
84 | * 错误框
85 | */
86 |
87 | static error(title, onHide) {
88 | wx.showToast({
89 | title: title,
90 | image: "../images/error.png",
91 | mask: true,
92 | duration: 500
93 | });
94 | // 隐藏结束回调
95 | if (onHide) {
96 | setTimeout(() => {
97 | onHide();
98 | }, 500);
99 | }
100 | }
101 |
102 | /**
103 | * 弹出加载提示
104 | */
105 | static loading(title = "加载中") {
106 | if (Tips.isLoading) {
107 | return;
108 | }
109 | Tips.isLoading = true;
110 | wx.showLoading({
111 | title: title,
112 | mask: true
113 | });
114 | }
115 |
116 | /**
117 | * 加载完毕
118 | */
119 | static loaded() {
120 | if (Tips.isLoading) {
121 | Tips.isLoading = false;
122 | wx.hideLoading();
123 | }
124 | }
125 |
126 | static share(title, url, desc) {
127 | return {
128 | title: title,
129 | path: url,
130 | desc: desc,
131 | success: function(res) {
132 | Tips.toast("分享成功");
133 | }
134 | };
135 | }
136 | }
137 |
138 | /**
139 | * 静态变量,是否加载中
140 | */
141 | Tips.isLoading = false;
142 |
--------------------------------------------------------------------------------
/src/utils/util.js:
--------------------------------------------------------------------------------
1 | function getCurrentTime() {
2 | var keep = '';
3 | var date = new Date();
4 | var y = date.getFullYear();
5 | var m = date.getMonth() + 1;
6 | m = m < 10 ? '0' + m : m;
7 | var d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
8 | var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
9 | var f = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
10 | var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
11 | var rand = Math.round(Math.random() * 899 + 100);
12 | keep = y + '' + m + '' + d + '' + h + '' + f + '' + s;
13 | return keep; //20160614134947
14 | }
15 |
16 | function objLength(input) {
17 | var type = toString(input);
18 | var length = 0;
19 | if (type != "[object Object]") {
20 | //throw "输入必须为对象{}!"
21 | } else {
22 | for (var key in input) {
23 | if (key != "number") {
24 | length++;
25 | }
26 |
27 | }
28 | }
29 | return length;
30 | }
31 | //验证是否是手机号码
32 | function vailPhone(number) {
33 | let flag = false;
34 | let myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
35 | if (number.length != 11) {
36 | flag = flag;
37 | }else if (!myreg.test(number)) {
38 | flag = flag;
39 | }else{
40 | flag = true;
41 | }
42 | return flag;
43 | }
44 | //验证是否西班牙手机(6开头 9位数)
45 | function ifSpanish(number) {
46 | let flag = false;
47 | let myreg = /^([6|7|9]{1}(\d+){8})$/;
48 | if (number.length != 9) {
49 | flag = flag;
50 | } else if (!myreg.test(number)) {
51 | flag = flag;
52 | } else {
53 | flag = true;
54 | }
55 | return flag;
56 | }
57 | //浮点型除法
58 | function div(a, b) {
59 | var c, d, e = 0,
60 | f = 0;
61 | try {
62 | e = a.toString().split(".")[1].length;
63 | } catch (g) { }
64 | try {
65 | f = b.toString().split(".")[1].length;
66 | } catch (g) { }
67 | return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), mul(c / d, Math.pow(10, f - e));
68 | }
69 | //浮点型加法函数
70 | function accAdd(arg1, arg2) {
71 | var r1, r2, m;
72 | try {
73 | r1 = arg1.toString().split(".")[1].length;
74 | } catch (e) {
75 | r1 = 0;
76 | }
77 | try {
78 | r2 = arg2.toString().split(".")[1].length;
79 | } catch (e) {
80 | r2 = 0;
81 | }
82 | m = Math.pow(10, Math.max(r1, r2));
83 | return ((arg1 * m + arg2 * m) / m).toFixed(2);
84 | }
85 | //浮点型乘法
86 | function mul(a, b) {
87 | var c = 0,
88 | d = a.toString(),
89 | e = b.toString();
90 | try {
91 | c += d.split(".")[1].length;
92 | } catch (f) { }
93 | try {
94 | c += e.split(".")[1].length;
95 | } catch (f) { }
96 | return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
97 | }
98 |
99 | // 遍历对象属性和值
100 | function displayProp(obj) {
101 | var names = "";
102 | for (var name in obj) {
103 | names += name + obj[name];
104 | }
105 | return names;
106 | }
107 | // 去除字符串所有空格
108 | function sTrim(text) {
109 | return text.replace(/\s/ig, '')
110 | }
111 | //去除所有:
112 | function replaceMaohao(txt) {
113 | return txt.replace(/\:/ig, '')
114 | }
115 | //转换星星分数
116 | function convertStarArray(score) {
117 | //1 全星,0 空星,2半星
118 | var arr = []
119 | for (var i = 1; i <= 5; i++) {
120 | if (score >= i) {
121 | arr.push(1)
122 | } else if (score > i-1 && score < i + 1) {
123 | arr.push(2)
124 | } else {
125 | arr.push(0)
126 | }
127 | }
128 | return arr
129 | }
130 | module.exports = {
131 | getCurrentTime: getCurrentTime,
132 | objLength: objLength,
133 | displayProp: displayProp,
134 | sTrim: sTrim,
135 | replaceMaohao: replaceMaohao,
136 | vailPhone: vailPhone,
137 | ifSpanish: ifSpanish,
138 | div: div,
139 | mul: mul,
140 | accAdd: accAdd,
141 | convertStarArray: convertStarArray
142 | }
--------------------------------------------------------------------------------
/src/utils/wxRequest.js:
--------------------------------------------------------------------------------
1 | import wepy from 'wepy';
2 | import util from './util';
3 | import md5 from './md5';
4 | import tip from './tip';
5 |
6 | const API_SECRET_KEY = 'afeng'
7 | const TIMESTAMP = util.getCurrentTime()
8 | const SIGN = md5.hex_md5((TIMESTAMP + API_SECRET_KEY).toLowerCase())
9 |
10 | const wxRequest = async(params = {}, url) => {
11 | tip.loading();
12 | let data = params.query || {};
13 | data.sign = SIGN;
14 | data.time = TIMESTAMP;
15 | let res = await wepy.request({
16 | url: url,
17 | method: params.method || 'GET',
18 | data: data,
19 | header: { 'Content-Type': 'application/json' },
20 | });
21 | tip.loaded();
22 | return res.data;
23 | };
24 |
25 |
26 | const request = (url ,method='GET', params = {}, handler = {}) => {
27 | handler.url = url;
28 | handler.data = params;
29 | handler.header = {
30 | 'content-type': 'application/json'
31 | }
32 | handler.method = method;
33 | if (method === 'POST') {
34 | handler.header['content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
35 | }
36 |
37 | return new Promise((resolve, reject) => {
38 | handler.success = res => {
39 | resolve(res.data)
40 | }
41 | handler.fail = () => {
42 | reject('Network request failed')
43 | }
44 | wepy.request(handler)
45 | })
46 | }
47 |
48 |
49 | module.exports = {
50 | wxRequest,
51 | request
52 | }
53 |
--------------------------------------------------------------------------------
/wepy.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | var prod = process.env.NODE_ENV === 'production';
3 |
4 | module.exports = {
5 | wpyExt: '.wpy',
6 | eslint: false,
7 | cliLogs: !prod,
8 | build: {
9 | web: {
10 | htmlTemplate: path.join('src', 'index.template.html'),
11 | htmlOutput: path.join('web', 'index.html'),
12 | jsOutput: path.join('web', 'index.js')
13 | }
14 | },
15 | resolve: {
16 | alias: {
17 | counter: path.join(__dirname, 'src/components/counter'),
18 | '@': path.join(__dirname, 'src')
19 | },
20 | aliasFields: ['wepy'],
21 | modules: ['node_modules']
22 | },
23 | compilers: {
24 | less: {
25 | compress: prod
26 | },
27 | /*sass: {
28 | outputStyle: 'compressed'
29 | },*/
30 | babel: {
31 | sourceMap: true,
32 | presets: [
33 | 'env'
34 | ],
35 | plugins: [
36 | 'transform-class-properties',
37 | 'transform-decorators-legacy',
38 | 'transform-object-rest-spread',
39 | 'transform-export-extensions',
40 | ]
41 | }
42 | },
43 | plugins: {
44 | },
45 | appConfig: {
46 | noPromiseAPI: ['createSelectorQuery']
47 | }
48 | }
49 |
50 | if (prod) {
51 |
52 | // 压缩sass
53 | // module.exports.compilers['sass'] = {outputStyle: 'compressed'}
54 |
55 | // 压缩js
56 | module.exports.plugins = {
57 | uglifyjs: {
58 | filter: /\.js$/,
59 | config: {
60 | }
61 | },
62 | imagemin: {
63 | filter: /\.(jpg|png|jpeg)$/,
64 | config: {
65 | jpg: {
66 | quality: 80
67 | },
68 | png: {
69 | quality: 80
70 | }
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------