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

perf:gzip打包优化

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