写作目的:为积极响应戴鸿君老师对项目实训内容的建设性意见,特写本系列个人纪实,记录团队在项目实训的工作中个人的贡献。
登录:
login() {
this.$refs['userForm'].validate((valid) => {
if (valid) { // 表单校验合法
this.request.post("/user/login", this.user).then(res => {
if(res.code === '200') {
localStorage.setItem("user", JSON.stringify(res.data)) // 存储用户信息到浏览器
localStorage.setItem("menus", JSON.stringify(res.data.menus)) // 存储用户信息到浏览器
// 动态设置当前用户的路由
setRoutes()
if (res.data.role === 'ROLE_USER') {
this.$router.push("/front/home")
this.$message.success("登录成功")
} else {
this.$router.push("/")
this.$message.success("登录成功")
}
} else {
this.$message.error(res.msg)
}
})
}
});
},
用户获取:
getUser() {
let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
if (username) {
// 从后台获取User数据
this.request.get("/user/username/" + username).then(res => {
// 重新赋值后台的最新User数据
this.user = res.data
})
}
}
文书页面:
load() {
this.request.get("/blog/page", {
params: {
pageNum: this.pageNum,
pageSize: this.pageSize,
name: this.name,
}
}).then(res => {
this.tableData = res.data.records
this.total = res.data.total
})
this.request.get("/blogType").then(res => {
this.types = res.data
})
},
save() {
this.form.content = editor.txt.html()
this.$refs['ruleForm'].validate((valid) => {
if (valid) {
this.request.post("/blog", this.form).then(res => {
if (res.code === '200') {
this.$message.success("保存成功")
this.dialogFormVisible = false
this.dialogFormVisible2 = false
this.load()
} else {
this.$message.error(res.msg)
}
})
}
})
},
save2() {
this.request.post("/blog", this.form).then(res => {
if (res.code === '200') {
this.$message.success("审核成功")
this.dialogFormVisible2 = false
this.load()
} else {
this.$message.error(res.msg)
}
})
},
handleAdd() {
this.dialogFormVisible = true
this.form = {}
this.$nextTick(() => {
if (!editor){
editor = new E("#richText")
// 配置 server 接口地址
editor.config.uploadImgServer = 'http://localhost:9090/file/uploadImg'
editor.config.uploadFileName = 'file'
editor.create()
}
editor.txt.html('')
if(this.$refs.img) {
this.$refs.img.clearFiles();
}
if(this.$refs.file) {
this.$refs.file.clearFiles();
}
})
},
handleEdit(row) {
this.form = JSON.parse(JSON.stringify(row))
this.dialogFormVisible = true
this.$nextTick(() => {
if (!editor){
editor = new E("#richText")
// 配置 server 接口地址
editor.config.uploadImgServer = 'http://localhost:9090/file/uploadImg'
editor.config.uploadFileName = 'file'
editor.create()
}
editor.txt.html(this.form.content)
if(this.$refs.img) {
this.$refs.img.clearFiles();
}
if(this.$refs.file) {
this.$refs.file.clearFiles();
}
})
},
handleEdit2(row) {
this.form = JSON.parse(JSON.stringify(row))
this.dialogFormVisible2 = true
},
del(id) {
this.request.delete("/blog/" + id).then(res => {
if (res.code === '200') {
this.$message.success("删除成功")
this.load()
} else {
this.$message.error("删除失败")
}
})
},
文书类型:
load() {
this.request.get("/blogType/page", {
params: {
pageNum: this.pageNum,
pageSize: this.pageSize,
name: this.name,
}
}).then(res => {
this.tableData = res.data.records
this.total = res.data.total
})
},
save() {
this.$refs['ruleForm'].validate((valid) => {
if (valid) {
this.request.post("/blogType", this.form).then(res => {
if (res.code === '200') {
this.$message.success("保存成功")
this.dialogFormVisible = false
this.load()
} else {
this.$message.error(res.msg)
}
})
}
})
},
轮播图和公告
created() {
// this.request.get("/").then(res => {
// this.files = res.data
// })
this.request.get("/notice").then(res => {
this.notices = res.data.splice(0, 10)
})
// this.request.get("/blog/recommend").then(res => {
// this.blogRecommends = res.data
// })
this.request.get("/file/pageHome", {
params: {
pageNum: this.pageNum,
pageSize: this.pageSize,
}
}).then(res => {
this.files = res.data.records
this.total = res.data.total
})
},
用户文书展示:
load() {
console.log(this.type)
this.request.get("/blog/page/type", {
params: {
pageNum: this.pageNum,
pageSize: this.pageSize,
name: this.name,
type: this.type
}
}).then(res => {
this.tableData = res.data.records
this.total = res.data.total
})
this.request.get("/blogType").then(res => {
this.types = res.data
})
},
AI回答:
const err = (msg) => `# *${msg}*`
const question = this.question;
if (!question) {
this.answer = err("未输入内容")
return;
}
AIRequest.chat(question,true).then(response =>{
// 处理响应
console.log(response);
if (response.code !=0) {
this.answer = err("发生错误,请查看服务器日志");
return;
}
this.answer = response.data.answer;
})
.catch(error => {
// 处理错误情况
console.error(error);
this.answer = err("发生错误,请查看服务器日志");
})
判决书:
created() {
const currentDate = new Date();
const year = currentDate.getFullYear();
const month = currentDate.getMonth() + 1; // getMonth() returns month from 0-11
const day = currentDate.getDate();
this.formattedDate = `${year}年${month}月${day}日`;
this.formData.date = this.formattedDate;
this.getLocation();
},
computed: {
shouldHideHeader() {
return (
this.formData.title === this.title &&
!this.formData.keywords &&
!this.formData.points &&
!this.formData.caseDetails &&
!this.formData.result
// !this.formData.location &&
// this.formData.date === this.formattedDate
);
},
renderAnswer() {
return this.md.render(this.answers);
}
},
methods: {
getAnswer(){
if (!this.checkRequired()) return;
this.answer = true;
this.answerList = ["你好","再见"];
this.lawList = [["1","1","法律1"],["1","1","法律2"],["1","1","法律3"]];
AIRequest.ask(this.formData.caseDetails).then(res =>{
console.log(res);
this.answerList = res.data.answerList;
this.lawList = res.data.lawList;
})
/* AiRequest.post("ai/chat",{
input:'我偷了李四50000000元,我应该怎么逃跑'
}).then(res =>{
console.log(res)
}
)*/
},
checkRequired() {
for (const item of document.querySelectorAll(`[required]`)) {
if (!item.value) return false;
}
return true;
},
async downloadPdf() {
if (!this.checkRequired()) return;
const element = this.$refs.appealContent;
const pdf = new jsPDF();
pdf.addFont("/stzhongs.ttf", "song", "normal")
pdf.setFont("song");
let offset = 20;
Array.from(element.querySelectorAll("h2,h3,p")).forEach((item) => {
let text = item.textContent.trim();
let split = "";
switch (item.tagName) {
case "H2":
pdf.setFontSize(20);
pdf.text(text, 105, offset, {align: "center"});
offset += 10;
break;
case "H3":
pdf.setFontSize(16);
pdf.text(text, 10, offset);
offset += 8;
break;
case "P":
pdf.setFontSize(12);
split = pdf.splitTextToSize(text.replace(/^\s*/mg, " "), 190);
pdf.text(split, 10, offset);
offset += 6 * split.length + 2;
break;
default:
break;
}
})
pdf.save('appeal.pdf');
},
getLocation() {
ipLocation().then(res => this.formData.location = res);
},
showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
this.location = "用户拒绝请求地理定位";
break;
case error.POSITION_UNAVAILABLE:
this.location = "位置信息不可用";
break;
case error.TIMEOUT:
this.location = "请求用户地理位置超时";
break;
default:
this.location = "未知错误";
break;
}
}
}
};