提交 080e6cca 编写于 作者: yma16's avatar yma16

perf:gzip打包优化

上级 4c9d03d3
......@@ -128,7 +128,7 @@ if (config.build.productionGzip) {
webpackConfig.plugins.push(
new CompressionWebpackPlugin({
asset: '[path].gz[query]',
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp(
'\\.(' +
......
......@@ -78,7 +78,7 @@ module.exports = {
// Surge or Netlify already gzip all myblog_static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzip: true,
productionGzipExtensions: ["js", "css"],
// Run the build command with an extra argument to
......
......@@ -37,148 +37,147 @@
</template>
<script>
import axios from "axios";
export default {
name: "ArticleComment",
props: ["articleId"],
// props定义则data()无需定义
data() {
return {
submitLoading: false,
noneMsg: "还没人评论>_<",
msg: "评论区",
baseurl: "/api/",
// baseurl: "http://yongma16.xyz/comment/",
userImg: "",
username: "匿名",
contentRes: [],
userId: "匿名",
articleCommit: "",
childArticleId: "",
};
},
watch: {
articleId: function (newData) {
this.childArticleId = newData;
return newData;
name: 'ArticleComment',
props: ['articleId'],
// props定义则data()无需定义
data () {
return {
submitLoading: false,
noneMsg: '还没人评论>_<',
msg: '评论区',
baseurl: '/api/',
// baseurl: "http://yongma16.xyz/comment/",
userImg: '',
username: '匿名',
contentRes: [],
userId: '匿名',
articleCommit: '',
childArticleId: ''
}
},
watch: {
articleId: function (newData) {
this.childArticleId = newData
return newData
}
},
},
mounted() {
this.childArticleId && this.getComments(this.childArticleId);
},
methods: {
dateToString(dateValue) {
let timeCreate = new Date(dateValue);
let year = timeCreate.getFullYear(),
month = timeCreate.getMonth() + 1,
day = timeCreate.getDate(),
hour =
mounted () {
this.childArticleId && this.getComments(this.childArticleId)
},
methods: {
dateToString (dateValue) {
let timeCreate = new Date(dateValue)
let year = timeCreate.getFullYear(),
month = timeCreate.getMonth() + 1,
day = timeCreate.getDate(),
hour =
timeCreate.getHours() > 9
? timeCreate.getHours()
: "0" + timeCreate.getHours(),
minute =
? timeCreate.getHours()
: '0' + timeCreate.getHours(),
minute =
timeCreate.getMinutes() > 9
? timeCreate.getMinutes()
: "0" + timeCreate.getMinutes(),
second =
? timeCreate.getMinutes()
: '0' + timeCreate.getMinutes(),
second =
timeCreate.getSeconds() > 9
? timeCreate.getSeconds()
: "0" + timeCreate.getSeconds();
return (
year +
"" +
? timeCreate.getSeconds()
: '0' + timeCreate.getSeconds()
return (
year +
'' +
month +
"" +
'' +
day +
"" +
" " +
'' +
' ' +
hour +
":" +
':' +
minute +
":" +
':' +
second
);
},
getComments(articleId) {
let that = this;
let params = {
articleId: articleId || that.articleId,
};
axios
.post(that.baseurl + "comment/get/", params)
.then((res) => {
try {
let resData = res.data;
that.contentRes = resData.content;
that.contentRes.map((item) => {
item.date = that.dateToString(item.date);
});
} catch (e) {
throw Error(e);
}
})
.catch((r) => {
throw Error(r);
});
},
increment(userId, articleId, content) {
let that = this;
if (!localStorage.getItem("yma16siteUserInfo")) {
that.$router
.push({
path: "/login",
})
.catch((error) => {
throw Error(error);
});
} else {
if (content === "" || !content) {
that.$notify({
title: "评论失败!",
message: "评论内容不能为空",
position: "top-left",
});
return false;
}
that.submitLoading = true;
const userInfo = JSON.parse(localStorage.getItem("yma16siteUserInfo"));
that.userId = userInfo.username;
let params = {
username: that.userId,
articleId: articleId,
content: content,
};
axios
.post(that.baseurl + "comment/post/", params)
.then((res) => {
that.submitLoading = false;
that.articleCommit = null;
try {
let resData = res.data;
that.contentRes = resData.content;
that.contentRes.map((item) => {
item.date = that.dateToString(item.date);
});
} catch (e) {
that.submitLoading = false;
throw Error(e);
)
},
getComments (articleId) {
let that = this
let params = {
articleId: articleId || that.articleId
}
})
.catch((r) => {
that.submitLoading = false;
that.$router
.push({
path: "/login",
})
.catch((error) => {
throw Error(error);
});
throw Error(r);
});
}
},
},
};
this.$axios
.post(that.baseurl + 'comment/get/', params)
.then((res) => {
try {
let resData = res.data
that.contentRes = resData.content
that.contentRes.map((item) => {
item.date = that.dateToString(item.date)
})
} catch (e) {
throw Error(e)
}
})
.catch((r) => {
throw Error(r)
})
},
increment (userId, articleId, content) {
let that = this
if (!localStorage.getItem('yma16siteUserInfo')) {
that.$router
.push({
path: '/login'
})
.catch((error) => {
throw Error(error)
})
} else {
if (content === '' || !content) {
that.$notify({
title: '评论失败!',
message: '评论内容不能为空',
position: 'top-left'
})
return false
}
that.submitLoading = true
const userInfo = JSON.parse(localStorage.getItem('yma16siteUserInfo'))
that.userId = userInfo.username
let params = {
username: that.userId,
articleId: articleId,
content: content
}
this.$axios
.post(that.baseurl + 'comment/post/', params)
.then((res) => {
that.submitLoading = false
that.articleCommit = null
try {
let resData = res.data
that.contentRes = resData.content
that.contentRes.map((item) => {
item.date = that.dateToString(item.date)
})
} catch (e) {
that.submitLoading = false
throw Error(e)
}
})
.catch((r) => {
that.submitLoading = false
that.$router
.push({
path: '/login'
})
.catch((error) => {
throw Error(error)
})
throw Error(r)
})
}
}
}
}
</script>
<style scoped>
......
......@@ -29,91 +29,91 @@
<script>
export default {
name: "Csslearn",
data() {
return {
screenmsg: "全屏",
msg: "css练习:",
css_length: "",
// baseurl: 'http://127.0.0.1:1998',
baseurl: "/api/",
// baseurl: "http://yongma16.xyz/",
css_title: [],
css_path: [],
css_loc: 0,
ifreame_content: "",
look_i: "浏览:",
now_title: "",
};
},
methods: {
fullScreenFun: function () {
window.parent.location.href = this.ifreame_content;
function launchFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullScreen();
name: 'Csslearn',
data () {
return {
screenmsg: '全屏',
msg: 'css练习:',
css_length: '',
// baseurl: 'http://127.0.0.1:1998',
baseurl: '/api/',
// baseurl: "http://yongma16.xyz/",
css_title: [],
css_path: [],
css_loc: 0,
ifreame_content: '',
look_i: '浏览:',
now_title: ''
}
}
launchFullscreen(document.documentElement);
// launchFullscreen(document.getElementById('iframeId')) // 某个元素进入全屏
window.parent.location.href = this.ifreame_content;
},
li_errorClass: function () {
},
get_ifreame: function (index) {
let that = this; // that
that.ifreame_content = that.css_path[index]; // 路径
that.css_loc = index; // 索引传递
that.now_title = index + 1 + ". " + that.css_title[index]; // 标题
},
getCss: function () {
try {
document.getElementById("mainappid").style.padding = "0";
document.getElementById("mainappid").style.margin = "0";
} catch (e) {
throw Error(e)
}
methods: {
fullScreenFun: function () {
window.parent.location.href = this.ifreame_content
function launchFullscreen (element) {
if (element.requestFullscreen) {
element.requestFullscreen()
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen()
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen()
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullScreen()
}
}
launchFullscreen(document.documentElement)
// launchFullscreen(document.getElementById('iframeId')) // 某个元素进入全屏
window.parent.location.href = this.ifreame_content
},
li_errorClass: function () {
},
get_ifreame: function (index) {
let that = this // that
that.ifreame_content = that.css_path[index] // 路径
that.css_loc = index // 索引传递
that.now_title = index + 1 + '. ' + that.css_title[index] // 标题
},
getCss: function () {
try {
document.getElementById('mainappid').style.padding = '0'
document.getElementById('mainappid').style.margin = '0'
} catch (e) {
throw Error(e)
}
let that = this;
that.$axios
.get(that.baseurl + "css/")
.then((res) => {
let getdata = res.data;
let csspath = getdata.path;
let csstitle = getdata.title;
csspath.map((o) => {
that.css_path.push(o);
});
// 标题传递
// eslint-disable-next-line camelcase
that.css_title = csstitle;
// 传递第一个路html路径
that.ifreame_content = that.css_path[0];
// 传递长度
that.css_length = csstitle.length;
that.now_title = csstitle.length > 0 ? 1 + ". " + csstitle[0] : ""; // 标题加序号
})
.catch((error) => {
throw Error(error);
});
let that = this
that.$axios
.get(that.baseurl + 'css/')
.then((res) => {
let getdata = res.data
let csspath = getdata.path
let csstitle = getdata.title
csspath.map((o) => {
that.css_path.push(o)
})
// 标题传递
// eslint-disable-next-line camelcase
that.css_title = csstitle
// 传递第一个路html路径
that.ifreame_content = that.css_path[0]
// 传递长度
that.css_length = csstitle.length
that.now_title = csstitle.length > 0 ? 1 + '. ' + csstitle[0] : '' // 标题加序号
})
.catch((error) => {
throw Error(error)
})
}
},
mounted () {
let that = this
that.getCss() // get请求
},
},
mounted() {
let that = this;
that.getCss(); // get请求
},
created() {
let that = this;
window.onload = that.getCss; // get请求
},
};
created () {
let that = this
window.onload = that.getCss // get请求
}
}
</script>
<style scoped>
......
......@@ -19,15 +19,15 @@
<script>
import Map from '@/echarts/Map'
export default {
name: 'Home',
data () {
return {
name: 'Home',
data () {
return {
}
},
components: {
Map
}
},
components: {
Map
}
}
</script>
......
......@@ -55,141 +55,139 @@
</el-drawer>
</template>
<script>
//
import axios from "axios";
export default {
props: {
drawObj: Object,
},
data() {
return {
msgDrawTitle: "~邮件沟通~",
direction: "rtl",
msgDraw: false,
baseUrl: "/api/",
basePath: "send-email/",
loading: false,
emailForm: {
title: "",
email: "",
content: "",
rules: {
title: [
{
type: "string",
required: true,
message: "标题不能为空",
trigger: "blur",
},
],
email: [
{
type: "string",
required: true,
message: "邮箱不能为空",
trigger: "blur",
},
{
validator: (callback, value) => {
if (value) {
// 验证邮箱
let patter =
/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
let testEmail = patter.test(value);
if (!testEmail) {
return Promise.reject("邮箱格式有误");
}
props: {
drawObj: Object
},
data () {
return {
msgDrawTitle: '~邮件沟通~',
direction: 'rtl',
msgDraw: false,
baseUrl: '/api/',
basePath: 'send-email/',
loading: false,
emailForm: {
title: '',
email: '',
content: '',
rules: {
title: [
{
type: 'string',
required: true,
message: '标题不能为空',
trigger: 'blur'
}
],
email: [
{
type: 'string',
required: true,
message: '邮箱不能为空',
trigger: 'blur'
},
{
validator: (callback, value) => {
if (value) {
// 验证邮箱
let patter =
/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
let testEmail = patter.test(value)
if (!testEmail) {
return Promise.reject('邮箱格式有误')
}
}
return Promise.resolve('')
},
trigger: 'blur'
}
],
content: [
{
type: 'string',
required: true,
message: '内容不能为空',
trigger: 'blur'
}
]
}
return Promise.resolve("");
},
trigger: "blur",
},
],
content: [
{
type: "string",
required: true,
message: "内容不能为空",
trigger: "blur",
},
],
},
},
};
},
methods: {
//关闭抽屉
handleDrawClose() {
const that = this;
that.drawObj.show = false;
that.emailForm.title = "";
that.emailForm.email = "";
that.emailForm.content = "";
}
}
},
// 发送消息
sendEmail(formName) {
// 发送email内容
try {
const that = this;
that.loading = true;
that.$refs[formName].validate((valid) => {
if (valid) {
const params = {
title: that.emailForm.title,
email: that.emailForm.email,
content: that.emailForm.content,
};
methods: {
// 关闭抽屉
handleDrawClose () {
const that = this
that.drawObj.show = false
that.emailForm.title = ''
that.emailForm.email = ''
that.emailForm.content = ''
},
// 发送消息
sendEmail (formName) {
// 发送email内容
try {
axios
.post(that.baseUrl + that.basePath, params)
.then((res) => {
if (
res &&
const that = this
that.loading = true
that.$refs[formName].validate((valid) => {
if (valid) {
const params = {
title: that.emailForm.title,
email: that.emailForm.email,
content: that.emailForm.content
}
try {
this.$axios
.post(that.baseUrl + that.basePath, params)
.then((res) => {
if (
res &&
res.data &&
res.data.code &&
res.data.code === 20000
) {
that.loading = false;
that.$message({
message: "邮件发送成功!",
type: "success",
});
that.handleDrawClose()
} else {
that.loading = false;
that.$message({
message: "邮件发送失败!",
type: "warning",
});
}
) {
that.loading = false
that.$message({
message: '邮件发送成功!',
type: 'success'
})
that.handleDrawClose()
} else {
that.loading = false
that.$message({
message: '邮件发送失败!',
type: 'warning'
})
}
})
.catch((r) => {
that.loading = false
that.$message({
message: '邮件发送失败!',
type: 'warning'
})
throw Error(r)
})
} catch (r) {
that.loading = false
that.$message({
message: '邮件发送失败!',
type: 'warning'
})
throw Error(r)
}
} else {
that.loading = false
}
})
.catch((r) => {
that.loading = false;
that.$message({
message: "邮件发送失败!",
type: "warning",
});
throw Error(r);
});
} catch (r) {
that.loading = false;
that.$message({
message: "邮件发送失败!",
type: "warning",
});
throw Error(r);
that.loading = false
throw Error(r)
}
} else {
that.loading = false;
}
});
} catch (r) {
that.loading = false;
throw Error(r);
}
},
},
};
}
}
}
</script>
<style>
.el-drawer__open .el-drawer.rtl {
......
......@@ -103,11 +103,11 @@ export default {
// 置空
that.linesCoord = []
function task1 () {
const that = this
let that = this
return new Promise((resolve) => {
setTimeout(() => {
console.log('第1个任务geojson获取')
that.$axios
this.$axios
.get('https://yongma16.xyz/static/json/map/guizhou.json')
.then(function (response) {
let res = response.data
......
......@@ -37,6 +37,8 @@ Vue.directive('highlight', function (el) {
// cookie
Vue.prototype.$cookies = cookies
// axios
Vue.use(axios)
Vue.prototype.$axios = axios
window.$axios_w = axios
......
export function loginUser (data) {
console.log('用户登录service!', data)
let baseUrl = '/api/user/login/'
let res = null
window.$axios_w && window.$axios_w
.post(baseUrl, data)
.then((o) => {
res = o
console.log('成功认证', res)
// 只返回username
localStorage.setItem(
'yma16siteUserInfo',
JSON.stringify({
username: data.name, //保存一个用户名
password: data.password,
console.log('用户登录service!', data)
let baseUrl = '/api/user/login/'
let res = null
window.$axios_w && window.$axios_w
.post(baseUrl, data)
.then((o) => {
res = o
console.log('成功认证', res)
// 只返回username
localStorage.setItem(
'yma16siteUserInfo',
JSON.stringify({
username: data.name, // 保存一个用户名
password: data.password
})
)
})
)
})
.catch((r) => {
console.log('登录失败!', r)
})
return res
.catch((r) => {
console.log('登录失败!', r)
})
return res
}
......@@ -15,7 +15,6 @@
</template>
<script>
import axios from 'axios'
export default {
name: 'EchartWeather',
data () {
......@@ -52,7 +51,7 @@ export default {
let that = this
return new Promise((resolve) => {
setTimeout(function () {
axios
that.$axios
.get(that.baseurl + 'article/weather/')
.then((res) => {
console.log('天气接口返回', res)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册