You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

460 lines
22 KiB

4 years ago
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>插件模板</title>
4 years ago
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@2.2.4/dist/tailwind.css">
<!-- <link rel="stylesheet" type="text/css" href="style.css" /> -->
<!-- <script type="text/javascript" src="plugin.js"></script> -->
4 years ago
</head>
4 years ago
<body>
<div class="">
<div class="h-10 w-full flex justify-center items-center border-b-2">项目名称</div>
4 years ago
<!-- 角色栏-->
4 years ago
<div class="w-full h-16 flex items-center border-b-2">
<div class="p-2 m-4">项目经理</div>
<div class="p-2 m-4 border-b-2 border-blue-500 text-blue-400">运维</div>
</div>
4 years ago
<div class="w-full p-4 bg-gray-100">
<!-- 日常任务面板-->
<div class="content p-3 h-46 bg-white rounded-lg">
<div class="h-6 mb-2 bg-gray-100"></div>
<div class="h-6 mb-2 bg-gray-100"></div>
<div class="h-6 mb-2 bg-gray-100"></div>
<div class="h-6 mb-2 bg-gray-100"></div>
<div class="h-6 bg-gray-100"></div>
4 years ago
</div>
</div>
4 years ago
<div class="task-bar h-100 w-full bg-gray-100 p-4">
4 years ago
<div class="flex mb-3">
<!-- <div class="flex flex-col items-center">
4 years ago
<div class="rounded-full h-8 w-8 mb-1 bg-gray-100 border-2 border-blue-500"></div>
<div class="w-8 flex-1 flex flex-col items-center">
<div class="w-0.5 flex-1 bg-gray-300"></div>
4 years ago
</div>
</div> -->
4 years ago
4 years ago
<div class="flex-1" style="height: 50rem;">
<div class="rounded-lg bg-white p-3" style="height: 100%;">
4 years ago
<button class="bg-blue-500 py-2 px-5 rounded text-white" onclick="alert('hello')">测试组建1</button>
<button class="bg-blue-500 py-2 px-5 rounded text-white" onclick="p100.show()">测试组建2</button>
4 years ago
<div data-tname="考勤" data-pid="1472861916249726976" data-uid="1217647686598135808" data-rid="rid333" data-tid="tid444" data-did="did555" style="height:50px;width:100%">
4 years ago
<div data-root="p1472866674721169408" style="height: 100%; width: 100%;">
<div class="formulate-plan mt-3">
4 years ago
<div class="p-2 border border-gray-200 rounded-sm text-sm">
4 years ago
<div class="temp flex justify-between items-center w-full">
<p class="w-20 flex-shrink-0 text-gray-400">选择模板</p>
<div class="flex items-center">
4 years ago
<span class="sel-temp-name mr-1">请选择红头文件模板</span>
4 years ago
<img style="width: 15px;" src="https://www.tall.wiki/staticrec/icon/right.svg" />
</div>
</div>
<div class="mt-2 temp-list flex items-center">
4 years ago
4 years ago
</div>
</div>
4 years ago
<div class="temp-box" id="form">
4 years ago
</div>
4 years ago
<div class="mt-4 flex justify-between items-center w-full text-sm">
4 years ago
<button class="border border-blue-500 text-blue-500 rounded-sm" style="width: 45%; height: 34px;" onclick="p1472866674721169408.bigImg()">预览</button>
<button class="border border-blue-500 bg-blue-500 text-white rounded-sm" style="width: 45%; height: 34px;" onclick="p1472866674721169408.submit()">提交</button>
4 years ago
</div>
<div class="img-preview fixed z-10 inset-0 bg-black bg-opacity-60 p-4 flex justify-center items-center" style="display: none;">
<img id="img" src="http://test.tall.wiki/staticrec/plan.png" />
</div>
</div>
</div>
</div>
4 years ago
<script>
4 years ago
document.getElementById("form").addEventListener("input", function(e){
4 years ago
p1472866674721169408.setData(e);
4 years ago
})
4 years ago
4 years ago
//事件委托就是利用事件冒泡特性,给父元素绑定事件
//parent.contains(child) 判断是否是某个节点的子节点
//e.target 触发事件的源节点
4 years ago
document.querySelector('.img-preview').onclick = function(e){
4 years ago
e = window.event || e;
let parentApp = document.getElementById('img');
if(!parentApp.contains(e.target)){
4 years ago
document.querySelector('.img-preview').style.display = 'none';
4 years ago
}
}
4 years ago
var p1472866674721169408 = {
token: '',
projectId: '',
roleId: '',
dom: '',
fileId: '', // 上传文件ID
filePath: '', // 上传文件路径
4 years ago
curStatus: 0, // 当前状态 0 未提交 1 已提交待审核
curIndex: 0, // 当前选择的模板
tempList: [{name: '模板1', organizer: '国家体育总局社会体育指导中心', title: ''}, {name: '模板2', organizer: '', title: ''}, {name: '模板3', organizer: '', title: ''}],
4 years ago
tempData: {},
init() {
4 years ago
this.dom = document.querySelector("div[data-root=p1472866674721169408]");
var domBox = this.dom.parentNode;
var title = this.dom.querySelector('.title');
// 获取父元素携带的参数
var userId = domBox.getAttribute("data-uid");
this.projectId = domBox.getAttribute("data-pid");
this.roleId = domBox.getAttribute("data-rid");
// 初始化的时候 获取token
this.getTokenByUserId(userId);
},
// 获取token
getTokenByUserId(userId){
var that = this
fetch(`https://www.tall.wiki/gateway/tall/v1.0/users/userId?userId=${userId}`)
.then(function(response) {
return response.json();
})
.then(function(res) {
const { success, code, data, msg } = res;
if (success && code === 200) {
that.token = data.token;
// 查询培训计划
that.getTrainPlan()
4 years ago
// 查询所有模板
that.getAllTemp();
} else {
console.log('msg: ', msg);
}
});
},
/**
* 查询当前培训计划
*/
getTrainPlan(){
4 years ago
var that = this;
4 years ago
fetch(`https://test.tall.wiki/gateway/sports/training/get`, {
4 years ago
headers: new Headers({
'Authorization': 'Bearer ' + that.token,
4 years ago
'Content-Type': 'application/json; charset=utf-8'
4 years ago
}),
method: 'POST',
4 years ago
body: JSON.stringify({
4 years ago
param: {projectId: that.projectId}
4 years ago
})
4 years ago
})
.then(function(response) {
return response.json();
})
.then(function(res) {
const { success, code, data, msg } = res;
if (success && code === 200) {
4 years ago
} else {
console.log('msg: ', msg);
}
});
},
/**
4 years ago
* 获取所有模板
*/
4 years ago
getAllTemp() {
var that = this;
4 years ago
fetch(`https://test.tall.wiki/gateway/sports/training/template`, {
headers: new Headers({
'Authorization': 'Bearer ' + that.token,
'Content-Type': 'application/json; charset=utf-8'
}),
method: 'POST',
body: JSON.stringify({
param: {projectId: that.projectId}
})
})
.then(function(response) {
return response.json();
})
.then(function(res) {
const { success, code, data, msg } = res;
if (success && code === 200) {
for (let i = 0; i < data.length; i++) {
if (data[i].type === 0) {
that.tempList = data[i].templateList;
}
}
that.renderTemp(); // 渲染模板
} else {
console.log('msg: ', msg);
}
});
},
4 years ago
/**
* 选择模板
*/
selTemp(index) {
4 years ago
let obj = this.tempList[index];
4 years ago
let tempName = document.querySelector('.sel-temp-name');
4 years ago
tempName.innerHTML = obj.name;
4 years ago
let temps = document.querySelectorAll('.temp-item');
for (let i = 0; i < temps.length; i++) {
temps[i].classList.remove("border-blue-400");
temps[i].classList.add("border-gray-200");
}
4 years ago
temps[index].classList.add("border-blue-400");
this.curIndex = index;
this.getTempData(obj.id);
},
// 根据模板id获取模板数据
getTempData(id) {
var that = this;
fetch(`https://test.tall.wiki/gateway/sports/training/templateId`, {
headers: new Headers({
'Authorization': 'Bearer ' + that.token,
'Content-Type': 'application/json; charset=utf-8'
}),
method: 'POST',
body: JSON.stringify({
param: {id: id}
})
})
.then(function(response) {
return response.json();
})
.then(function(res) {
const { success, code, data, msg } = res;
if (success && code === 200) {
for (let i = 0; i < data.length; i++) {
if (data[i].type === 0) {
that.tempList = data[i].templateList;
}
}
that.tempData = data;
that.renderTempData(); // 渲染模板数据
} else {
console.log('msg: ', msg);
}
});
},
// 渲染模板
renderTemp() {
let that = this;
// this.tempList
let html = '';
for (let j = 0; j < that.tempList.length; j++) {
4 years ago
html += `<div class="temp-item border border-gray-200 flex justify-center items-center ${j > 2 ? 'mt-2' : ''}" style="width: 30%; height: 100px; ${j % 3 == 2 ? '' : 'margin-right: 5%;'}" onclick="p1472866674721169408.selTemp(${j})">
4 years ago
<img style="max-width: 100%; max-height: 100%;" src="${that.tempList[j].path}" />
</div>`;
}
that.dom.querySelector('.temp-list').innerHTML = html;
},
// 渲染模板数据
renderTempData() {
4 years ago
let that = this;
4 years ago
let html = '';
4 years ago
for (let i = 0; i < that.tempData.length; i++) {
let data = that.tempData[i];
4 years ago
if (data.type === 1) {
4 years ago
html += `<div class="ques-box mt-2.5 px-2 py-1.5 w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">
4 years ago
<div class="flex justify-between items-center w-full" style="height: 20px;">
<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>
4 years ago
<input data-id="${data.questionId}" class="train-name text-right outline-none" style="width: calc(100% - 6rem)" type="text" placeholder="请输入${data.question}" />
4 years ago
</div>
</div>`;
} else if (data.type === 2) {
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full h-16 border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">
<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>
4 years ago
<textarea data-id="${data.questionId}" class="train-desc text-right outline-none" style="width: calc(100% - 6rem)" placeholder="请输入${data.question}"></textarea>
4 years ago
</div>`;
} else if (data.type === 3) {
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">`;
html += `<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>`;
html += `<div class="flex items-center flex-wrap justify-end">`;
for (let j = 0; j < data.optionList.length; j++) {
4 years ago
html += `<label class="ml-3 my-1 flex items-center"><input class="mr-1.5" name="Fruit" type="radio" data-id="${data.questionId}" value="${data.optionList[j].submitValue}" />${data.optionList[j].showValue}</label>`;
4 years ago
}
html += `</div>`;
html += `</div>`;
} else if (data.type === 4) {
4 years ago
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">`;
html += `<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>`;
html += `<div class="flex items-center flex-wrap justify-end">`;
for (let j = 0; j < data.optionList.length; j++) {
html += `<label class="ml-3 my-1 flex items-center"><input class="mr-1.5" name="Fruit" type="checkbox" data-id="${data.questionId}" value="${data.optionList[j].submitValue}" />${data.optionList[j].showValue}</label>`;
}
html += `</div>`;
html += `</div>`;
4 years ago
} else if (data.type === 5) {
4 years ago
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">`;
html += `<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>`;
html += `<select id="group" value="1">`;
for (let j = 0; j < data.optionList.length; j++) {
html += `<option data-id="${data.questionId}" value="${data.optionList[j].submitValue}">${data.optionList[j].showValue} </option>`;
}
html += `</select>`;
html += `</div>`;
4 years ago
} else if (data.type === 6) {
html += `<div class="mt-2.5 px-2 py-1.5 flex justify-between w-full border border-gray-200 rounded-sm text-sm" data-id="${data.questionId}">
<div class="flex justify-between items-center w-full" style="height: 20px;">
<p class="w-20 flex-shrink-0 text-gray-400">${data.question}</p>
4 years ago
<input class="train-start-time text-right outline-none" data-id="${data.questionId}" type="date" placeholder="请选择${data.question}">
4 years ago
</div>
</div>`;
4 years ago
} else if (data.type === 7) {
html += `<div class="file-upload mt-2.5 px-2 flex justify-between items-center w-full h-8 border border-gray-200 rounded-sm text-sm">
<p class="file-name text-gray-400">文件上传</p>
<div class="relative flex items-center">
<button>上传</button>
4 years ago
<input class="input-file absolute z-10 opacity-0" type="file" data-id="${data.questionId}" name="files" id="file" multiple>
4 years ago
</div>
</div>`;
4 years ago
}
}
4 years ago
that.dom.querySelector('.temp-box').innerHTML = html;
4 years ago
},
4 years ago
// 监听input框的值
setData(e) {
4 years ago
let that = this;
4 years ago
var event = e || window.event;
var tar = event.target || event.srcElement;
let id = tar.getAttribute("data-id");
console.log("event", event, "tar", tar, "id", id)
let arr = this.tempData;
arr.forEach(function(item, index) {
4 years ago
if (item.type === 1 || item.type === 2 || item.type === 3 || item.type === 6) {
4 years ago
if (item.questionId == id) {
item.answer = tar.value;
}
4 years ago
} else if (item.type === 7) {
tar.addEventListener('change', function(event) {
var files = event.target.files;
var formData = new FormData();
formData.append('param', files[0]);
that.upload(formData, index);
}, false);
4 years ago
}
});
console.log(arr);
},
4 years ago
// 预览
bigImg() {
4 years ago
document.querySelector('.img-preview').style.display = 'flex';
4 years ago
},
4 years ago
submit() {
4 years ago
let that = this;
console.log("that.tempData",that.tempData)
let questionList = [], arr = that.tempData;
arr.forEach(function(item, index) {
console.log(item, index);
if (item.type === 1 || item.type === 2) {
item.answer = that.dom.querySelector('.ques-' + item.questionId).value;
let obj = {};
obj.questionId = item.questionId;
obj.answerList = item.answer;
} else if (item.type === 3) {
item.answer = that.dom.querySelector('.ques-' + item.questionId).value;
let obj = {};
obj.questionId = item.questionId;
obj.answerList = item.answer;
}
})
4 years ago
},
4 years ago
// 文件上传
4 years ago
upload(formData, index){
4 years ago
var that = this;
fetch(`https://test.tall.wiki/gateway/sports/file/upload`, {
headers: new Headers({
'Authorization': 'Bearer ' + that.token
}),
method: 'POST',
body: formData,
})
.then(function(response) {
return response.json();
})
.then(function(res) {
const { success, code, data, msg } = res;
if (success && code === 200) {
that.fileId = data.fileId;
that.filePath = data.path;
let fileName = that.dom.querySelector('.file-name');
fileName.innerHTML = data.name;
4 years ago
that.tempData[index].answer = data.path;
console.log("that.tempData", that.tempData)
4 years ago
} else {
console.log('msg: ', msg);
}
});
},
}
4 years ago
p1472866674721169408.init()
4 years ago
</script>
4 years ago
</div>
</div>
</div>
4 years ago
<div class="flex mb-3">
<!-- 序号-->
<div class="flex flex-col items-center">
<div class="rounded-full h-8 w-8 mb-1 bg-gray-100 border-2 border-blue-500"></div>
<div class="w-8 flex-1 flex flex-col items-center">
<div class="w-0.5 flex-1 bg-gray-300"></div>
4 years ago
</div>
</div>
4 years ago
<div class="flex-1">
<!-- 定期任务面板-->
<div class="rounded-lg ml-4 bg-white p-3">
<!-- 示例插件1-->
<button class="bg-blue-500 py-2 px-5 rounded text-white" onclick="alert('hello')">测试组建1</button>
<!-- 示例插件2 id=100-->
<button class="bg-blue-500 py-2 px-5 rounded text-white" onclick="p100.show()">测试组建2</button>
<script>
const p100 = {
name: 'hello tall plugin',
show() {
alert(this.name)
}
}
</script>
4 years ago
</div>
</div>
</div>
</div>
</div>
</body>
<style>
4 years ago
.content, .task-bar{
4 years ago
overflow-y: scroll;
}
4 years ago
.content::-webkit-scrollbar, .task-bar::-webkit-scrollbar{
4 years ago
display: none;
}
4 years ago
</style>
</html>