<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="./css/IndexCss.css">
</head>
<body>
<div id="app">
<div class="header">
<div class="tab" v-for="item in CaseDate" :key="item.CaseId" v-text="item.CaseName" @click="tagger(item.CaseId)"></div>
</div>
<div class="main">
<div class="aside">
<ul>
<li>侧边栏一</li>
<li>侧边栏二</li>
<li>侧边栏三</li>
<li>侧边栏四</li>
</ul>
<p>{{cateId}}</p>
<p>{{list.EventTag}}</p>
</div>
<div class="article">
<div class="homeDiv" v-if="flag">
<span class="add" @click="add()">添加</span>
<div class="listDiv" v-for="(item,i) in list" :key="i">
<span class="title" v-text="caseName"></span>
<img :src="item.Picture">
<div class="text">
<p v-text="item.EventTag"></p>
<p v-text="item.EventDesription"></p>
</div>
<div class="optation">
<span class="edit" @click="edit(item.IncidentID)">编辑</span>
<span class="delete" @click="romove(item.IncidentID)">删除</span>
</div>
</div>
<div></div>
</div>
<div class="detailDiv" v-else>
<div class="opt">
<span @click="save">保存</span>
<span @click="back">返回</span>
</div>
<div class="formDiv" model="addForm">
<div class="formDiv_left">
<div>
<span>事件标签</span>
<input type="text" v-model="addForm.EventTag">
</div>
<div>
<span>开始时间</span>
<input type="date" type="text" v-model="addForm.StartTime">
<span>结束时间</span>
<input type="date" type="text" v-model="addForm.EndTime">
</div>
<div>
<span>事件描述</span>
<textarea type="text " v-model="addForm.EventDesription "></textarea>
</div>
<div>
<span>热度来源</span>
<textarea type="text " v-model="addForm.HeatSource "></textarea>
</div>
<div>
<span>事件案例</span>
<select type="text " v-model="addForm.CaseStudy ">
<option :value ="item.CaseId" v-for="item in CaseDate" :key="item.CaseId">{{item.CaseName}}</option>
</select>
</div>
</div>
<div class="formDiv_right ">
<div class="imgDiv">
<input type="file" @change="uploadImg" accept="image/*" v-if="!filePath" />
<img :src="filePath" v-else>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="./js/Upload.js "></script>
<script src="./js/vue.js "></script>
<script src="./js/IndexJs.js "></script>
</body>
</html>
// Vue.component('home', {
// template: '#homeDiv',
// props: ['title', 'lists'],
// data() {
// return {
// chilidLists: []
// }
// },
// created() {
// this.chilidLists = sessionStorage.getItem('list')
// console.log(this.chilidLists)
// },
// methods: {
// childAdd: function() {
// // console.log("ok")
// this.$emit('child-add', false)
// }
// }
// })
// Vue.component('detail', {
// template: '#detailDiv'
// })
var vm = new Vue({
el: "#app",
data: {
flag: true,
CaseDate: [{
CaseId: 1,
CaseName: '案例一'
},
{
CaseId: 2,
CaseName: '案例二'
},
{
CaseId: 3,
CaseName: '案例三'
}, {
CaseId: 4,
CaseName: '案例四'
}
],
incidentData: [{
IncidentID: 1,
EventTag: '新冠事件',
StartTime: "2020-01-20",
EndTime: '2021-03-03',
Picture: './image/1.png',
EventDesription: '11111111112222222',
HeatSource: '百度指数',
CaseStudy: 1
},
{
IncidentID: 2,
EventTag: '新冠事件',
StartTime: "2020-01-20",
EndTime: '2021-03-03',
Picture: './image/1.png',
EventDesription: '1111111111111111111111',
HeatSource: '百度指数',
CaseStudy: 1
},
{
IncidentID: 3,
EventTag: '新冠事件2',
StartTime: "2020-01-20",
EndTime: '2021-03-03',
Picture: './image/1.png',
EventDesription: '2222222222222222222222',
HeatSource: '百度指数',
CaseStudy: 2
},
{
IncidentID: 4,
EventTag: '新冠事件3',
StartTime: "2020-01-20",
EndTime: '2021-03-03',
Picture: './image/1.png',
EventDesription: '3333333333333333333333333',
HeatSource: '百度指数',
CaseStudy: 3
},
{
IncidentID: 5,
EventTag: '新冠事件4',
StartTime: "2020-01-20",
EndTime: '2021-03-03',
Picture: './image/1.png',
EventDesription: '44444444444444444444444444444',
HeatSource: '百度指数',
CaseStudy: 4
}
],
cateId: '1',
caseName: '案例一',
list: [],
addForm: {},
filePath: '',
isEdit: false
},
created() {
this.init()
// console.log(this.list)
window.sessionStorage.setItem("list", JSON.stringify(this.list))
// console.log(this.list)
// this.list = this.incidentData[0]
this.cateId = this.CaseDate[0].CaseId
this.caseName = this.CaseDate[0].CaseName
// console.log(this.cateId, this.cateName)
},
methods: {
init() {
this.incidentData.forEach(item => {
if (item.CaseStudy == this.cateId) {
this.list.push(item)
}
});
},
tagger: function(caseId) {
this.flag = true
this.cateId = caseId
this.CaseDate.forEach(item => {
if (item.CaseId == caseId) {
this.caseName = item.CaseName
}
})
this.list = []
this.incidentData.forEach(item => {
if (item.CaseStudy == caseId) {
this.list.forEach(data => {
if (data.CaseStudy !== caseId) {
this.list = []
}
})
this.list.push(item)
}
})
},
add() {
this.flag = false
this.isEdit = false
this.filePath = ''
this.addForm = {}
// var click = document.getElementById('uploadimg');
},
// 返回
back() {
this.flag = true
},
// 保存
save() {
// 编辑
if (this.isEdit) {
this.incidentData.forEach(item => {
if (item.IncidentID == this.addForm.IncidentID) {
item = this.addForm
}
})
this.isEdit = true
this.addForm = {}
} else {
// 添加
this.$set(this.addForm, 'Picture', this.filePath)
this.incidentData.push(this.addForm)
this.cateId = this.addForm.CaseStudy
// this.CaseDate.forEach(item => {
// if (item.CaseId == this.caseId) {
// this.caseName = item.CaseName
// }
// })
// this.list = []
// this.incidentData.forEach(item => {
// if (item.CaseStudy == this.cateId) {
// this.list.forEach(data => {
// if (data.CaseStudy !== this.cateId) {
// this.list = []
// }
// })
// this.list.push(item)
// }
// })
this.tagger(this.cateId)
this.addForm = {}
this.isEdit = false
}
this.flag = true;
},
// 上传图片
uploadImg: function(e) {
let that = this;
let file = e.target.files[0];
// let formData = new FormData(); //创建 formdata对象
// formData.append('file', file);
// console.log()
this.filePath = './image/' + file.name
},
// 编辑
edit(id) {
// console.log(id)
this.isEdit = true
this.incidentData.forEach(item => {
if (item.IncidentID == id) {
this.addForm = item
this.filePath = item.Picture
}
})
// console.log(this.addForm)
this.flag = false
},
// 删除
romove(id) {
// this.incidentData.splice(0, 1)
// console.log(this.incidentData)
// console.log(id)
for (let i = 0; i < this.incidentData.length; i++) {
console.log(this.incidentData[i].IncidentID)
if (this.incidentData[i].IncidentID == id) {
this.incidentData.splice(i, 1)
}
}
this.list = []
this.incidentData.forEach(item => {
if (item.CaseStudy == this.cateId) {
this.list.forEach(data => {
if (data.CaseStudy !== this.cateId) {
this.list = []
}
})
this.list.push(item)
}
})
}
},
});
* {
margin: 0;
padding: 0;
}
#app {
height: 100%;
}
.header {
height: 80px;
background-color: pink;
}
.tab {
display: inline-block;
background-color: greenyellow;
cursor: pointer;
margin-left: 5px;
}
.main {
height: calc(100% - 80px);
/* border: 1px solid green; */
}
.aside {
float: left;
width: 180px;
height: 100%;
background-color: greenyellow;
}
ul {
width: 100%;
}
ul li {
height: 30px;
margin: 0 auto;
text-align: center;
cursor: pointer;
}
.article {
float: right;
margin: 20px;
width: calc(100% - 224px);
height: calc(100% - 40px);
background-color: yellow;
overflow: auto;
}
.add {
display: inline-block;
width: 100px;
height: 50px;
line-height: 50px;
background-color: red;
text-align: center;
cursor: pointer;
}
.listDiv {
margin: 20px;
width: calc(100%-40px);
height: 170px;
background-color: aqua;
}
.title,
.text,
.optation {
margin-top: 60px;
display: inline-block;
vertical-align: top;
}
.listDiv img {
margin-top: 10px;
}
.optation {
margin-right: 20px;
float: right;
}
.optation span {
display: inline-block;
background-color: red;
cursor: pointer;
}
.opt span {
background-color: red;
cursor: pointer;
}
.formDiv {
margin: 20px;
width: calc(100%-40px);
height: 300px;
background-color: fuchsia;
}
.formDiv_left {
float: left;
width: 80%;
border: 1px solid red;
}
.formDiv_right {
float: right;
width: 18%;
height: 200px;
}
.imgDiv {
width: 90%;
height: 70%;
margin: 0 auto;
/* background-color: red; */
border: 1px dotted #000;
}
.imgDiv input {
opacity: 0;
width: 90%;
height: 70%;
margin: 0 auto;
}
.imgDiv img {
width: 90%;
height: 70%;
margin: 0 auto;
}