123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- let majorId = 0;
-
- let arr =[
- {
- id:0,
- name:"随机资料"
- },
- {
- id:1,
- name:"技术通报"
- },
- {
- id:2,
- name:"研究文章"
- },
- ]
- $(function() {
- var params = window.location.href.split("?");
- if (params.length > 1) {
- values = params[1].split("&");
- if (values.length > 10) {
- var funcId = values[0].replace("id=", "");
- var functi = ""; //标题
- var funcauthor = ""; //作者
- var functime = ""; //输入时间
- var funckey = ""; //关键字
- var funcdes = ""; //概述
- var funcmajorId = ""; //专业
- var funcmajorName = ""; //专业名
- var funcarticleType = ""; //文章类型
- var funcfilePath = ""; //文件路径
- var funcfile = "" //选择文件
- if (funcId !== "0") {
- functi = decodeURI(values[1].replace("title=", "")); //标题
- funcauthor = decodeURI(values[2].replace("author=", "")); //作者
- functime = decodeURI(values[3].replace("input_time=", "")); //输入时间
- funckey = decodeURI(values[4].replace("keywords=", "")); //关键字
- funcdes = decodeURI(values[5].replace("description=", "")); //概述
- funcmajorId = decodeURI(values[6].replace("major_id=", "")); //专业
- funcmajorName = decodeURI(values[7].replace("major_name=", "")); //专业名
- funcarticleType = decodeURI(values[8].replace("article_type=", "")); //文章类型
- // funcfilePath = decodeURI(values[9].replace("file_path=", "")); //文件路径
- funcfile = decodeURI(values[10].replace("file=", "")); //选择文件
- }
- }
- }
- $("#title").val(functi); //标题
- $("#author").val(funcauthor); //作者
- $("#input_time").val(functime); //输入时间
- $("#keywords").val(funckey); //关键字
- $("#description").val(funcdes); //概述
- $("#major_id").val(funcmajorId); //专业
- $("#major_name").val(funcmajorName); //专业名
- $("#article_type").val(funcarticleType); //文章类型
- // $("#file_path").val(funcfilePath); //文件路径
- $("#file").val(funcfile); //选择文件
- // if (isHide === "1") {
- // $("#flag").attr("checked", "checked");
- // }
- getArticleType();
- layui.use(["form", "layer","upload"], function() {
- $ = layui.jquery;
- var form = layui.form,
- layer = layui.layer;
- //监听提交
- var upload = layui.upload;
- form.on("submit(save)", function(data) {
- if ($("#title").val().trim() === "") {
- showMsg("标题不能为空", 2);
- $("#title").focus();
- return false;
- }
- if ($("#author").val().trim() === "") {
- showMsg("作者不能为空", 2);
- $("#author").focus();
- return false;
- }
- if ($("#input_time").val().trim() === "") {
- showMsg("输入时间不能为空", 2);
- $("#input_time").focus();
- return false;
- }
- if ($("#keywords").val().trim() === "") {
- showMsg("关键字不能为空", 2);
- $("#keywords").focus();
- return false;
- }
- if ($("#description").val().trim() === "") {
- showMsg("概述不能为空", 2);
- $("#author").focus();
- return false;
- }
- if ($("#major_id").val().trim() === "") {
- showMsg("专业不能为空", 2);
- $("#major_id").focus();
- return false;
- }
- if ($("#major_name").val().trim() === "") {
- showMsg("专业名不能为空", 2);
- $("#major_name").focus();
- return false;
- }
- if ($("#article_type").val().trim() === "") {
- showMsg("文章类型不能为空", 2);
- $("#article_type").focus();
- return false;
- }
- if ($("#file_path").val().trim() === "") {
- showMsg("上传文件不能为空", 2);
- $("#file_path").focus();
- return false;
- }
- var func = data.field;
- func.id = funcId;
- fetchJSON("api/article/add", func, "post", function(data) {
- if (data.status === 0) {
- var index = parent.layer.getFrameIndex(window.name);
- showMsg("上传成功", 1, 2000);
- parent.layer.close(index);
- } else {
- showMsg(data.msg, 2);
- }
- });
- return false;
- });
- upload.render({
- elem: '#fileSelector',
- url: urlBase + "api/article/import",
- //accept: 'file', //普通文件
- headers: {
- "token":sessionStorage.getItem("token")
- },
- data: {},
- accept: 'file',
- done: function(res) {
- if(res.status === 0)
- {
- $("#file_path").val(res.msg);
- }
- else
- showMsg(res.msg, 2);
- }
- });
-
- //专业
- function getMajor() {
- fetchJSON("api/major/listAll", {}, "get", function(bet) {
- if (bet.status === 0) {
- $("#major_id").empty();
- $("#major_id").append($("<option>", {
- value: -1,
- text: "请选择"
- }));
- for (var i = 0; i < bet.data.length; i++) {
- if (bet.data[i].id === majorId) {
- $("#major_id").append(
- $("<option>", {
- // value: bet.data[i].id,
- text: bet.data[i].id,
- selected: true
- })
- );
- } else {
- $("#major_id").append(
- $("<option>", {
- // value: bet.data[i].id,
- text: bet.data[i].id
- })
- );
- }
- }
- form.render('select');
- } else {
- showMsg(bet.msg, 2);
- }
- });
- };
- getMajor()
- //专业名
- function getMajorName() {
- fetchJSON("api/major/listAll", {}, "get", function(bet) {
- if (bet.status === 0) {
- $("#major_name").empty();
- $("#major_name").append($("<option>", {
- value: -1,
- text: "请选择"
- }));
- for (var i = 0; i < bet.data.length; i++) {
- if (bet.data[i].id === majorId) {
- $("#major_name").append(
- $("<option>", {
- // value: bet.data[i].id,
- text: bet.data[i].major,
- selected: true
- })
- );
- } else {
- $("#major_name").append(
- $("<option>", {
- // value: bet.data[i].id,
- text: bet.data[i].major
- })
- );
- }
- }
- form.render('select');
- } else {
- showMsg(bet.msg, 2);
- }
- });
- };
- getMajorName()
- });
- });
- //文章类型
- function getArticleType() {
- $("#article_type").append($("<option>", {
- value: -1,
- text: "请选择"
- }));
- for (var i = 0; i < arr.length; i++) {
- $("#article_type").append(
- $("<option>", {
- // value: arr[i].id,
- text: arr[i].name
- })
- );
- }
- };
|