diff --git a/src/actions/index.js b/src/actions/index.js
index d192ebb..ac914e4 100644
--- a/src/actions/index.js
+++ b/src/actions/index.js
@@ -3,26 +3,36 @@
* @param {string} msg
* @param {function} act
*/
-export const add_dialog_msg =(msg, act) => ({
- type: 'dialog_addmsg',
- msg: msg,
- act: act || null
+export const add_dialog_msg = (msg, act) => ({
+ type: 'dialog_addmsg',
+ msg: msg,
+ act: act || null
});
/**
* remove dialog queue first message
*/
export const remove_dialog_msg = () => ({
- type: 'dialog_remove_first'
+ type: 'dialog_remove_first'
});
+export const add_confirm = (msg, act = null) => ({
+ type: 'confirm_addmsg',
+ msg,
+ act
+})
+
+export const remove_confirm = () => ({
+ type: 'confirm_remove'
+})
+
/**
* set i18next object
* @param {object} i18n i18next object
*/
export const set_i18n = (i18n) => ({
- type: 'i18n_set_ctx',
- i18n: i18n
+ type: 'i18n_set_ctx',
+ i18n: i18n
});
/**
@@ -30,7 +40,7 @@ export const set_i18n = (i18n) => ({
* @param {bool} flag switch menu open/close
*/
export const toggle_menu = (flag) => ({
- type: flag ? 'ui_show_menu' : 'ui_hide_menu'
+ type: flag ? 'ui_show_menu' : 'ui_hide_menu'
});
/**
@@ -38,7 +48,7 @@ export const toggle_menu = (flag) => ({
* @param {bool} flag
*/
export const toggle_loading = (flag) => ({
- type: flag ? 'ui_show_loading' : 'ui_hide_loading'
+ type: flag ? 'ui_show_loading' : 'ui_hide_loading'
});
/**
@@ -46,620 +56,620 @@ export const toggle_loading = (flag) => ({
* @param {object} data
*/
export const getRequest = (data = {}) => {
- let json = {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- mode:'cors'
- };
- let token = sessionStorage.getItem('token');
- if(token) json.headers['x-auth-token'] = token;
+ let json = {
+ method: 'post',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ mode: 'cors'
+ };
+ let token = sessionStorage.getItem('token');
+ if (token) json.headers['x-auth-token'] = token;
- json.body = JSON.stringify({data});
+ json.body = JSON.stringify({ data });
- return json;
+ return json;
}
export const get_network_info = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/system/getnetwork', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1){
- return dispatch(add_dialog_msg(json.message));
- }
- let j = {};
- if('data' in json && 'record' in json.data && json.data.record.length > 0) j = json.data.record[0];
- return dispatch(network_info(j));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/system/getnetwork', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) {
+ return dispatch(add_dialog_msg(json.message));
+ }
+ let j = {};
+ if ('data' in json && 'record' in json.data && json.data.record.length > 0) j = json.data.record[0];
+ return dispatch(network_info(j));
+ });
}
const network_info = (json) => ({
- type: 'network_info',
- network: json
+ type: 'network_info',
+ network: json
});
export const set_network_info = (dhcpMode, ip, netmask, gateway, dns) => dispatch => {
- dispatch(toggle_loading(1));
- let type = dhcpMode ? 'dhcp' : 'manual';
- let req = getRequest();
- let json = {
- data:{
- type,
- ip,
- netmask,
- gateway,
- dns
- }
- }
- req.body = JSON.stringify(json);
- return fetch('/api/system/updatenetwork', req)
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_network_info());
- });
+ dispatch(toggle_loading(1));
+ let type = dhcpMode ? 'dhcp' : 'manual';
+ let req = getRequest();
+ let json = {
+ data: {
+ type,
+ ip,
+ netmask,
+ gateway,
+ dns
+ }
+ }
+ req.body = JSON.stringify(json);
+ return fetch('/api/system/updatenetwork', req)
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_network_info());
+ });
}
export const get_system_time = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/system/gettime', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1){
- return dispatch(add_dialog_msg(json.message));
- }
- let t = '';
- if('data' in json && 'record' in json.data && json.data.record.length > 0) t = json.data.record[0].time;
- return dispatch(system_time(t));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/system/gettime', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) {
+ return dispatch(add_dialog_msg(json.message));
+ }
+ let t = '';
+ if ('data' in json && 'record' in json.data && json.data.record.length > 0) t = json.data.record[0].time;
+ return dispatch(system_time(t));
+ });
}
const system_time = (time) => ({
- type: 'system_time',
- time
+ type: 'system_time',
+ time
});
export const set_system_time = time => dispatch => {
- dispatch(toggle_loading(1));
- let req = getRequest({time});
- return fetch('/api/system/updatetime', req)
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_system_time());
- });
+ dispatch(toggle_loading(1));
+ let req = getRequest({ time });
+ return fetch('/api/system/updatetime', req)
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_system_time());
+ });
}
export const get_user_list = () => dispatch => {
- dispatch(toggle_loading(1));
- let req = getRequest();
- return fetch('/api/system/getuserlist', req)
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(user_list(json.data.record));
- });
+ dispatch(toggle_loading(1));
+ let req = getRequest();
+ return fetch('/api/system/getuserlist', req)
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(user_list(json.data.record));
+ });
}
const user_list = (user) => ({
- type: 'user_list',
- user
+ type: 'user_list',
+ user
})
const userApi = (url, data = {}) => dispatch => {
- dispatch(toggle_loading(1));
- let req = getRequest(data);
- return fetch(url, req)
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_user_list());
- });
+ dispatch(toggle_loading(1));
+ let req = getRequest(data);
+ return fetch(url, req)
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_user_list());
+ });
}
export const edit_user = (data) => dispatch => {
- return dispatch(userApi('/api/system/edituser', data));
+ return dispatch(userApi('/api/system/edituser', data));
}
export const add_user = (data) => dispatch => {
- return dispatch(userApi('/api/system/adduser', data));
+ return dispatch(userApi('/api/system/adduser', data));
}
export const del_user = (data) => dispatch => {
- return dispatch(userApi('/api/system/deluser', data));
+ return dispatch(userApi('/api/system/deluser', data));
}
export const get_dio_info = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/dio/getdioinfo', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(dioinfo(json.data.rt.do || [], json.data.rt.di || []));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/dio/getdioinfo', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(dioinfo(json.data.rt.do || [], json.data.rt.di || []));
+ });
}
export const get_dio_status = () => dispatch => {
- return fetch('/api/dio/getio', getRequest())
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(diostatus(json.data.rt.do, json.data.rt.di));
- });
+ return fetch('/api/dio/getio', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(diostatus(json.data.rt.do, json.data.rt.di));
+ });
}
export const set_do_status = (data) => dispatch => {
- return fetch('/api/dio/dotrun', getRequest(data))
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- })
+ return fetch('/api/dio/dotrun', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ })
}
export const set_dio_info = (data) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/dio/setdioinfo', getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_dio_info());
- })
+ dispatch(toggle_loading(1));
+ return fetch('/api/dio/setdioinfo', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_dio_info());
+ })
}
const diostatus = (doSt, diSt) => ({
- type: 'dio_status',
- doSt,
- diSt
+ type: 'dio_status',
+ doSt,
+ diSt
})
const dioinfo = (dod, did) => ({
- type: 'dio_list',
- do: dod,
- di: did
+ type: 'dio_list',
+ do: dod,
+ di: did
});
export const get_log_list = (p = 1) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/log/getlog', getRequest({p}))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(loglist(json.data.record, json.data.page));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/log/getlog', getRequest({ p }))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(loglist(json.data.record, json.data.page));
+ });
}
const loglist = (list, page) => ({
- type: 'log_list',
- list,
- page
+ type: 'log_list',
+ list,
+ page
});
export const scan_leone = (data) => (dispatch, getState) => {
- dispatch(toggle_loading(1));
- dispatch(set_scanning());
- return fetch('/api/leone/scanleone', getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- let {i18n} = getState();
- if(json.data.record.length == 0) return dispatch(add_dialog_msg(i18n&&i18n.t? i18n.t('tip.scan_empty') : ''));
- return dispatch(show_scan_leone(json.data.record));
- })
+ dispatch(toggle_loading(1));
+ dispatch(set_scanning());
+ return fetch('/api/leone/scanleone', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ let { i18n } = getState();
+ if (json.data.record.length == 0) return dispatch(add_dialog_msg(i18n && i18n.t ? i18n.t('tip.scan_empty') : ''));
+ return dispatch(show_scan_leone(json.data.record));
+ })
}
export const clear_scan_leone = (clrRemote = false) => dispatch => {
- dispatch(clear_scan());
-
- return fetch('/api/leone/clearscanleone', getRequest())
- .then(response => response.json())
- .then(json => {
- return ;
- });
+ dispatch(clear_scan());
+
+ return fetch('/api/leone/clearscanleone', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ return;
+ });
}
export const add_scan_leone = (data) => dispatch => {
- dispatch(toggle_loading(1));
+ dispatch(toggle_loading(1));
- return fetch('/api/leone/addscanleone', getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- dispatch(clear_scan());
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_leone_list());
- })
+ return fetch('/api/leone/addscanleone', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ dispatch(clear_scan());
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_leone_list());
+ })
}
export const get_leone_list = (showLoading = true) => dispatch => {
- if(showLoading) dispatch(toggle_loading(1));
- return fetch('/api/leone/getleonelist', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(leone_list(json.data.record, json.data.rt.status));
- });
+ if (showLoading) dispatch(toggle_loading(1));
+ return fetch('/api/leone/getleonelist', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(leone_list(json.data.record, json.data.rt.status));
+ });
}
export const del_leone = (data) => dispatch => {
- dispatch(leone_api('/api/leone/delleone', data));
+ dispatch(leone_api('/api/leone/delleone', data));
}
export const add_leone = data => dispatch => {
- dispatch(leone_api('/api/leone/addleone', data));
+ dispatch(leone_api('/api/leone/addleone', data));
}
export const edit_leone = data => dispatch => {
- dispatch(leone_api('/api/leone/editleone', data));
+ dispatch(leone_api('/api/leone/editleone', data));
}
const leone_api = (url, data) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_leone_list());
- });
+ dispatch(toggle_loading(1));
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_leone_list());
+ });
}
const clear_scan = () => ({
- type: 'leone_clear_scan'
+ type: 'leone_clear_scan'
})
const set_scanning = () => ({
- type: 'leone_scanning'
+ type: 'leone_scanning'
})
const show_scan_leone = (list) => ({
- type: 'leone_scan',
- list
+ type: 'leone_scan',
+ list
});
const leone_list = (list, status) => ({
- type: 'leone_list',
- list,
- status
+ type: 'leone_list',
+ list,
+ status
})
export const io_cmd = (data, cb = null) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/iocmd/iocmd', getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- if(cb && typeof cb == 'function') return cb();
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/iocmd/iocmd', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ if (cb && typeof cb == 'function') return cb();
+ });
}
export const get_iogroup_list = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/iogroup/getiogrouplist', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(iogroup_list(json.data.record, json.data.rt.do, json.data.rt.leone));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/iogroup/getiogrouplist', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(iogroup_list(json.data.record, json.data.rt.do, json.data.rt.leone));
+ });
}
const iogroup_list = (list, doa, leone) => ({
- type: 'iogroup_list',
- list,
- do: doa,
- leone
+ type: 'iogroup_list',
+ list,
+ do: doa,
+ leone
});
const group_api = (url, data) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_iogroup_list());
- });
+ dispatch(toggle_loading(1));
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_iogroup_list());
+ });
}
export const del_iogroup = (data) => dispatch => {
- dispatch(group_api('/api/iogroup/deliogroup', data));
+ dispatch(group_api('/api/iogroup/deliogroup', data));
}
export const add_iogroup = (data) => dispatch => {
- dispatch(group_api('/api/iogroup/addiogroup', data));
+ dispatch(group_api('/api/iogroup/addiogroup', data));
}
export const edit_iogroup = (data) => dispatch => {
- dispatch(group_api('/api/iogroup/editiogroup', data));
+ dispatch(group_api('/api/iogroup/editiogroup', data));
}
export const get_select_list = (data) => dispatch => {
- return fetch('/api/system/getselectlist', getRequest(data))
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(select_list(json.data.record || []));
- })
+ return fetch('/api/system/getselectlist', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(select_list(json.data.record || []));
+ })
}
export const clear_select_list = () => ({
- type: 'clear_select_list'
+ type: 'clear_select_list'
})
const select_list = (list) => ({
- type: 'select_list',
- list
+ type: 'select_list',
+ list
})
const schedule_api = (url, data) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(get_schedule_list());
- })
+ dispatch(toggle_loading(1));
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(get_schedule_list());
+ })
}
const schedule_list = (list, dos, les, ios) => ({
- type: 'schedule_list',
- list,
- dos,
- les,
- ios
+ type: 'schedule_list',
+ list,
+ dos,
+ les,
+ ios
});
export const get_schedule_list = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/schedule/getschedulelist', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- return dispatch(schedule_list(json.data.record || [], json.data.rt.do || [], json.data.rt.leone || [], json.data.rt.iogroup || []));
- })
+ dispatch(toggle_loading(1));
+ return fetch('/api/schedule/getschedulelist', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ return dispatch(schedule_list(json.data.record || [], json.data.rt.do || [], json.data.rt.leone || [], json.data.rt.iogroup || []));
+ })
}
export const add_schedule = (data) => dispatch => {
- dispatch(schedule_api('/api/schedule/addschedule', data));
+ dispatch(schedule_api('/api/schedule/addschedule', data));
}
export const del_schedule = (data) => dispatch => {
- dispatch(schedule_api('/api/schedule/delschedule', data));
+ dispatch(schedule_api('/api/schedule/delschedule', data));
}
export const edit_schedule = (data) => dispatch => {
- dispatch(schedule_api('/api/schedule/editschedule', data));
+ dispatch(schedule_api('/api/schedule/editschedule', data));
}
export const sw_schedule = (data) => dispatch => {
- dispatch(schedule_api('/api/schedule/swschedule', data));
+ dispatch(schedule_api('/api/schedule/swschedule', data));
}
export const clear_userlist = () => ({
- type: 'clear_userlist'
+ type: 'clear_userlist'
});
export const clear_dio = () => ({
- type: 'clear_dio'
+ type: 'clear_dio'
});
-export const clear_leone =() => ({
- type: 'clear_leone'
+export const clear_leone = () => ({
+ type: 'clear_leone'
});
export const clear_log = () => ({
- type: 'clear_log'
+ type: 'clear_log'
});
export const clear_iogroup = () => ({
- type: 'clear_iogroup'
+ type: 'clear_iogroup'
});
export const clear_schedule = () => ({
- type: 'clear_schedule'
+ type: 'clear_schedule'
});
export const get_modbus_list = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/modbus/getmodbuslist', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1 ) return dispatch(add_dialog_msg(json.message));
- dispatch(modbus_list(json.data.record || []));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/modbus/getmodbuslist', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(modbus_list(json.data.record || []));
+ });
}
const modbus_list = list => ({
- type: 'modbus_list',
- list
+ type: 'modbus_list',
+ list
});
export const clear_modbus = () => ({
- type: 'clear_modbus'
+ type: 'clear_modbus'
})
const modbus_api = (url, data) => dispatch => {
- dispatch(toggle_loading(1));
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(get_modbus_list());
- })
+ dispatch(toggle_loading(1));
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(get_modbus_list());
+ })
}
export const del_modbus = (data) => dispatch => {
- dispatch(modbus_api('/api/modbus/delmodbus', data));
+ dispatch(modbus_api('/api/modbus/delmodbus', data));
}
export const add_modbus = data => dispatch => {
- dispatch(modbus_api('/api/modbus/addmodbus', data));
+ dispatch(modbus_api('/api/modbus/addmodbus', data));
}
export const edit_modbus = data => dispatch => {
- dispatch(modbus_api('/api/modbus/editmodbus', data));
+ dispatch(modbus_api('/api/modbus/editmodbus', data));
}
export const get_mb_data = data => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/modbus/getmodbus', getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(mb_data(data.id, json.data.rt.iolist || [], json.data.rt.aioset || []));
- })
+ dispatch(toggle_loading(1));
+ return fetch('/api/modbus/getmodbus', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(mb_data(data.id, json.data.rt.iolist || [], json.data.rt.aioset || []));
+ })
}
const mb_data = (id, iolist, aioset) => ({
- type: 'mb_data',
- id,
- iolist,
- aioset
+ type: 'mb_data',
+ id,
+ iolist,
+ aioset
})
export const get_mb_iostatus = data => dispatch => {
- return fetch('/api/modbus/getiostatus', getRequest(data))
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(mb_iostatus(data.id, data.type, json.data.record || []));
- })
+ return fetch('/api/modbus/getiostatus', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(mb_iostatus(data.id, data.type, json.data.record || []));
+ })
}
const mb_iostatus = (id, iotype, list) => ({
- type: 'mb_iostatus',
- id,
- iotype,
- list
+ type: 'mb_iostatus',
+ id,
+ iotype,
+ list
});
const mb_iolist_api = (url, data) => dispatch => {
- dispatch(toggle_loading(1))
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(get_mb_data({id: data.devuid}));
- });
+ dispatch(toggle_loading(1))
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(get_mb_data({ id: data.devuid }));
+ });
}
const mb_aio_api = (url, data) => dispatch => {
- dispatch(toggle_loading(1))
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(get_mb_data({id: data.devuid}));
- });
+ dispatch(toggle_loading(1))
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(get_mb_data({ id: data.devuid }));
+ });
}
export const edit_mb_iolist = data => dispatch => {
- return dispatch(mb_iolist_api('/api/modbus/editiolist', data));
+ return dispatch(mb_iolist_api('/api/modbus/editiolist', data));
}
export const add_mb_iolist = data => dispatch => {
- return dispatch(mb_iolist_api('/api/modbus/addiolist', data));
+ return dispatch(mb_iolist_api('/api/modbus/addiolist', data));
}
export const del_mb_iolist = data => dispatch => {
- return dispatch(mb_iolist_api('/api/modbus/deliolist', data));
+ return dispatch(mb_iolist_api('/api/modbus/deliolist', data));
}
export const add_mb_aio = data => dispatch => {
- return dispatch(mb_aio_api('/api/modbus/addaioset', data));
+ return dispatch(mb_aio_api('/api/modbus/addaioset', data));
}
export const edit_mb_aio = data => dispatch => {
- return dispatch(mb_aio_api('/api/modbus/editaioset', data));
+ return dispatch(mb_aio_api('/api/modbus/editaioset', data));
}
export const del_mb_aio = data => dispatch => {
- return dispatch(mb_aio_api('/api/modbus/delaioset', data));
+ return dispatch(mb_aio_api('/api/modbus/delaioset', data));
}
export const get_mb_log = data => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/modbus/getmodbuslog', getRequest(data))
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(mb_log(json.data.record || []));
- });
+ dispatch(toggle_loading(1));
+ return fetch('/api/modbus/getmodbuslog', getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(mb_log(json.data.record || []));
+ });
}
const mb_log = (list) => ({
- type: 'mb_log',
- list
+ type: 'mb_log',
+ list
});
export const get_link_list = () => dispatch => {
- dispatch(toggle_loading(1));
- return fetch('/api/link/getlinklist', getRequest())
- .then(response => response.json())
- .then(json => {
- dispatch(toggle_loading(0));
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(link_list(json.data.record || []))
- })
+ dispatch(toggle_loading(1));
+ return fetch('/api/link/getlinklist', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ dispatch(toggle_loading(0));
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(link_list(json.data.record || []))
+ })
}
const link_list = (list) => ({
- type: 'link_list',
- list
+ type: 'link_list',
+ list
})
export const clear_link = () => ({
- type: 'clear_link'
+ type: 'clear_link'
})
const link_api = (url, data) => dispatch => {
- return fetch(url, getRequest(data))
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- dispatch(get_link_list());
- })
+ return fetch(url, getRequest(data))
+ .then(response => response.json())
+ .then(json => {
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ dispatch(get_link_list());
+ })
}
export const add_link = (data) => dispatch => {
- dispatch(link_api('/api/link/addlink', data));
+ dispatch(link_api('/api/link/addlink', data));
}
export const del_link = (data) => dispatch => {
- dispatch(link_api('/api/link/dellink', data));
+ dispatch(link_api('/api/link/dellink', data));
}
export const sw_link_active = (data) => dispatch => {
- dispatch(link_api('/api/link/swlinkactive', data));
+ dispatch(link_api('/api/link/swlinkactive', data));
}
export const get_dashboard = () => dispatch => {
- return fetch('/api/system/dashboard', getRequest())
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return dispatch(add_dialog_msg(json.message));
- let rt = json.data.rt;
- dispatch(dashboard(rt.ip[0]? rt.ip[0].ip : '', rt.version[0]? rt.version[0].version : '', rt.di, rt.leone))
- })
+ return fetch('/api/system/dashboard', getRequest())
+ .then(response => response.json())
+ .then(json => {
+ if (json.status != 1) return dispatch(add_dialog_msg(json.message));
+ let rt = json.data.rt;
+ dispatch(dashboard(rt.ip[0] ? rt.ip[0].ip : '', rt.version[0] ? rt.version[0].version : '', rt.di, rt.leone))
+ })
}
const dashboard = (ip, version, di, leone) => ({
- type: 'dashboard',
- ip,
- version,
- di,
- leone
+ type: 'dashboard',
+ ip,
+ version,
+ di,
+ leone
})
export const toggle_dashboard = (flag) => ({
- type: flag ? 'ui_show_dashboard' : 'ui_hide_dashboard'
+ type: flag ? 'ui_show_dashboard' : 'ui_hide_dashboard'
})
export const clear_dashboard = () => ({
- type: 'clear_dashboard'
+ type: 'clear_dashboard'
})
\ No newline at end of file
diff --git a/src/components/AdminPage/Wristband/Location/index.js b/src/components/AdminPage/Wristband/Location/index.js
index 4713214..a8409f7 100644
--- a/src/components/AdminPage/Wristband/Location/index.js
+++ b/src/components/AdminPage/Wristband/Location/index.js
@@ -75,13 +75,15 @@ class Location extends React.Component {
delLocation = (id) => {
if(!id) return ;
- let {showDialog} = this.props;
- fetch('/api/wristband/dellocation', getRequest({id}))
- .then(response => response.json())
- .then(json => {
- if(json.status != 1) return showDialog(json.message);
- this.getList();
- })
+ let {showDialog, callConfirm} = this.props;
+ callConfirm('確定要刪除這筆定位點資料?', ()=>{
+ fetch('/api/wristband/dellocation', getRequest({id}))
+ .then(response => response.json())
+ .then(json => {
+ if(json.status != 1) return showDialog(json.message);
+ this.getList();
+ })
+ })
}
render() {
diff --git a/src/components/AdminPage/Wristband/WristbandInfo/index.js b/src/components/AdminPage/Wristband/WristbandInfo/index.js
index 3219428..0b2cbfe 100644
--- a/src/components/AdminPage/Wristband/WristbandInfo/index.js
+++ b/src/components/AdminPage/Wristband/WristbandInfo/index.js
@@ -44,13 +44,16 @@ class WristbandInfo extends React.Component {
delWristband = (id) => {
if(!id) return ;
+ let {showDialog, callConfirm} = this.props;
- fetch('/api/wristband/delwristband', getRequest({id}))
- .then(response=>response.json())
- .then(json=>{
- if(json.status!=1) return showDialog(json.message);
- this.getList();
- })
+ callConfirm('確定要刪除這筆手環資料?', ()=>{
+ fetch('/api/wristband/delwristband', getRequest({id}))
+ .then(response=>response.json())
+ .then(json=>{
+ if(json.status!=1) return showDialog(json.message);
+ this.getList();
+ })
+ })
}
openModal = (type, data = {}) => {
diff --git a/src/components/ConfirmBox.js b/src/components/ConfirmBox.js
new file mode 100644
index 0000000..d170b43
--- /dev/null
+++ b/src/components/ConfirmBox.js
@@ -0,0 +1,15 @@
+import React from 'react';
+import {Modal, Button} from 'semantic-ui-react';
+
+const ConfirmBox = ({obj, getNext}) => (
+