var _token="";
var dataToSend = "username=createProjectTask&password=M%2BR86EsyNsiHT9Fxz8bZSg%3D%3D";
var _url="https://www.baidu.com:8443/login";
$.ajax({
type:"POST",
url: _url,
contentType: "application/x-www-form-urlencoded",
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
},
data: dataToSend,
async: false,
success: function (response) {
//debugger
console.log("服务器返回的数据:", response);
if (response && response.data && 'usertoken' in response.data) {
_token = response.data.usertoken;
}
},
error: function (xhr, status, error) {
console.log("请求出错:", error);
}
});
if( _token==""){
alert("未获取到授权!");
return;
}
//获取32位随机码
function generateRandomCode() {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const randomBytes = window.crypto.getRandomValues(new Uint8Array(32));
let randomCode = '';
for (let i = 0; i < 32; i++) {
const index = randomBytes[i] % characters.length;
randomCode += characters.charAt(index);
}
return randomCode;
}
const randomCode = generateRandomCode();
console.log(randomCode);
// 对用户名和密码进行Base64编码,生成Basic Auth需要的认证字符串
var username = "user_123";
var password = "pwd123";
var credentials = btoa(username + ":" + password);
//alert("base64加密后的值:"+credentials);
// 创建Date对象获取当前时间
var currentDate = new Date();
// 获取年、月、日、时、分、秒,并进行格式化处理
var year = currentDate.getFullYear();
var month = ('0' + (currentDate.getMonth() + 1)).slice(-2);
var day = ('0' + currentDate.getDate()).slice(-2);
var hours = ('0' + currentDate.getHours()).slice(-2);
var minutes = ('0' + currentDate.getMinutes()).slice(-2);
var seconds = ('0' + currentDate.getSeconds()).slice(-2);
// 拼接成指定格式的时间字符串
var formattedTime = year + month + day + hours + minutes + seconds;
console.log(formattedTime);
var _issubmit=false;
var boxes = _g().getWidgetsByName("box");
var checkedBoxesInfo = [];
var _index =16;
var _flag =false;
if (boxes.length > 0) {
for (var i = 0; i < boxes.length; i++) {
//debugger
if (boxes[i].getValue() === true) {
//对于置灰的跳过
_flag=false;
var b2name="B"+(i+2);
_flag = _g().getWidgetByCell(b2name).isEnabled();
//debugger
if(!_flag) continue;
_issubmit = true;
var boxInfo = {
//projectName: "任务名称",
projectName: _g().getCellValue(0, _index, i+1),
//planName: "测试0222",
planName: _g().getCellValue(0, _index+1, i+1),
taskSn: "2",
//taskSn: _g().getCellValue(0, _index+2, i+1),
//taskName: "02",
taskName: _g().getCellValue(0, _index+3, i+1),
//taskRemark: "测试11111",
taskRemark: _g().getCellValue(0, _index+4, i+1),
//planStartDate: "2024-12-01",
planStartDate: _g().getCellValue(0, _index+5, i+1),
//planEndDate: "2024-12-09",
planEndDate: _g().getCellValue(0, _index+6, i+1),
//ownerId: "00005713",
ownerId: _g().getCellValue(0, _index+7, i+1),
//auditorId: "00005713"
auditorId: _g().getCellValue(0, _index+8, i+1)
};
checkedBoxesInfo.push(boxInfo);
//const jsonString = JSON.stringify(boxInfo);
//console.info("boxInfo",boxInfo);
//alert(jsonString);
}
}
}
var resultJson = JSON.stringify(checkedBoxesInfo);
console.info("组装的record节点的JSON",resultJson);
if(!_issubmit){
alert("请勾选要推送的信息!");
return;
}
//alert(resultJson);
//debugger
//var _url="http://111.111.111.111:50000/save";
var a={
common:{
busid: '0050',
instld: randomCode,
sender: 'abc',
receiver:'bcd',
request_time: formattedTime
},
business: {
record: checkedBoxesInfo
}
};
console.info("组装的请求JSON : ",a);
$.ajax({
url:_url,
type: "POST",
data:JSON.stringify(a),
dataType: "json",
contentType: "application/json",
headers: {
"Content-Type": "application/json;charset=UTF-8",
"Authorization":credentials,
"usertoken":_token,
"itgAuthorizationKey":"YTY3NGExMGZmMGM1ZTIzY2Q1ZTk2MDE4NWQ2YzBmZTg="
},
timeout: 5000,
async: false,
success: function (response) {
debugger
console.info("response",response);
// 检查必要的节点是否存在
if (!response.business ||!response.common ||!response.common.returnMsg ||!response.common.returnStatus) {
alert("推送失败!");
return;
}
if (response.common.returnStatus === "S") {
_g().verifyAndWriteReport();
alert("推送完成!");
location.reload();
} else {
alert(response.common.returnMsg);
}
},
error: function (xhr, status, error) {
//debugger
console.info("请求失败:" + error);
alert("推送失败");
}
});