Commit 961dcafc by 姜雷

修改测试地址

parents 9d16899b 3118a781
const path = require('path');
const config = { const config = {
projectName: 'wx-school-app-public', projectName: 'wx-school-app-public',
date: '2019-4-12', date: '2019-4-12',
...@@ -5,32 +7,35 @@ const config = { ...@@ -5,32 +7,35 @@ const config = {
deviceRatio: { deviceRatio: {
'640': 2.34 / 2, '640': 2.34 / 2,
'750': 1, '750': 1,
'828': 1.81 / 2 '828': 1.81 / 2,
}, },
sourceRoot: 'src', sourceRoot: 'src',
outputRoot: 'dist', outputRoot: 'dist',
alias: {
'@': path.resolve(__dirname, '..', 'src'),
},
plugins: { plugins: {
babel: { babel: {
sourceMap: true, sourceMap: true,
presets: [ presets: [
['env', { [
modules: false 'env',
}] {
modules: false,
},
],
], ],
plugins: [ plugins: [
'transform-decorators-legacy', 'transform-decorators-legacy',
'transform-class-properties', 'transform-class-properties',
'transform-object-rest-spread' 'transform-object-rest-spread',
] ],
} },
},
defineConstants: {
}, },
defineConstants: {},
copy: { copy: {
patterns: [ patterns: [{ from: 'sitemap.json', to: 'dist/sitemap.json' }],
], options: {},
options: {
}
}, },
weapp: { weapp: {
module: { module: {
...@@ -38,34 +43,28 @@ const config = { ...@@ -38,34 +43,28 @@ const config = {
autoprefixer: { autoprefixer: {
enable: true, enable: true,
config: { config: {
browsers: [ browsers: ['last 3 versions', 'Android >= 4.1', 'ios >= 8'],
'last 3 versions', },
'Android >= 4.1',
'ios >= 8'
]
}
}, },
pxtransform: { pxtransform: {
enable: true, enable: true,
config: { config: {},
}
}, },
url: { url: {
enable: true, enable: true,
config: { config: {
limit: 10240 // 设定转换尺寸上限 limit: 10240, // 设定转换尺寸上限
} },
}, },
cssModules: { cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: { config: {
namingPattern: 'module', // 转换模式,取值为 global/module namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]' generateScopedName: '[name]__[local]___[hash:base64:5]',
} },
} },
} },
} },
}, },
h5: { h5: {
publicPath: '/', publicPath: '/',
...@@ -75,28 +74,24 @@ const config = { ...@@ -75,28 +74,24 @@ const config = {
autoprefixer: { autoprefixer: {
enable: true, enable: true,
config: { config: {
browsers: [ browsers: ['last 3 versions', 'Android >= 4.1', 'ios >= 8'],
'last 3 versions', },
'Android >= 4.1',
'ios >= 8'
]
}
}, },
cssModules: { cssModules: {
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
config: { config: {
namingPattern: 'module', // 转换模式,取值为 global/module namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]' generateScopedName: '[name]__[local]___[hash:base64:5]',
} },
} },
} },
} },
} },
} };
module.exports = function (merge) { module.exports = function(merge) {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
return merge({}, config, require('./dev')) return merge({}, config, require('./dev'));
} }
return merge({}, config, require('./prod')) return merge({}, config, require('./prod'));
} };
{ {
"name": "wx-school-app-public", "name": "wx-school-app-public",
"version": "1.0.0", "version": "1.0.7",
"private": true, "private": true,
"description": "", "description": "",
"scripts": { "scripts": {
"build:weapp": "taro build --type weapp", "build:weapp": "taro build --type weapp",
"build:swan": "taro build --type swan", "build:swan": "taro build --type swan",
"build:alipay": "taro build --type alipay", "build:alipay": "taro build --type alipay",
"build:tt": "taro build --type tt", "build:tt": "taro build --type tt",
"build:h5": "taro build --type h5", "build:h5": "taro build --type h5",
"build:rn": "taro build --type rn", "build:rn": "taro build --type rn",
"dev:weapp": "npm run build:weapp -- --watch", "dev:weapp": "npm run build:weapp -- --watch",
"dev:swan": "npm run build:swan -- --watch", "dev:swan": "npm run build:swan -- --watch",
"dev:alipay": "npm run build:alipay -- --watch", "dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --watch", "dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch", "dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch" "dev:rn": "npm run build:rn -- --watch"
}, },
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@tarojs/async-await": "1.2.13", "@tarojs/async-await": "1.3.4",
"@tarojs/components": "1.2.13", "@tarojs/components": "1.3.4",
"@tarojs/redux": "1.2.13", "@tarojs/redux": "1.3.4",
"@tarojs/redux-h5": "1.2.13", "@tarojs/redux-h5": "1.3.4",
"@tarojs/router": "1.2.13", "@tarojs/router": "1.3.4",
"@tarojs/taro": "1.2.13", "@tarojs/taro": "1.3.4",
"@tarojs/taro-alipay": "1.2.13", "@tarojs/taro-alipay": "1.3.4",
"@tarojs/taro-h5": "1.2.13", "@tarojs/taro-h5": "1.3.4",
"@tarojs/taro-swan": "1.2.13", "@tarojs/taro-swan": "1.3.4",
"@tarojs/taro-tt": "1.2.13", "@tarojs/taro-tt": "1.3.4",
"@tarojs/taro-weapp": "1.2.13", "@tarojs/taro-weapp": "1.3.4",
"crypto-js": "^3.1.9-1", "crypto-js": "^3.1.9-1",
"nerv-devtools": "^1.3.9", "nerv-devtools": "^1.4.3",
"nervjs": "^1.3.9", "nervjs": "^1.4.3",
"redux": "^4.0.0", "redux": "^4.0.0",
"redux-logger": "^3.0.6", "redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0" "redux-thunk": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"@tarojs/plugin-babel": "1.2.13", "@tarojs/plugin-babel": "1.3.4",
"@tarojs/plugin-csso": "1.2.13", "@tarojs/plugin-csso": "1.3.4",
"@tarojs/plugin-sass": "1.2.13", "@tarojs/plugin-sass": "1.3.4",
"@tarojs/plugin-uglifyjs": "1.2.13", "@tarojs/plugin-uglifyjs": "1.3.4",
"@tarojs/webpack-runner": "1.2.13", "@tarojs/webpack-runner": "1.3.4",
"@types/react": "^16.4.8", "@types/react": "^16.4.8",
"@types/webpack-env": "^1.13.6", "@types/webpack-env": "^1.13.6",
"babel-eslint": "^8.2.3", "babel-eslint": "^8.2.3",
"babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-jsx-stylesheet": "^0.6.5", "babel-plugin-transform-jsx-stylesheet": "^0.6.5",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1", "babel-preset-env": "^1.6.1",
"eslint": "^4.19.1", "eslint": "^4.19.1",
"eslint-config-taro": "1.2.13", "eslint-config-taro": "1.3.4",
"eslint-plugin-import": "^2.12.0", "eslint-plugin-import": "^2.12.0",
"eslint-plugin-react": "^7.8.2", "eslint-plugin-react": "^7.8.2",
"eslint-plugin-taro": "1.2.13", "eslint-plugin-taro": "1.3.4",
"eslint-plugin-typescript": "^0.12.0", "eslint-plugin-typescript": "^0.12.0",
"typescript": "^3.0.1" "typescript": "^3.0.1"
} }
} }
{
"rules": {
"action": "disallow",
"page": "*"
}
}
import Taro, { request } from '@tarojs/taro'; import Taro, { request } from '@tarojs/taro';
import store from '../store/index'; import store from '../store/index';
import { BASE_SERVER_URL, LogoutCode, SuccessCode } from '../constants/index'; import { BASE_SERVER_URL, LogoutCode, SuccessCode } from '@/constants';
export type ResponseDataEntity<T> = { export type ResponseDataEntity<T> = {
code: number; code: number;
......
...@@ -3,3 +3,4 @@ export const LogoutCode = -2; ...@@ -3,3 +3,4 @@ export const LogoutCode = -2;
export const NotRegisterCode = 1005; export const NotRegisterCode = 1005;
export const BASE_SERVER_URL = 'https://ex-test-dcxy-smapro-app.168cad.top'; export const BASE_SERVER_URL = 'https://ex-test-dcxy-smapro-app.168cad.top';
export const SOCKET_URL = 'wss://test-shower-wss1.168cad.top:9443/ws';
import Actions from '@/types/Store/Actions';
import Taro, { useReducer, useEffect } from '@tarojs/taro';
import { str2ab, ab2str } from '@/utils/arrayBuffer';
type StoreState = {
socketState: boolean;
socketTask: Taro.SocketTask | null;
};
const StopCode = 1000;
let reConnectting: boolean = false;
let timer: NodeJS.Timeout | null = null;
const initState = {
socketState: false,
socketTask: null,
};
const reducer = (state: StoreState, action: Actions): StoreState => {
switch (action.type) {
case 'GET_SOCKET_TASK':
return { ...state, socketTask: action.payload };
case 'SOCKET_STATE_CHANGE':
return { ...state, socketState: action.payload };
default:
return state;
}
};
const useDeviceWS = ({
url,
getSocketData,
}: {
url: string;
getSocketData: (msg: string) => void;
}): {
state: StoreState;
sendMessageToServer: (
msg: string,
successHandle: Taro.SocketTask.send.ParamPropSuccess,
failHandle: Taro.SocketTask.send.ParamPropFail,
) => void;
} => {
const [state, dispatch] = useReducer(reducer, initState);
const connectDeviceSocket = (url: string) => {
Taro.connectSocket({ url: url }).then(task => {
dispatch({ type: 'GET_SOCKET_TASK', payload: task });
task.onOpen(() => {
console.log('onOpen');
if (reConnectting) {
// reConnectDeviceSocket(true);
timer && clearTimeout(timer);
timer = null;
reConnectting = false;
}
task.send({ data: str2ab('{}') });
dispatch({ type: 'SOCKET_STATE_CHANGE', payload: true });
// this.sendDeviceCode();
});
task.onMessage(res => {
const msg: string = ab2str(res.data);
console.log('socket onMessage: ', msg);
if (msg === '[0]') {
console.log('结束蓝牙以及socket: ', msg);
closeDeviceSocket();
} else if (msg === '[]') {
} else {
if (msg.length > 100) {
getSocketData('[]');
} else if (msg.length > 20) {
for (let index = 0; index <= Math.floor(msg.length / 20); index++) {
let str = msg.substring(index * 20, (index + 1) * 20);
getSocketData(str);
}
} else {
if (msg) {
getSocketData(msg);
}
}
}
});
task.onClose(e => {
console.log('socked关闭', e, reConnectting, timer);
dispatch({ type: 'SOCKET_STATE_CHANGE', payload: false });
dispatch({ type: 'GET_SOCKET_TASK', payload: null });
if (e.code === StopCode) {
console.log('正确结束socket连接');
} else {
console.log('开始重连socket');
reConnectDeviceSocket();
}
});
});
};
const closeDeviceSocket = () => {
const { socketTask } = state;
console.log('in close', socketTask, timer);
if (socketTask) {
socketTask.close({
code: StopCode,
complete: () => {
dispatch({ type: 'SOCKET_STATE_CHANGE', payload: false });
dispatch({ type: 'GET_SOCKET_TASK', payload: null });
},
});
}
if (timer) {
clearTimeout(timer);
}
};
const reConnectDeviceSocket = () => {
console.log(reConnectting, timer);
if (reConnectting) {
connectDeviceSocket(url);
} else if (timer) {
clearTimeout(timer);
reConnectting = false;
timer = null;
console.log('请保证网络正常');
Taro.showModal({
title: '警告',
content: '请保持网络畅通正常',
});
} else {
timer = setTimeout(() => {
reConnectting = false;
}, 10000);
reConnectting = true;
console.log(reConnectting, timer);
connectDeviceSocket(url);
}
};
const sendMessageToServer = (
msg: string,
successHandle: Taro.SocketTask.send.ParamPropSuccess,
failHandle: Taro.SocketTask.send.ParamPropFail,
) => {
const { socketTask } = state;
socketTask &&
socketTask.send({
data: str2ab(msg),
success: successHandle,
fail: failHandle,
});
};
useEffect(() => {
connectDeviceSocket(url);
return closeDeviceSocket;
}, [url]);
return { state, sendMessageToServer };
};
export default useDeviceWS;
export const ab2str = (buf: ArrayBuffer): string => {
return String.fromCharCode.apply(null, new Int8Array(buf));
};
export const str2ab = (str: string): ArrayBuffer => {
var buf = new ArrayBuffer(str.length);
var bufView = new Int8Array(buf);
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
};
...@@ -15,16 +15,14 @@ ...@@ -15,16 +15,14 @@
"sourceMap": true, "sourceMap": true,
"baseUrl": ".", "baseUrl": ".",
"rootDir": ".", "rootDir": ".",
"paths": {
"@/*": ["./src/*"]
},
"jsx": "preserve", "jsx": "preserve",
"jsxFactory": "Taro.createElement", "jsxFactory": "Taro.createElement",
"allowJs": true, "allowJs": true,
"typeRoots": [ "typeRoots": ["node_modules/@types"]
"node_modules/@types"
]
}, },
"exclude": [ "exclude": ["node_modules", "dist"],
"node_modules",
"dist"
],
"compileOnSave": false "compileOnSave": false
} }
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