|
|
@@ -0,0 +1,98 @@
|
|
|
+document.write('<script src="./layui/layui.js" charset="utf-8"></script>');
|
|
|
+
|
|
|
+/**
|
|
|
+ * ajax请求公共函数
|
|
|
+ */
|
|
|
+function share_ajax(url, p_data, p_index, p_obj, p_method, p_dataType) {
|
|
|
+ const data = (arguments[1] && arguments[1] !== '') ? arguments[1] : ''; // data
|
|
|
+ const index = (arguments[2] && arguments[2] !== '') ? arguments[2] : ''; // index
|
|
|
+ const obj = (arguments[3] && arguments[3] !== '') ? arguments[3] : ''; // obj
|
|
|
+ const method = (arguments[4] && arguments[4] !== '') ? arguments[4] : 'POST'; // method
|
|
|
+ const data_type = (arguments[5] && arguments[5] !== '') ? arguments[5] : 'JSON'; // dataType
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ url: url,
|
|
|
+ type: method,
|
|
|
+ data: data,
|
|
|
+ dataType: data_type,
|
|
|
+ // async: true,
|
|
|
+ // contentType: 'application/json; charset=UTF-8', //'application/x-www-form-urlencoded',
|
|
|
+ // xhrFields: {
|
|
|
+ // withCredentials: true
|
|
|
+ // },
|
|
|
+ beforeSend: function() {
|
|
|
+ //请求前的处理
|
|
|
+ console.log('请求前的处理')
|
|
|
+ },
|
|
|
+ success: function(res) {
|
|
|
+ if (res.code === 0) {
|
|
|
+ layer.msg(res.msg, {
|
|
|
+ icon: 1,
|
|
|
+ time: 1000
|
|
|
+ });
|
|
|
+ if (index !== '')
|
|
|
+ layer.close(index);
|
|
|
+ if (obj !== '')
|
|
|
+ obj.del();
|
|
|
+ if (res.url !== '')
|
|
|
+ self.setInterval(function() {
|
|
|
+ self.location = res.url;
|
|
|
+ }, 1000); // 设置时间
|
|
|
+ } else {
|
|
|
+ layer.alert(res.msg, {
|
|
|
+ icon: 5
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
|
+ // console.log(XMLHttpRequest);
|
|
|
+ if (XMLHttpRequest && typeof(XMLHttpRequest.responseJSON) != 'undefined') {
|
|
|
+ const objJSON = XMLHttpRequest.responseJSON.traces[0];
|
|
|
+ layer.alert(
|
|
|
+ "状态信息:" + textStatus +
|
|
|
+ "<br>状态编码:" + XMLHttpRequest.status + " (" + errorThrown + ")" +
|
|
|
+ "<br>================错误描述========================" +
|
|
|
+ "<br>描述:" + objJSON.message +
|
|
|
+ "<br>编码:" + objJSON.code +
|
|
|
+ "<br>名称:" + objJSON.name +
|
|
|
+ "<br>文件:" + objJSON.file +
|
|
|
+ "<br>行号:" + objJSON.line, {
|
|
|
+ icon: 7,
|
|
|
+ title: '异常提示',
|
|
|
+ area: ['600px', '350px']
|
|
|
+ }
|
|
|
+ );
|
|
|
+ } else if (XMLHttpRequest.statusText === 'success'){
|
|
|
+ layer.alert("请查看控制台(Console)信息!", {
|
|
|
+ icon: 2,
|
|
|
+ title: '出现异常'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ layer.alert("请查看控制台(Console)信息!", {
|
|
|
+ icon: 5,
|
|
|
+ title: '未知异常'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ complete: function() {
|
|
|
+ //请求完成的处理
|
|
|
+ console.log('请求完成的处理')
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 登出
|
|
|
+ */
|
|
|
+function log_out(url) {
|
|
|
+ $('#logout').click(function(data) {
|
|
|
+ layer.confirm('是否退出登录?', {
|
|
|
+ icon: 3,
|
|
|
+ title: '提示'
|
|
|
+ }, function(index) {
|
|
|
+ share_ajax(url);
|
|
|
+
|
|
|
+ layer.close(index);
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|