Commit fde05524 by Bal Feng

add ext.json

parent 6237190d
...@@ -5,6 +5,11 @@ const config = { ...@@ -5,6 +5,11 @@ const config = {
designWidth: 750, designWidth: 750,
sourceRoot: 'src', sourceRoot: 'src',
outputRoot: 'dist', outputRoot: 'dist',
copy: {
patterns: [
{ from: 'ext.json', to: 'dist/ext.json' } // 指定需要 copy 的文件
]
},
// 通用插件配置 // 通用插件配置
plugins: { plugins: {
babel: { babel: {
......
{
"extEnable": true,
"extAppid": "wx337a3a660c6da1c6",
"ext": {
"attr": {
"siteId": "11536422",
"logoUrl": "https://user-assets.sxlcdn.com/images/24978/FuN1XSaebo4UJHhfumbZHfySq3S9.png?imageMogr2/strip/thumbnail/1200x9000%3E/format/png",
"siteUrl": "www.sxl.cn",
"description": "自主选位,自主点菜,源味渔社针对大食堂的弊端,致力于为消费者提供本味,健康,绿色,快捷的餐饮食品。"
},
"style": {
"mainBackground": "#AB8F83"
}
},
"pages": [
"pages/home/index",
"pages/cart/index",
"pages/user/index"
],
"window": {
"backgroundTextStyle": "dark",
"navigationBarBackgroundColor": "#346b30",
"navigationBarTitleText": "点餐小程序",
"navigationBarTextStyle": "white"
},
"tabBar": {
"list": [
{
"pagePath": "pages/home/index",
"text": "首页",
"iconPath": "./images/tab/icon-home.png",
"selectedIconPath": "./images/tab/icon-home-selected.png"
},
{
"pagePath": "pages/cart/index",
"text": "订单",
"iconPath": "./images/tab/icon-order.png",
"selectedIconPath": "./images/tab/icon-order-selected.png"
},
{
"pagePath": "pages/user/index",
"text": "更多",
"iconPath": "./images/tab/icon-mine.png",
"selectedIconPath": "./images/tab/icon-mine-selected.png"
}
],
"color": "#fff",
"selectedColor": "#fff",
"backgroundColor": "#346b30",
"borderStyle": "#ccc"
},
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
"debug": true
}
{ {
"miniprogramRoot": "./dist", "miniprogramRoot": "./dist",
"projectname": "taro-msparis", "projectname": "taro-ordering-production",
"description": "", "description": "",
"appid": "wxd2a161b3c8752b6f", "appid": "wx2a21c16c91b7e1bf",
"setting": { "setting": {
"urlCheck": true, "urlCheck": true,
"es6": false, "es6": false,
......
...@@ -7,15 +7,13 @@ import { Provider } from '@tarojs/redux' ...@@ -7,15 +7,13 @@ import { Provider } from '@tarojs/redux'
import './styles/base.scss' import './styles/base.scss'
const dvaApp = dva.createApp({ const dvaApp = dva.createApp({
initialState: {}, initialState: {},
models: models, models,
}); })
const store = dvaApp.getStore(); const store = dvaApp.getStore()
class App extends Component { class App extends Component {
config = { config = {
pages: [ pages: [
'pages/home/index', 'pages/home/index',
...@@ -52,10 +50,6 @@ class App extends Component { ...@@ -52,10 +50,6 @@ class App extends Component {
} }
} }
componentDidMount() {
}
render() { render() {
return (<Provider store={store}> return (<Provider store={store}>
<Home/> <Home/>
......
import Taro from '@tarojs/taro'
export default {
namespace: 'global',
state: {},
effects: {},
reducers: {
save(state, {
payload,
}) {
return {
...state,
...payload,
}
}
},
}
...@@ -2,10 +2,12 @@ import cart from '../pages/cart/model' ...@@ -2,10 +2,12 @@ import cart from '../pages/cart/model'
import home from '../pages/home/model' import home from '../pages/home/model'
import user from '../pages/user/model' import user from '../pages/user/model'
import products from '../pages/productTabs/model' import products from '../pages/productTabs/model'
import global from './global'
export default [ export default [
cart, cart,
home, home,
user, user,
products, products,
global,
] ]
...@@ -4,14 +4,22 @@ export default { ...@@ -4,14 +4,22 @@ export default {
namespace: 'home', namespace: 'home',
state: { state: {
settings: {}, settings: {},
currentStoreFrontId: null,
}, },
effects: { effects: {
* load(_, { * load(_, {
call, call,
put put,
select,
}) { }) {
const { attr, style } = yield call(homeApi.getExtConfig)
yield put({
type: 'global/save',
payload: attr,
})
const { siteId } = yield select(state => state.global)
const { data } = yield call(homeApi.settings, { const { data } = yield call(homeApi.settings, {
siteId: '11536422', siteId,
}) })
yield put({ yield put({
type: 'saveSettings', type: 'saveSettings',
...@@ -19,6 +27,15 @@ export default { ...@@ -19,6 +27,15 @@ export default {
settings: data, settings: data,
} }
}) })
yield put({
type: 'products/categories',
})
yield put({
type: 'saveSettings',
payload: {
currentStoreFrontId: data.storefronts && data.storefronts[0].id
}
})
}, },
}, },
reducers: { reducers: {
......
import Request from '../../utils/request'; import Taro from '@tarojs/taro'
import Request from '../../utils/request'
import extJson from '../../../ext.json'
const isWeApp = process.env.TARO_ENV === 'weapp'
export const settings = data => Request({ export const settings = data => Request({
url: `/r/v1/sites/${data.siteId}/restaurant/settings`, url: `/r/v1/sites/${data.siteId}/restaurant/settings`,
method: 'GET', method: 'GET',
}); })
export const getExtConfig = () => {
return new Promise((resolve, reject) => {
if (isWeApp) {
Taro.getExtConfig({
success: (res) => {
resolve(res.extConfig)
},
fail: (error) => {
reject(error)
},
})
} else {
resolve(extJson.ext)
}
})
}
...@@ -11,9 +11,11 @@ export default { ...@@ -11,9 +11,11 @@ export default {
* categories(_, { * categories(_, {
call, call,
put, put,
select,
}) { }) {
const { siteId } = yield select(state => state.global)
const { data } = yield call(api.categories, { const { data } = yield call(api.categories, {
siteId: '11536422', siteId,
}) })
yield put({ yield put({
type: 'save', type: 'save',
...@@ -37,8 +39,9 @@ export default { ...@@ -37,8 +39,9 @@ export default {
select, select,
}) { }) {
const { categoryId } = yield select(state => state.products) const { categoryId } = yield select(state => state.products)
const { currentStoreFrontId } = yield select(state => state.home)
const { data } = yield call(api.products, { const { data } = yield call(api.products, {
storefrontsId: '14171', storefrontsId: currentStoreFrontId,
categoryId, categoryId,
from: 0, from: 0,
per: 999, per: 999,
......
...@@ -10,6 +10,7 @@ import Loading from '../../components/Loading/Loading' ...@@ -10,6 +10,7 @@ import Loading from '../../components/Loading/Loading'
...loading, ...loading,
})) }))
export default class ProductTabs extends Component { export default class ProductTabs extends Component {
handleClick (value) { handleClick (value) {
const { categories } = this.props const { categories } = this.props
this.props.dispatch({ this.props.dispatch({
...@@ -25,12 +26,6 @@ export default class ProductTabs extends Component { ...@@ -25,12 +26,6 @@ export default class ProductTabs extends Component {
current: value, current: value,
}) })
} }
componentDidMount() {
const { dispatch } = this.props
dispatch({
type: 'products/categories'
})
}
getTitle() { getTitle() {
const { categories } = this.props const { categories } = this.props
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment