From 379d337ddede7740344ccb57f06e6c04a1717a43 Mon Sep 17 00:00:00 2001 From: Maoqiang Zheng Date: Thu, 29 Nov 2018 17:35:49 +0800 Subject: [PATCH] first commit --- .editorconfig | 12 + .eslintrc | 8 + .gitignore | 5 + .npmrc | 4 + config/dev.js | 9 + config/index.js | 79 +++++++ config/prod.js | 9 + package.json | 57 +++++ project.config.json | 13 ++ src/actions/counter.js | 24 ++ src/app.js | 53 +++++ src/app.scss | 0 src/component/recommendShop/recommendShop.js | 65 ++++++ .../recommendShop/recommondShop.scss | 53 +++++ src/constants/counter.js | 2 + src/index.html | 19 ++ src/pages/home/home.js | 216 ++++++++++++++++++ src/pages/home/home.scss | 33 +++ src/pages/index/index.js | 60 +++++ src/pages/index/index.scss | 0 src/reducers/counter.js | 22 ++ src/reducers/index.js | 6 + src/store/index.js | 28 +++ 23 files changed, 777 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 config/dev.js create mode 100644 config/index.js create mode 100644 config/prod.js create mode 100644 package.json create mode 100644 project.config.json create mode 100644 src/actions/counter.js create mode 100644 src/app.js create mode 100644 src/app.scss create mode 100644 src/component/recommendShop/recommendShop.js create mode 100644 src/component/recommendShop/recommondShop.scss create mode 100644 src/constants/counter.js create mode 100644 src/index.html create mode 100644 src/pages/home/home.js create mode 100644 src/pages/home/home.scss create mode 100644 src/pages/index/index.js create mode 100644 src/pages/index/index.scss create mode 100644 src/reducers/counter.js create mode 100644 src/reducers/index.js create mode 100644 src/store/index.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5760be5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..b4afb92 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,8 @@ +{ + "extends": ["taro"], + "rules": { + "no-unused-vars": ["error", { "varsIgnorePattern": "Taro" }], + "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".tsx"] }] + }, + "parser": "babel-eslint" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acb9cf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +dist/ +.temp/ +.rn_temp/ +node_modules/ +.DS_Store diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..fa91a18 --- /dev/null +++ b/.npmrc @@ -0,0 +1,4 @@ +registry=https://r.cnpmjs.org +disturl=https://r.cnpmjs.org/node +sass_binary_site=https://r.cnpmjs.org/node-sass/ +fse_binary_host_mirror=https://r.cnpmjs.org/fsevents diff --git a/config/dev.js b/config/dev.js new file mode 100644 index 0000000..0377634 --- /dev/null +++ b/config/dev.js @@ -0,0 +1,9 @@ +module.exports = { + env: { + NODE_ENV: '"development"' + }, + defineConstants: { + }, + weapp: {}, + h5: {} +} diff --git a/config/index.js b/config/index.js new file mode 100644 index 0000000..bd8e041 --- /dev/null +++ b/config/index.js @@ -0,0 +1,79 @@ +const config = { + projectName: 'cf-wx-app', + date: '2018-11-29', + designWidth: 750, + deviceRatio: { + '640': 2.34 / 2, + '750': 1, + '828': 1.81 / 2 + }, + sourceRoot: 'src', + outputRoot: 'dist', + plugins: { + babel: { + sourceMap: true, + presets: [ + 'env' + ], + plugins: [ + 'transform-decorators-legacy', + 'transform-class-properties', + 'transform-object-rest-spread' + ] + } + }, + defineConstants: { + }, + copy: { + patterns: [ + ], + options: { + } + }, + weapp: { + module: { + postcss: { + autoprefixer: { + enable: true, + config: { + browsers: [ + 'last 3 versions', + 'Android >= 4.1', + 'ios >= 8' + ] + } + }, + pxtransform: { + enable: true, + config: { + + } + }, + url: { + enable: true, + config: { + limit: 10240 // 设定转换尺寸上限 + } + } + } + } + }, + h5: { + publicPath: '/', + staticDirectory: 'static', + module: { + postcss: { + autoprefixer: { + enable: true + } + } + } + } +} + +module.exports = function (merge) { + if (process.env.NODE_ENV === 'development') { + return merge({}, config, require('./dev')) + } + return merge({}, config, require('./prod')) +} diff --git a/config/prod.js b/config/prod.js new file mode 100644 index 0000000..3910355 --- /dev/null +++ b/config/prod.js @@ -0,0 +1,9 @@ +module.exports = { + env: { + NODE_ENV: '"production"' + }, + defineConstants: { + }, + weapp: {}, + h5: {} +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..d02e40a --- /dev/null +++ b/package.json @@ -0,0 +1,57 @@ +{ + "name": "cf-wx-app", + "version": "1.0.0", + "private": true, + "description": "cf-wx-app", + "scripts": { + "build:weapp": "taro build --type weapp", + "build:swan": "taro build --type swan", + "build:alipay": "taro build --type alipay", + "build:h5": "taro build --type h5", + "build:rn": "taro build --type rn", + "dev:weapp": "npm run build:weapp -- --watch", + "dev:swan": "npm run build:swan -- --watch", + "dev:alipay": "npm run build:alipay -- --watch", + "dev:h5": "npm run build:h5 -- --watch", + "dev:rn": "npm run build:rn -- --watch" + }, + "author": "", + "license": "MIT", + "dependencies": { + "@tarojs/async-await": "^1.2.0-beta.3", + "@tarojs/components": "^1.2.0-beta.3", + "@tarojs/redux": "^1.2.0-beta.3", + "@tarojs/redux-h5": "^1.2.0-beta.3", + "@tarojs/router": "^1.2.0-beta.3", + "@tarojs/taro": "^1.2.0-beta.3", + "@tarojs/taro-alipay": "^1.2.0-beta.3", + "@tarojs/taro-h5": "^1.2.0-beta.3", + "@tarojs/taro-swan": "^1.2.0-beta.3", + "@tarojs/taro-weapp": "^1.2.0-beta.3", + "nervjs": "^1.3.9", + "nerv-devtools": "^1.3.9", + "redux": "^4.0.0", + "redux-logger": "^3.0.6", + "redux-thunk": "^2.3.0" + }, + "devDependencies": { + "@types/react": "^16.4.8", + "@types/webpack-env": "^1.13.6", + "@tarojs/plugin-babel": "^1.2.0-beta.3", + "@tarojs/plugin-csso": "^1.2.0-beta.3", + "@tarojs/plugin-sass": "^1.2.0-beta.3", + "@tarojs/plugin-uglifyjs": "^1.2.0-beta.3", + "@tarojs/webpack-runner": "^1.2.0-beta.3", + "babel-plugin-transform-class-properties": "^6.24.1", + "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-plugin-transform-jsx-stylesheet": "^0.6.5", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-preset-env": "^1.6.1", + "babel-eslint": "^8.2.3", + "eslint": "^4.19.1", + "eslint-config-taro": "^1.2.0-beta.3", + "eslint-plugin-react": "^7.8.2", + "eslint-plugin-import": "^2.12.0", + "eslint-plugin-taro": "^1.2.0-beta.3" + } +} diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..9cc5472 --- /dev/null +++ b/project.config.json @@ -0,0 +1,13 @@ +{ + "miniprogramRoot": "./dist", + "projectname": "cf-wx-app", + "description": "cf-wx-app", + "appid": "touristappid", + "setting": { + "urlCheck": true, + "es6": false, + "postcss": false, + "minified": false + }, + "compileType": "miniprogram" +} diff --git a/src/actions/counter.js b/src/actions/counter.js new file mode 100644 index 0000000..7147eaa --- /dev/null +++ b/src/actions/counter.js @@ -0,0 +1,24 @@ +import { + ADD, + MINUS +} from '../constants/counter' + +export const add = () => { + return { + type: ADD + } +} +export const minus = () => { + return { + type: MINUS + } +} + +// 异步的action +export function asyncAdd () { + return dispatch => { + setTimeout(() => { + dispatch(add()) + }, 2000) + } +} diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..8e116fe --- /dev/null +++ b/src/app.js @@ -0,0 +1,53 @@ +import '@tarojs/async-await' +import Taro, { Component } from '@tarojs/taro' +import { Provider } from '@tarojs/redux' +import Index from './pages/index' +import configStore from './store' + +import './app.scss' + +// 如果需要在 h5 环境中开启 React Devtools +// 取消以下注释: +// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5') { +// require('nerv-devtools') +// } + +const store = configStore() + +class App extends Component { + + config = { + pages: [ + 'pages/index/index', + 'pages/home/home', + ], + window: { + backgroundTextStyle: 'light', + navigationBarBackgroundColor: '#fff', + navigationBarTitleText: 'WeChat', + navigationBarTextStyle: 'black' + } + } + + componentDidMount () {} + + componentDidShow () {} + + componentDidHide () {} + + componentCatchError () {} + + componentDidCatchError () {} + + // 在 App 类中的 render() 函数没有实际作用 + // 请勿修改此函数 + render () { + return ( + + + + ) + } +} + +Taro.render(, document.getElementById('app')) diff --git a/src/app.scss b/src/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/component/recommendShop/recommendShop.js b/src/component/recommendShop/recommendShop.js new file mode 100644 index 0000000..7b15255 --- /dev/null +++ b/src/component/recommendShop/recommendShop.js @@ -0,0 +1,65 @@ +import Taro, { Component } from '@tarojs/taro' +import { View, Button, Text,Image } from '@tarojs/components' + + +import './recommondShop.scss' + + + +class recommondShop extends Component { + + config = { + navigationBarTitleText: 'recommondShop' + } + + componentWillReceiveProps(nextProps) { + console.log(this.props, nextProps) + } + + componentWillUnmount() { } + + componentDidShow() { } + + componentDidHide() { } + + render() { + + const title = this.props.shop.shop_name + const imgUrl = 'http://192.168.1.230/' + this.props.shop.shop_logo + const price = this.props.shop.goods[0].goods_price + const ProductName = this.props.shop.goods_name + const address = this.props.shop.shop_address + const distance = this.props.shop.distance + return ( + + + + {title} + + + + + + + + + + + 商品:{ProductName} + 价格:{price} + + + + + {address} + {distance} + + + + ) + } +} + +export default recommondShop diff --git a/src/component/recommendShop/recommondShop.scss b/src/component/recommendShop/recommondShop.scss new file mode 100644 index 0000000..e551a2a --- /dev/null +++ b/src/component/recommendShop/recommondShop.scss @@ -0,0 +1,53 @@ +.shop-list-box{ + border: 1px solid #ddd; + border-radius: 3px; + box-shadow: 0 5px 5px #ddd; + margin-bottom: 10px; + .header{ + border-bottom:gray solid 1px; + display: flex; + .title{ + width: 50%; + color: #333; + font-weight: bold; + + } + .ask-button{ + width: 50%; + button{ + background-color: #337ab7; + height: 36px; + width:24px; + color:white + } + } + } + .body{ + border-bottom:gray solid 1px; + display: flex; + font-size: 35px; + .shop-img{ + padding: 20px; + Image{ + height: 200px; + width: 200px; + } + } + .details{ + View{ + margin-top: 20px; + } + } + } + .footer{ + display: flex; + .distance{ + width: 50%; + font-size: 30px + } + .address{ + width:50%; + font-size: 30px + } + } +} \ No newline at end of file diff --git a/src/constants/counter.js b/src/constants/counter.js new file mode 100644 index 0000000..145d68f --- /dev/null +++ b/src/constants/counter.js @@ -0,0 +1,2 @@ +export const ADD = 'ADD' +export const MINUS = 'MINUS' diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..0291a98 --- /dev/null +++ b/src/index.html @@ -0,0 +1,19 @@ + + + + + + + + + + + Taro + + + +
+ + diff --git a/src/pages/home/home.js b/src/pages/home/home.js new file mode 100644 index 0000000..c70d3f2 --- /dev/null +++ b/src/pages/home/home.js @@ -0,0 +1,216 @@ +import Taro, { Component } from '@tarojs/taro' +import { View, Button, Text, Swiper, SwiperItem, Image } from '@tarojs/components' +import { connect } from '@tarojs/redux' +import recommondShop from '../../component/recommendShop/recommendShop' + +import { add, minus, asyncAdd } from '../../actions/counter' + +import './home.scss' + + +@connect(({ counter }) => ({ + counter +}), (dispatch) => ({ + add () { + dispatch(add()) + }, + dec () { + dispatch(minus()) + }, + asyncAdd () { + dispatch(asyncAdd()) + } +})) +class Home extends Component { + + config = { + navigationBarTitleText: '首页' + } + constructor(){ + this.state={ + shops:'', + ads:'', + categories:'', + demanding:'' + } + } + +//http://ihome6.com/Shop-supplyShops + componentDidMount(){ + this.getShopInfo() + this.getHomePageInfo() + } + componentWillReceiveProps (nextProps) { + //console.log(this.props, nextProps) + } + + componentWillUnmount () { } + + componentDidShow () { } + + componentDidHide () { } + + getHomePageInfo(){ + Taro.request({ + url: 'http://192.168.1.230/Shop-wxStore', + }) + .then(res =>{ + // console.log(res.data) + this.setState({ + ads: res.data.data.adsLb, + categories: res.data.data.supplyClass, + categories: res.data.data.supplyClass, + demanding: res.data.data.demand.supplys, + }, () => { + console.log(this.state.demanding) + })}) + } + getShopInfo(){ + Taro.request({ + url: 'http://192.168.1.230/Shop-supplyShops', + method: 'POST', + dataType: 'json', + data: { + param: JSON.stringify({ + curr_page: 1, + page_count: 20, + parent_supply_class: 1, + supply_class: 1, + supply_level: 1, + action: "2" + }) + }, + header: { + 'content-type': 'application/x-www-form-urlencoded' + } + }) + .then(res => { + this.setState({ shops: res.data.shops }) + } + ) + } + + render () { + + + const demandingElemensArray = this.state.demanding.map((item,index)=>{ + return + + + {item.class_name} + + + 软件园D区 + + + 业主:{item.user_name} + + + + + + + + + }) + + const shopCollectionElementsArray=this.state.shops.map((item,index)=>{ + return + }) + + const adsImgElementsArray=this.state.ads.map((item,index)=>{ + return + + + }) + const categoriesElementsArray1=this.state.categories[0].map((item,index)=>{ + return + + {item.class_name} + + }) + const categoriesElementsArray2=this.state.categories[1].map((item,index)=>{ + return + + {item.class_name} + + }) + + + + return ( + + + + + {adsImgElementsArray} + + + + + + + + {categoriesElementsArray1} + + + + + {categoriesElementsArray2} + + + + + + + + + 业主需求 + + + 更多>> + + + + + {demandingElemensArray} + + + + + + + + 行业推荐 + + + {shopCollectionElementsArray} + + + + ) + } +} + +export default Home diff --git a/src/pages/home/home.scss b/src/pages/home/home.scss new file mode 100644 index 0000000..40e679f --- /dev/null +++ b/src/pages/home/home.scss @@ -0,0 +1,33 @@ +.container{ + margin-top: 100px; + .title{ + display: flex; + flex-wrap: nowrap; + flex-direction: row; + .text{ + width: 50% ; + flex:1; + } + .more-link{ + width: 50% ; + flex:1; + text-align: right + } + } + .demand{ + font-size: 30px; + } +} +.main-cate{ + .categories{ + display: flex; + flex-wrap: wrap; + flex-direction: row; + text-align: center; + font-size:30px; + .category-item{ + width: 20%; + margin-top: 20px; + } + } +} \ No newline at end of file diff --git a/src/pages/index/index.js b/src/pages/index/index.js new file mode 100644 index 0000000..af89135 --- /dev/null +++ b/src/pages/index/index.js @@ -0,0 +1,60 @@ +import Taro, { Component } from '@tarojs/taro' +import { View, Button, Text } from '@tarojs/components' +import { connect } from '@tarojs/redux' + +import { add, minus, asyncAdd } from '../../actions/counter' + +import './index.scss' + + +@connect(({ counter }) => ({ + counter +}), (dispatch) => ({ + add () { + dispatch(add()) + }, + dec () { + dispatch(minus()) + }, + asyncAdd () { + dispatch(asyncAdd()) + } +})) +class Index extends Component { + + config = { + navigationBarTitleText: '首页' + } + +//http://ihome6.com/Shop-supplyShops + componentDidMount(){ + Taro.navigateTo({ + url: '/pages/home/home' + }) + + // Taro.request({ + // url:'http://192.168.1.230/Shop-wxStore', + + // }) + // .then(res => console.log(res.data)) + } + componentWillReceiveProps (nextProps) { + console.log(this.props, nextProps) + } + + componentWillUnmount () { } + + componentDidShow () { } + + componentDidHide () { } + + render () { + return ( + + + + ) + } +} + +export default Index diff --git a/src/pages/index/index.scss b/src/pages/index/index.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/reducers/counter.js b/src/reducers/counter.js new file mode 100644 index 0000000..c6a8dd6 --- /dev/null +++ b/src/reducers/counter.js @@ -0,0 +1,22 @@ +import { ADD, MINUS } from '../constants/counter' + +const INITIAL_STATE = { + num: 0 +} + +export default function counter (state = INITIAL_STATE, action) { + switch (action.type) { + case ADD: + return { + ...state, + num: state.num + 1 + } + case MINUS: + return { + ...state, + num: state.num - 1 + } + default: + return state + } +} diff --git a/src/reducers/index.js b/src/reducers/index.js new file mode 100644 index 0000000..b443112 --- /dev/null +++ b/src/reducers/index.js @@ -0,0 +1,6 @@ +import { combineReducers } from 'redux' +import counter from './counter' + +export default combineReducers({ + counter +}) diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..5a1582f --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,28 @@ +import { createStore, applyMiddleware, compose } from 'redux' +import thunkMiddleware from 'redux-thunk' +import rootReducer from '../reducers' + +const composeEnhancers = + typeof window === 'object' && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ + // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize... + }) : compose + +const middlewares = [ + thunkMiddleware +] + +if (process.env.NODE_ENV === 'development') { + middlewares.push(require('redux-logger').createLogger()) +} + +const enhancer = composeEnhancers( + applyMiddleware(...middlewares), + // other store enhancers if any +) + +export default function configStore () { + const store = createStore(rootReducer, enhancer) + return store +}