Commit 18b0b11d by zhonghao

无人值守屏保

parent 8c76f0c0
This source diff could not be displayed because it is too large. You can view the blob instead.
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import * as api from '../services/store'; import * as api from '../services/store';
export default { export default {
namespace: 'store', namespace: 'store',
state: { state: {
auth: {}, auth: {},
socket: '', socket: '',
ai: { ai: {
temperature: 0, temperature: 0,
humidity: 0, humidity: 0,
shock: 0, shock: 0,
trigger: { trigger: {
text: 0, text: 0,
data: 0, data: 0,
}, },
offset: 0, offset: 0,
}, },
}, },
reducers: { reducers: {
initScaleData(state) { initScaleData(state) {
state.ai = { state.ai = {
...state.ai, ...state.ai,
shock: 0, shock: 0,
trigger: { trigger: {
text: 0, text: 0,
data: 0, data: 0,
}, },
offset: 0, offset: 0,
}; };
return {...state}; return {...state};
}, },
setAuth(state, {id, auth}) { setAuth(state, {id, auth}) {
state.id = id; state.id = id;
state.auth = auth; state.auth = auth;
window.auth = auth; window.auth = auth;
if (window.socket) { if (window.socket) {
window.socket.io.opts.query = { window.socket.io.opts.query = {
token: auth.token, token: auth.token,
}; };
} }
return {...state}; return {...state};
}, },
setScaleData(state, {data}) { setScaleData(state, {data}) {
state.ai = data; state.ai = data;
return {...state}; return {...state};
}, },
setSocket(state, {socket}) { setSocket(state, {socket}) {
state.socket = socket; state.socket = socket;
return {...state}; return {...state};
}, },
}, },
effects: { effects: {
*auth(action, {put, call}) { *auth(action, {put, call}) {
const {data} = action.key const {data} = action.key
? yield call(api.token, action) ? yield call(api.token, action)
: yield call(api.refreshToken); : yield call(api.refreshToken);
if (data && data.code === 1) { if (data && data.code === 1) {
let set = []; let set = [];
if (action.key) { if (action.key) {
set = [ set = [
['KEY', action.key], ['KEY', action.key],
['SECRET', action.secret], ['SECRET', action.secret],
['DEVICE', action.device], ['DEVICE', action.device],
]; ];
} }
if (action.host) { if (action.host) {
set.push(['HOST', action.host]); set.push(['HOST', action.host]);
} }
if (data.data && data.data.contact) { if (data.data && data.data.contact) {
set.push(['CONTACT', data.data.contact]); set.push(['CONTACT', data.data.contact]);
} }
set.push(['auth', JSON.stringify(data.data)]); set.push(['auth', JSON.stringify(data.data)]);
yield call(AsyncStorage.multiSet, set); yield call(AsyncStorage.multiSet, set);
// 缓存数据到内存,方便调用 // 缓存数据到内存,方便调用
const getValues = () => const getValues = () =>
AsyncStorage.multiGet(['HOST', 'KEY', 'DEVICE', 'CONTACT']); AsyncStorage.multiGet(['HOST', 'KEY', 'DEVICE', 'CONTACT']);
const values = yield call(getValues); const values = yield call(getValues);
window.deviceInfo = {}; window.deviceInfo = {};
values.map(r => { values.map(r => {
const k = r[0]; const k = r[0];
const v = r[1]; const v = r[1];
if (k && v) { if (k && v) {
window.deviceInfo[k.toLowerCase()] = v; window.deviceInfo[k.toLowerCase()] = v;
} }
}); });
yield put({type: 'setAuth', id: data.id, auth: data.data}); yield put({type: 'setAuth', id: data.id, auth: data.data});
yield put({type: 'region'}); yield put({type: 'region'});
} }
return data; return data;
}, },
*logout(action, {put, call}) { *logout(action, {put, call}) {
yield call(AsyncStorage.removeItem, 'auth'); yield call(AsyncStorage.removeItem, 'auth');
yield put({type: 'app/replace', route: 'home'}); yield put({type: 'app/replace', route: 'home'});
}, },
*version(action, {call}) { *version(action, {call}) {
yield call(api.version); yield call(api.version);
}, },
*region(action, {call}) { *region(action, {call}) {
const {data} = yield call(api.region); const {data} = yield call(api.region);
if (data.code === 1) { if (data.code === 1) {
window.region = data.data; window.region = data.data;
window.regionArr = []; window.regionArr = [];
['citycode', 'adcode', 'towncode'].map(k => { ['citycode', 'adcode', 'towncode'].map(k => {
const v = window.region[k]; const v = window.region[k];
if (v) { if (v) {
window.regionArr.push(v); window.regionArr.push(v);
} }
}); });
window.regionArr.push(window.region.key); window.regionArr.push(window.region.key);
window.regionArr = window.regionArr.reverse(); window.regionArr = window.regionArr.reverse();
} }
}, },
*door(action, {call}) { *door(action, {call}) {
const {data} = yield call(api.door, action); const {data} = yield call(api.door, action);
if (data.code === 1) { if (data.code === 1) {
return data.data; return data.data;
} }
}, },
*wxdoor(action, {call}) { *wxdoor(action, {call}) {
const {data} = yield call(api.wxdoor, action); const {data} = yield call(api.wxdoor, action);
if (data.code === 1) { if (data.code === 1) {
return data.data; return data.data;
} }
}, },
*scaleData(action, {put, call, select}) { *scaleData(action, {put, call, select}) {
let {data} = yield call(api.scaleData); let {data} = yield call(api.scaleData);
if (data.code === 1 && data.data) { if (data.code === 1 && data.data) {
let trigger = yield select(state => state.store.ai.trigger); let trigger = yield select(state => state.store.ai.trigger);
const dataTran = tranAIData(data.data, trigger); const dataTran = tranAIData(data.data, trigger);
yield put({type: 'setScaleData', data: dataTran}); yield put({type: 'setScaleData', data: dataTran});
return data.data; return data.data;
} }
}, },
*sendsms(action, {call}) { *sendsms(action, {call}) {
const {data} = yield call(api.sendsms, action); const {data} = yield call(api.sendsms, action);
return data; return data;
}, },
*verifysms(action, {call}) { *verifysms(action, {call}) {
const {data} = yield call(api.verifysms, action); const {data} = yield call(api.verifysms, action);
return data; return data;
}, },
*getAdvertising(action, {call}) { *getAdvertising(action, {call}) {
return yield call(api.getAdvertising, action); return yield call(api.getAdvertising, action);
}, },
*getStore(action, {call}) { *getStore(action, {call}) {
return yield call(api.getStore, action); return yield call(api.getStore, action);
}, },
*findModuleSetting(action, {call}) { *findModuleSetting(action, {call}) {
return yield call(api.findModuleSetting, action); return yield call(api.findModuleSetting, action);
}, },
}, *noBuyGoGoGo(action, {call}) {
}; return yield call(api.noBuyGoGoGo, action);
},
const randomData = Math.random(); },
};
let tranAIData = (data, trigger) => {
let aiData = { const randomData = Math.random();
shock: 0,
trigger: { let tranAIData = (data, trigger) => {
text: 0, let aiData = {
data: 0, shock: 0,
}, trigger: {
offset: 0, text: 0,
}; data: 0,
let max = 0; },
let min = 500000; offset: 0,
let sum = 0; };
data.weights.map(v => { let max = 0;
if (v > max) { let min = 500000;
max = v; let sum = 0;
} data.weights.map(v => {
if (v < min) { if (v > max) {
min = v; max = v;
} }
sum += v; if (v < min) {
}); min = v;
let ave = sum / 10; }
if (max - min >= 600) { sum += v;
aiData.shock = (100 + Math.random() * 80) * (ave / 75000); });
} else { let ave = sum / 10;
aiData.shock = ((max - min) / 4) * (ave / 75000); if (max - min >= 600) {
} aiData.shock = (100 + Math.random() * 80) * (ave / 75000);
if (data.stableWeight && data.stableWeight > 0) { } else {
aiData.trigger.data = 96; aiData.shock = ((max - min) / 4) * (ave / 75000);
aiData.trigger.text = data.stableWeight; }
} else { if (data.stableWeight && data.stableWeight > 0) {
aiData.trigger.data = trigger.data + Math.random() * 30; aiData.trigger.data = 96;
aiData.trigger.text = ave; aiData.trigger.text = data.stableWeight;
} } else {
if (data.stableWeight && data.stableWeight > 0) { aiData.trigger.data = trigger.data + Math.random() * 30;
aiData.offset = randomData * 30; aiData.trigger.text = ave;
} else if (max - ave > 30 && ave - min > 30) { }
aiData.offset = 30 + Math.random() * 30; if (data.stableWeight && data.stableWeight > 0) {
} else { aiData.offset = randomData * 30;
aiData.offset = max - ave > ave - min ? ave - min : max - ave; } else if (max - ave > 30 && ave - min > 30) {
} aiData.offset = 30 + Math.random() * 30;
if ( } else {
!data.weights || aiData.offset = max - ave > ave - min ? ave - min : max - ave;
(Number(data.weights[0]) === 0 && }
Number(data.weights[data.weights.length - 1]) === 0) if (
) { !data.weights ||
aiData = { (Number(data.weights[0]) === 0 &&
shock: 0, Number(data.weights[data.weights.length - 1]) === 0)
trigger: { ) {
text: 0, aiData = {
data: 0, shock: 0,
}, trigger: {
offset: 0, text: 0,
}; data: 0,
} },
return {temperature: data.temperature, humidity: data.humidity, ...aiData}; offset: 0,
}; };
}
return {temperature: data.temperature, humidity: data.humidity, ...aiData};
};
...@@ -13,10 +13,17 @@ import Touch from '../components/Touch'; ...@@ -13,10 +13,17 @@ import Touch from '../components/Touch';
import counterText from '../assets/Vertical/counterText.png'; import counterText from '../assets/Vertical/counterText.png';
import img24h from '../assets/Vertical/24h.png'; import img24h from '../assets/Vertical/24h.png';
import phone from '../assets/Vertical/phone.png'; import phone from '../assets/Vertical/phone.png';
import guide from '../assets/Vertical/guide.jpg';
import {login} from '../utils/config'; import {login} from '../utils/config';
import {colors} from '../utils/common'; import {colors} from '../utils/common';
import WxFacepay from '../utils/WxFacepay'; import WxFacepay from '../utils/WxFacepay';
import {width, setSpText, scaleSize, scaleHeight} from '../utils/screen'; import {
width,
setSpText,
scaleSize,
scaleHeight,
// height,
} from '../utils/screen';
import Speech from '../utils/Speech'; import Speech from '../utils/Speech';
import delay from '../utils/delay'; import delay from '../utils/delay';
import Printer from '../utils/Printer'; import Printer from '../utils/Printer';
...@@ -354,6 +361,11 @@ class VerticalPage extends Component { ...@@ -354,6 +361,11 @@ class VerticalPage extends Component {
}); });
}; };
onNoBuy = async () => {
const {data} = await this.props.dispatch({type: 'store/noBuyGoGoGo'});
Speech.speak(data.msg);
};
closeHint = () => { closeHint = () => {
this.setState({ this.setState({
hintVisible: false, hintVisible: false,
...@@ -533,7 +545,14 @@ class VerticalPage extends Component { ...@@ -533,7 +545,14 @@ class VerticalPage extends Component {
imgArr, imgArr,
adType, adType,
} = this.props; } = this.props;
let {contact, hintVisible, logoVisible, logo, priceVisible} = this.state; let {
contact,
hintVisible,
logoVisible,
logo,
priceVisible,
dtype,
} = this.state;
pageSize = pageSize =
goods && goods.bags.length > 0 goods && goods.bags.length > 0
? goods && goods.bags.length > 3 ? goods && goods.bags.length > 3
...@@ -573,6 +592,25 @@ class VerticalPage extends Component { ...@@ -573,6 +592,25 @@ class VerticalPage extends Component {
this.state.faceType === 'wxpay' ? this.wxFacepay : this.smilepay; this.state.faceType === 'wxpay' ? this.wxFacepay : this.smilepay;
return ( return (
<View style={styles.main}> <View style={styles.main}>
{goodsArr.length === 0 && dtype === 'guard' ? (
<View style={styles.guardModal}>
<View style={styles.guardModal_image}>
<Image source={guide} />
</View>
<View style={styles.guardModal_button}>
<Touch onPress={() => this.onCall()}>
<View style={styles.guardModal_button_call}>
<Text style={styles.callText}>呼叫客服</Text>
</View>
</Touch>
<Touch onPress={() => this.onNoBuy()}>
<View style={styles.guardModal_button_nobuy}>
<Text style={styles.callText}>无购物出店</Text>
</View>
</Touch>
</View>
</View>
) : null}
<HintPhone <HintPhone
visible={hintVisible} visible={hintVisible}
contact={contact} contact={contact}
...@@ -1093,6 +1131,7 @@ const styles = { ...@@ -1093,6 +1131,7 @@ const styles = {
main: { main: {
backgroundColor: '#F0F0F0', backgroundColor: '#F0F0F0',
height: '100%', height: '100%',
position: 'relative',
}, },
header: { header: {
flexDirection: 'row', flexDirection: 'row',
...@@ -1551,6 +1590,58 @@ const styles = { ...@@ -1551,6 +1590,58 @@ const styles = {
marginRight: '5%', marginRight: '5%',
marginBottom: '2.5%', marginBottom: '2.5%',
}, },
guardModal: {
position: 'absolute',
top: 0,
left: 0,
zIndex: 999999999999999,
elevation: 6,
display: 'flex',
width: '100%',
height: '100%',
backgroundColor: '#000000',
},
guardModal_image: {
height: '70%',
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
},
guardModal_button: {
height: '30%',
width: '100%',
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
guardModal_button_call: {
backgroundColor: '#fc4000',
borderRadius: 100,
color: '#ffffff',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: scaleSize(350),
height: scaleSize(125),
fontSize: scaleSize(75),
marginRight: 50,
},
guardModal_button_nobuy: {
borderWidth: 5,
borderColor: '#ffffff',
borderRadius: 100,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: scaleSize(350),
height: scaleSize(125),
},
callText: {
fontSize: scaleSize(45),
color: '#ffffff',
},
}; };
export default CounterMixins(VerticalPage); export default CounterMixins(VerticalPage);
import qs from 'qs'; import qs from 'qs';
import axios from 'axios'; import axios from 'axios';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
const pack = require('../../package.json'); const pack = require('../../package.json');
export function token({host = '', key, secret, device}) { export function token({host = '', key, secret, device}) {
return axios.post(`${host}/store/auth`, qs.stringify({key, secret, device})); return axios.post(`${host}/store/auth`, qs.stringify({key, secret, device}));
} }
export async function refreshToken() { export async function refreshToken() {
const auth = await AsyncStorage.getItem('auth'); const auth = await AsyncStorage.getItem('auth');
if (auth) { if (auth) {
try { try {
const {refresh_token} = JSON.parse(auth); const {refresh_token} = JSON.parse(auth);
return await axios.get('/auth/refresh', { return await axios.get('/auth/refresh', {
headers: {Authorization: `Bearer ${refresh_token}`}, headers: {Authorization: `Bearer ${refresh_token}`},
}); });
} catch (e) { } catch (e) {
return {data: null}; return {data: null};
} }
} }
return {data: null}; return {data: null};
} }
export function version() { export function version() {
return axios.put('/store/version', qs.stringify({version: pack.version})); return axios.put('/store/version', qs.stringify({version: pack.version}));
} }
export function region() { export function region() {
return axios.get('/store/region'); return axios.get('/store/region');
} }
export function door({userId}) { export function door({userId}) {
return axios.post('/store/door', qs.stringify({userId})); return axios.post('/store/door', qs.stringify({userId}));
} }
export function wxdoor({ export function wxdoor({
userId, userId,
openid, openid,
wxtoken, wxtoken,
nickname, nickname,
alipayUid, alipayUid,
fToken, fToken,
phone, phone,
sense, sense,
orderId, orderId,
authCode, authCode,
}) { }) {
return axios.post( return axios.post(
'/store/wxdoor', '/store/wxdoor',
qs.stringify({ qs.stringify({
userId, userId,
openid, openid,
wxtoken, wxtoken,
nickname, nickname,
alipayUid, alipayUid,
fToken, fToken,
phone, phone,
sense, sense,
orderId, orderId,
authCode, authCode,
}), }),
); );
} }
export function scaleData() { export function scaleData() {
return axios.get('/store/scaleData'); return axios.get('/store/scaleData');
} }
export function sendsms({phone, faceType}) { export function sendsms({phone, faceType}) {
return axios.post('/store/sendsms', qs.stringify({phone, faceType})); return axios.post('/store/sendsms', qs.stringify({phone, faceType}));
} }
export function verifysms({phone, code, userId, faceType}) { export function verifysms({phone, code, userId, faceType}) {
return axios.post( return axios.post(
'/store/verifysms', '/store/verifysms',
qs.stringify({phone, code, userId, faceType}), qs.stringify({phone, code, userId, faceType}),
); );
} }
export function getAdvertising(action) { export function getAdvertising(action) {
return axios.get(`/store/advertising?${qs.stringify(action)}`); return axios.get(`/store/advertising?${qs.stringify(action)}`);
} }
export function getStore({group}) { export function getStore({group}) {
return axios.get(`/store/setting/${group}`); return axios.get(`/store/setting/${group}`);
} }
export function findModuleSetting({group}) { export function findModuleSetting({group}) {
return axios.get(`/store/module/setting/${group}`); return axios.get(`/store/module/setting/${group}`);
} }
export function noBuyGoGoGo() {
return axios.post('/store/counter/nobuy');
}
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