import Vue from 'vue' import { Loading } from 'element-ui' Vue.prototype.GLOBAL ={ //用户cookie user_key:'user', //服务器地址 server_address:'http://127.0.0.1:8080', // 检查元素可见 visible_in_container:function(p,e) { var z = p.getBoundingClientRect(); var r = e.getBoundingClientRect(); // Check style visiblilty and off-limits return !(r.top > z.bottom || r.bottom < z.top || r.left > z.right || r.right < z.left); }, //发送json请求 fetchJSON(url,method, form, success){ fetch(this.server_address + url, { body:JSON.stringify(form), method: method, headers: { 'Content-Type': 'application/json' }, credentials: "include" }).then(res=>res.json()).then(res=>success(res)).catch(err=>{ console.error(err) }) }, //发送get请求 fetchGet(url,params,success,json=true){ if (params) { let paramsArray = []; //拼接参数 Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key])) if (url.search(/\?/) === -1) { url += '?' + paramsArray.join('&') } else { url += '&' + paramsArray.join('&') } } if(json) { fetch(this.server_address + url, { method: 'GET', credentials: "include" }).then(res => res.json()).then(res => success(res)).catch(err => { console.error(err) }) }else{ fetch(this.server_address + url, { method: 'GET', credentials: "include" }).then(res=>res.text()).then(res=>success(res)) } }, } //阅读论文 Vue.prototype.$read= function(item) { let loadingInstance =Loading.service({}); let that=this this.GLOBAL.fetchGet(`/v1/api/paper/content/${item.id}`,{},function(res) { item.content=res that.$store.commit('menus/read') that.$store.commit('read/open', item) that.$router.push(that.localePath('/read')) loadingInstance.close() },false) }