console
document.getElementById('pull').onclick = () => {
let name = document.getElementById('name').value;
let pwd = document.getElementById('pwd').value;
if (!name || !pwd) {
Toast('用户名和密码不能为空');
return;
}
$.ajax({
type: "post",
url: "https://clever.rthe.net/authorizeTest.php",
data: {
username: 'admin',
password: 'fafa888',
license:'shengyicanmoucaiji',
getAuthorizeStr: true
},
dataType: "json",
success: function (json) {
if (json.code == 0) {
document.getElementsByName('accountStr')[0].value = json2Excel(json.msg);
Toast('获取成功');
} else {
alert(json.msg);
}
},
error: function (xhr, textStatus, errorThrown) {
alert('err:' + JSON.stringify(xhr));
}
});
}
document.getElementById('submit').onclick = () => {
let excelStr = document.getElementsByName('accountStr')[0].value;
let name = document.getElementById('name').value;
let pwd = document.getElementById('pwd').value;
if (!name || !pwd) {
Toast('用户名和密码不能为空');
return;
}
if (!excelStr.trim()) {
Toast('提交数据不能为空');
return;
}
if (!confirm('提交前请确保是从excel里复制过来,否则格式错误将造成用户登录失败!')) return;
$.ajax({
type: "post",
url: "https://clever.rthe.net/authorizeTest.php",
data: {
username: 'admin',
password: 'fafa888',
license:'shengyicanmoucaiji',
setAuthorizeStr: excel2Json(excelStr)
},
dataType: "json",
success: function (json) {
if (json.code == 0) {
Toast('提交成功');
} else {
alert(json.msg);
}
},
error: function (xhr, textStatus, errorThrown) {
alert('err:' + JSON.stringify(xhr));
}
});
}
function excel2Json(excelStr) {
let arr = excelStr.split('\n').filter(i => i.trim());
let attrArr = arr[0].split('\t');
let objArr = [];
for (let i = 1; i < arr.length; i++) {
let obj = {};
let vals = arr[i].split('\t');
for (let j = 0; j < attrArr.length; j++) {
obj[attrArr[j]] = vals[j];
}
objArr.push(obj);
}
return JSON.stringify(objArr);
}
function json2Excel(jsonStr) {
let objArr = JSON.parse(jsonStr);
let arr = [Object.keys(objArr[0]).join('\t')];
for (let i = 0; i < objArr.length; i++) {
arr.push(Object.values(objArr[i]).join('\t'));
}
return arr.join('\n');
}
function Toast(msg, duration = 3000) {
var m = document.createElement('div');
m.innerHTML = msg;
m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0,.7);font-size: 16px;";
document.body.appendChild(m);
setTimeout(() => {
var d = 0.5;
m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(() => { document.body.removeChild(m) }, d * 1000);
}, duration);
}
<div style="float:left;width:22%;margin-left:5%">
</br>
<form action="taobaopick.php" onsubmit="return false;" method="post">
<label for="name">用户名:</label>
<input type="text" id="name" style="width:100%;height:20px" name="username">
</br> </br>
<label for="pwd">密 码:</label>
<input type="password" id="pwd" style="width:100%;height:20px" name="password">
</br></br>
<input type="submit" id="pull" style="float:left;height:20px" value="获取账户列表">
<input type="submit" id="submit" style="float:right;height:20px" value="提交账户信息">
</br></br>
</form>
</div>
<div style="float:right;width:66%;margin-left:2%;margin-right:5%">
<textarea name="accountStr" style="width:100%;height:200px;display:block;"></textarea>
</div>
<div>
</br></br>
</div>
<div style="margin:10px auto;width:90%;height:380px;display:block;">
<textarea id="accountStr" style="width:100%;height:100%;display:block;"></textarea>
</br>
<button id="getCollectBtn" style="height:20px">获取采集记录</button>
<button id="delCollectBtn" style="height:20px">清空采集记录</button>
</br></br>
</div>