add confirm box
This commit is contained in:
parent
27d2209ea2
commit
b07e51ef7c
@ -3,7 +3,7 @@
|
|||||||
* @param {string} msg
|
* @param {string} msg
|
||||||
* @param {function} act
|
* @param {function} act
|
||||||
*/
|
*/
|
||||||
export const add_dialog_msg =(msg, act) => ({
|
export const add_dialog_msg = (msg, act) => ({
|
||||||
type: 'dialog_addmsg',
|
type: 'dialog_addmsg',
|
||||||
msg: msg,
|
msg: msg,
|
||||||
act: act || null
|
act: act || null
|
||||||
@ -16,6 +16,16 @@ 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
|
* set i18next object
|
||||||
* @param {object} i18n i18next object
|
* @param {object} i18n i18next object
|
||||||
@ -52,12 +62,12 @@ export const getRequest = (data = {}) => {
|
|||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
mode:'cors'
|
mode: 'cors'
|
||||||
};
|
};
|
||||||
let token = sessionStorage.getItem('token');
|
let token = sessionStorage.getItem('token');
|
||||||
if(token) json.headers['x-auth-token'] = token;
|
if (token) json.headers['x-auth-token'] = token;
|
||||||
|
|
||||||
json.body = JSON.stringify({data});
|
json.body = JSON.stringify({ data });
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
@ -68,11 +78,11 @@ export const get_network_info = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1){
|
if (json.status != 1) {
|
||||||
return dispatch(add_dialog_msg(json.message));
|
return dispatch(add_dialog_msg(json.message));
|
||||||
}
|
}
|
||||||
let j = {};
|
let j = {};
|
||||||
if('data' in json && 'record' in json.data && json.data.record.length > 0) j = json.data.record[0];
|
if ('data' in json && 'record' in json.data && json.data.record.length > 0) j = json.data.record[0];
|
||||||
return dispatch(network_info(j));
|
return dispatch(network_info(j));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -87,7 +97,7 @@ export const set_network_info = (dhcpMode, ip, netmask, gateway, dns) => dispatc
|
|||||||
let type = dhcpMode ? 'dhcp' : 'manual';
|
let type = dhcpMode ? 'dhcp' : 'manual';
|
||||||
let req = getRequest();
|
let req = getRequest();
|
||||||
let json = {
|
let json = {
|
||||||
data:{
|
data: {
|
||||||
type,
|
type,
|
||||||
ip,
|
ip,
|
||||||
netmask,
|
netmask,
|
||||||
@ -100,7 +110,7 @@ export const set_network_info = (dhcpMode, ip, netmask, gateway, dns) => dispatc
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_network_info());
|
return dispatch(get_network_info());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -111,11 +121,11 @@ export const get_system_time = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1){
|
if (json.status != 1) {
|
||||||
return dispatch(add_dialog_msg(json.message));
|
return dispatch(add_dialog_msg(json.message));
|
||||||
}
|
}
|
||||||
let t = '';
|
let t = '';
|
||||||
if('data' in json && 'record' in json.data && json.data.record.length > 0) t = json.data.record[0].time;
|
if ('data' in json && 'record' in json.data && json.data.record.length > 0) t = json.data.record[0].time;
|
||||||
return dispatch(system_time(t));
|
return dispatch(system_time(t));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -127,12 +137,12 @@ const system_time = (time) => ({
|
|||||||
|
|
||||||
export const set_system_time = time => dispatch => {
|
export const set_system_time = time => dispatch => {
|
||||||
dispatch(toggle_loading(1));
|
dispatch(toggle_loading(1));
|
||||||
let req = getRequest({time});
|
let req = getRequest({ time });
|
||||||
return fetch('/api/system/updatetime', req)
|
return fetch('/api/system/updatetime', req)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_system_time());
|
return dispatch(get_system_time());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -144,7 +154,7 @@ export const get_user_list = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(user_list(json.data.record));
|
return dispatch(user_list(json.data.record));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -161,7 +171,7 @@ const userApi = (url, data = {}) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_user_list());
|
return dispatch(get_user_list());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -184,7 +194,7 @@ export const get_dio_info = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(dioinfo(json.data.rt.do || [], json.data.rt.di || []));
|
return dispatch(dioinfo(json.data.rt.do || [], json.data.rt.di || []));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -193,7 +203,7 @@ export const get_dio_status = () => dispatch => {
|
|||||||
return fetch('/api/dio/getio', getRequest())
|
return fetch('/api/dio/getio', getRequest())
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(diostatus(json.data.rt.do, json.data.rt.di));
|
return dispatch(diostatus(json.data.rt.do, json.data.rt.di));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -202,7 +212,7 @@ export const set_do_status = (data) => dispatch => {
|
|||||||
return fetch('/api/dio/dotrun', getRequest(data))
|
return fetch('/api/dio/dotrun', getRequest(data))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +222,7 @@ export const set_dio_info = (data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_dio_info());
|
return dispatch(get_dio_info());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -229,11 +239,11 @@ const dioinfo = (dod, did) => ({
|
|||||||
|
|
||||||
export const get_log_list = (p = 1) => dispatch => {
|
export const get_log_list = (p = 1) => dispatch => {
|
||||||
dispatch(toggle_loading(1));
|
dispatch(toggle_loading(1));
|
||||||
return fetch('/api/log/getlog', getRequest({p}))
|
return fetch('/api/log/getlog', getRequest({ p }))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(loglist(json.data.record, json.data.page));
|
return dispatch(loglist(json.data.record, json.data.page));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -251,9 +261,9 @@ export const scan_leone = (data) => (dispatch, getState) => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
let {i18n} = getState();
|
let { i18n } = getState();
|
||||||
if(json.data.record.length == 0) return dispatch(add_dialog_msg(i18n&&i18n.t? i18n.t('tip.scan_empty') : ''));
|
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));
|
return dispatch(show_scan_leone(json.data.record));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -264,7 +274,7 @@ export const clear_scan_leone = (clrRemote = false) => dispatch => {
|
|||||||
return fetch('/api/leone/clearscanleone', getRequest())
|
return fetch('/api/leone/clearscanleone', getRequest())
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
return ;
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,18 +286,18 @@ export const add_scan_leone = (data) => dispatch => {
|
|||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
dispatch(clear_scan());
|
dispatch(clear_scan());
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_leone_list());
|
return dispatch(get_leone_list());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const get_leone_list = (showLoading = true) => dispatch => {
|
export const get_leone_list = (showLoading = true) => dispatch => {
|
||||||
if(showLoading) dispatch(toggle_loading(1));
|
if (showLoading) dispatch(toggle_loading(1));
|
||||||
return fetch('/api/leone/getleonelist', getRequest())
|
return fetch('/api/leone/getleonelist', getRequest())
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(leone_list(json.data.record, json.data.rt.status));
|
return dispatch(leone_list(json.data.record, json.data.rt.status));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -310,7 +320,7 @@ const leone_api = (url, data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_leone_list());
|
return dispatch(get_leone_list());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -340,8 +350,8 @@ export const io_cmd = (data, cb = null) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
if(cb && typeof cb == 'function') return cb();
|
if (cb && typeof cb == 'function') return cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +361,7 @@ export const get_iogroup_list = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
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));
|
return dispatch(iogroup_list(json.data.record, json.data.rt.do, json.data.rt.leone));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -369,7 +379,7 @@ const group_api = (url, data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_iogroup_list());
|
return dispatch(get_iogroup_list());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -390,7 +400,7 @@ export const get_select_list = (data) => dispatch => {
|
|||||||
return fetch('/api/system/getselectlist', getRequest(data))
|
return fetch('/api/system/getselectlist', getRequest(data))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(select_list(json.data.record || []));
|
return dispatch(select_list(json.data.record || []));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -409,7 +419,7 @@ const schedule_api = (url, data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
return dispatch(get_schedule_list());
|
return dispatch(get_schedule_list());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -428,7 +438,7 @@ export const get_schedule_list = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
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 || []));
|
return dispatch(schedule_list(json.data.record || [], json.data.rt.do || [], json.data.rt.leone || [], json.data.rt.iogroup || []));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -452,7 +462,7 @@ export const clear_userlist = () => ({
|
|||||||
export const clear_dio = () => ({
|
export const clear_dio = () => ({
|
||||||
type: 'clear_dio'
|
type: 'clear_dio'
|
||||||
});
|
});
|
||||||
export const clear_leone =() => ({
|
export const clear_leone = () => ({
|
||||||
type: 'clear_leone'
|
type: 'clear_leone'
|
||||||
});
|
});
|
||||||
export const clear_log = () => ({
|
export const clear_log = () => ({
|
||||||
@ -471,7 +481,7 @@ export const get_modbus_list = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1 ) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(modbus_list(json.data.record || []));
|
dispatch(modbus_list(json.data.record || []));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -491,7 +501,7 @@ const modbus_api = (url, data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(get_modbus_list());
|
dispatch(get_modbus_list());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -514,7 +524,7 @@ export const get_mb_data = data => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
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(mb_data(data.id, json.data.rt.iolist || [], json.data.rt.aioset || []));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -530,7 +540,7 @@ export const get_mb_iostatus = data => dispatch => {
|
|||||||
return fetch('/api/modbus/getiostatus', getRequest(data))
|
return fetch('/api/modbus/getiostatus', getRequest(data))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(mb_iostatus(data.id, data.type, json.data.record || []));
|
dispatch(mb_iostatus(data.id, data.type, json.data.record || []));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -548,8 +558,8 @@ const mb_iolist_api = (url, data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(get_mb_data({id: data.devuid}));
|
dispatch(get_mb_data({ id: data.devuid }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,8 +569,8 @@ const mb_aio_api = (url, data) => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(get_mb_data({id: data.devuid}));
|
dispatch(get_mb_data({ id: data.devuid }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,7 +600,7 @@ export const get_mb_log = data => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(mb_log(json.data.record || []));
|
dispatch(mb_log(json.data.record || []));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -606,7 +616,7 @@ export const get_link_list = () => dispatch => {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
dispatch(toggle_loading(0));
|
dispatch(toggle_loading(0));
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(link_list(json.data.record || []))
|
dispatch(link_list(json.data.record || []))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -623,7 +633,7 @@ const link_api = (url, data) => dispatch => {
|
|||||||
return fetch(url, getRequest(data))
|
return fetch(url, getRequest(data))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
dispatch(get_link_list());
|
dispatch(get_link_list());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -642,9 +652,9 @@ export const get_dashboard = () => dispatch => {
|
|||||||
return fetch('/api/system/dashboard', getRequest())
|
return fetch('/api/system/dashboard', getRequest())
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return dispatch(add_dialog_msg(json.message));
|
if (json.status != 1) return dispatch(add_dialog_msg(json.message));
|
||||||
let rt = json.data.rt;
|
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))
|
dispatch(dashboard(rt.ip[0] ? rt.ip[0].ip : '', rt.version[0] ? rt.version[0].version : '', rt.di, rt.leone))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,13 +75,15 @@ class Location extends React.Component {
|
|||||||
|
|
||||||
delLocation = (id) => {
|
delLocation = (id) => {
|
||||||
if(!id) return ;
|
if(!id) return ;
|
||||||
let {showDialog} = this.props;
|
let {showDialog, callConfirm} = this.props;
|
||||||
|
callConfirm('確定要刪除這筆定位點資料?', ()=>{
|
||||||
fetch('/api/wristband/dellocation', getRequest({id}))
|
fetch('/api/wristband/dellocation', getRequest({id}))
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => {
|
.then(json => {
|
||||||
if(json.status != 1) return showDialog(json.message);
|
if(json.status != 1) return showDialog(json.message);
|
||||||
this.getList();
|
this.getList();
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -44,13 +44,16 @@ class WristbandInfo extends React.Component {
|
|||||||
|
|
||||||
delWristband = (id) => {
|
delWristband = (id) => {
|
||||||
if(!id) return ;
|
if(!id) return ;
|
||||||
|
let {showDialog, callConfirm} = this.props;
|
||||||
|
|
||||||
|
callConfirm('確定要刪除這筆手環資料?', ()=>{
|
||||||
fetch('/api/wristband/delwristband', getRequest({id}))
|
fetch('/api/wristband/delwristband', getRequest({id}))
|
||||||
.then(response=>response.json())
|
.then(response=>response.json())
|
||||||
.then(json=>{
|
.then(json=>{
|
||||||
if(json.status!=1) return showDialog(json.message);
|
if(json.status!=1) return showDialog(json.message);
|
||||||
this.getList();
|
this.getList();
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
openModal = (type, data = {}) => {
|
openModal = (type, data = {}) => {
|
||||||
|
15
src/components/ConfirmBox.js
Normal file
15
src/components/ConfirmBox.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {Modal, Button} from 'semantic-ui-react';
|
||||||
|
|
||||||
|
const ConfirmBox = ({obj, getNext}) => (
|
||||||
|
<Modal open={obj && obj.msg != '' ? true : false} onClose={() => getNext()} style={{zIndex: "2001"}}>
|
||||||
|
<Modal.Content>{obj && obj.msg ? obj.msg : ''}</Modal.Content>
|
||||||
|
<Modal.Actions>
|
||||||
|
<Button onClick={() => getNext(true, obj.act)} content="Submit" />
|
||||||
|
<Button onClick={() => getNext()} content="Cancel" />
|
||||||
|
</Modal.Actions>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
export default ConfirmBox;
|
@ -1,5 +1,5 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { add_dialog_msg, toggle_loading } from '../../../actions';
|
import { add_dialog_msg, toggle_loading, add_confirm } from '../../../actions';
|
||||||
import LocationPage from '../../../components/AdminPage/Wristband/Location';
|
import LocationPage from '../../../components/AdminPage/Wristband/Location';
|
||||||
|
|
||||||
|
|
||||||
@ -13,6 +13,9 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
|
|||||||
},
|
},
|
||||||
toggleLoading: (flag = false) => {
|
toggleLoading: (flag = false) => {
|
||||||
dispatch(toggle_loading(flag));
|
dispatch(toggle_loading(flag));
|
||||||
|
},
|
||||||
|
callConfirm: (msg, act = null) => {
|
||||||
|
dispatch(add_confirm(msg, act))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { add_dialog_msg, toggle_loading } from '../../../actions';
|
import { add_dialog_msg, toggle_loading, add_confirm } from '../../../actions';
|
||||||
import WristbandInfo from '../../../components/AdminPage/Wristband/WristbandInfo';
|
import WristbandInfo from '../../../components/AdminPage/Wristband/WristbandInfo';
|
||||||
|
|
||||||
|
|
||||||
@ -13,6 +13,9 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
|
|||||||
},
|
},
|
||||||
toggleLoading: (flag = false) => {
|
toggleLoading: (flag = false) => {
|
||||||
dispatch(toggle_loading(flag));
|
dispatch(toggle_loading(flag));
|
||||||
|
},
|
||||||
|
callConfirm: (msg, act = null) => {
|
||||||
|
dispatch(add_confirm(msg, act))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {connect} from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {add_dialog_msg, toggle_loading} from '../../../actions';
|
import { add_dialog_msg, toggle_loading, add_confirm } from '../../../actions';
|
||||||
import WristbandPage from '../../../components/AdminPage/Wristband';
|
import WristbandPage from '../../../components/AdminPage/Wristband';
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import Datetime from 'react-datetime';
|
|||||||
import MainMenu from '../../containers/MenuControl';
|
import MainMenu from '../../containers/MenuControl';
|
||||||
import Loading from '../../containers/LoadingControl';
|
import Loading from '../../containers/LoadingControl';
|
||||||
import Dialog from '../DialogControl';
|
import Dialog from '../DialogControl';
|
||||||
|
import ConfirmBox from '../ConfirmControl';
|
||||||
import Dashboard from '../../containers/DashBoard';
|
import Dashboard from '../../containers/DashBoard';
|
||||||
import {toggle_dashboard} from '../../actions'
|
import {toggle_dashboard} from '../../actions'
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ class AdmPage extends React.Component {
|
|||||||
<div style={{height: '100%'}}>
|
<div style={{height: '100%'}}>
|
||||||
<Loading />
|
<Loading />
|
||||||
<Dialog />
|
<Dialog />
|
||||||
|
<ConfirmBox />
|
||||||
<MainMenu i18n={i18n} >
|
<MainMenu i18n={i18n} >
|
||||||
<Dashboard />
|
<Dashboard />
|
||||||
{children}
|
{children}
|
||||||
|
19
src/containers/ConfirmControl.js
Normal file
19
src/containers/ConfirmControl.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import ConfirmBox from '../components/ConfirmBox';
|
||||||
|
import { remove_confirm } from '../actions'
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
obj: state.confirmbox[0] || null
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||||
|
getNext: (doit = false, act = null) => {
|
||||||
|
//get next dialog message
|
||||||
|
if (doit) {
|
||||||
|
if (typeof act == 'function') act();
|
||||||
|
}
|
||||||
|
dispatch(remove_confirm());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(ConfirmBox);
|
15
src/reducers/confirmbox.js
Normal file
15
src/reducers/confirmbox.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const confirmbox = (state = [], action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'confirm_addmsg':
|
||||||
|
return [...state, {
|
||||||
|
msg: action.msg,
|
||||||
|
act: action.act || null
|
||||||
|
}];
|
||||||
|
case 'confirm_remove':
|
||||||
|
return state.slice(1);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default confirmbox;
|
@ -1,16 +1,18 @@
|
|||||||
import {combineReducers} from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
import dialog from './dialog';
|
import dialog from './dialog';
|
||||||
import i18n from './i18n';
|
import i18n from './i18n';
|
||||||
import ui from './ui';
|
import ui from './ui';
|
||||||
import sysinfo from './sysinfo';
|
import sysinfo from './sysinfo';
|
||||||
import lists from './lists';
|
import lists from './lists';
|
||||||
|
import confirmbox from './confirmbox';
|
||||||
|
|
||||||
const reducers = combineReducers({
|
const reducers = combineReducers({
|
||||||
dialog,
|
dialog,
|
||||||
i18n,
|
i18n,
|
||||||
ui,
|
ui,
|
||||||
sysinfo,
|
sysinfo,
|
||||||
lists
|
lists,
|
||||||
|
confirmbox
|
||||||
});
|
});
|
||||||
|
|
||||||
export default reducers;
|
export default reducers;
|
Loading…
Reference in New Issue
Block a user