提交 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 this.$axios
.post(that.baseurl + "comment/get/", params) .post(that.baseurl + 'comment/get/', params)
.then((res) => { .then((res) => {
try { try {
let resData = res.data; let resData = res.data
that.contentRes = resData.content; that.contentRes = resData.content
that.contentRes.map((item) => { that.contentRes.map((item) => {
item.date = that.dateToString(item.date); item.date = that.dateToString(item.date)
}); })
} catch (e) { } catch (e) {
throw Error(e); throw Error(e)
} }
}) })
.catch((r) => { .catch((r) => {
throw Error(r); throw Error(r)
}); })
}, },
increment(userId, articleId, content) { increment (userId, articleId, content) {
let that = this; let that = this
if (!localStorage.getItem("yma16siteUserInfo")) { if (!localStorage.getItem('yma16siteUserInfo')) {
that.$router that.$router
.push({ .push({
path: "/login", path: '/login'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
} else { } else {
if (content === "" || !content) { if (content === '' || !content) {
that.$notify({ that.$notify({
title: "评论失败!", title: '评论失败!',
message: "评论内容不能为空", message: '评论内容不能为空',
position: "top-left", position: 'top-left'
}); })
return false; return false
} }
that.submitLoading = true; that.submitLoading = true
const userInfo = JSON.parse(localStorage.getItem("yma16siteUserInfo")); const userInfo = JSON.parse(localStorage.getItem('yma16siteUserInfo'))
that.userId = userInfo.username; that.userId = userInfo.username
let params = { let params = {
username: that.userId, username: that.userId,
articleId: articleId, articleId: articleId,
content: content, content: content
}; }
axios this.$axios
.post(that.baseurl + "comment/post/", params) .post(that.baseurl + 'comment/post/', params)
.then((res) => { .then((res) => {
that.submitLoading = false; that.submitLoading = false
that.articleCommit = null; that.articleCommit = null
try { try {
let resData = res.data; let resData = res.data
that.contentRes = resData.content; that.contentRes = resData.content
that.contentRes.map((item) => { that.contentRes.map((item) => {
item.date = that.dateToString(item.date); item.date = that.dateToString(item.date)
}); })
} catch (e) { } catch (e) {
that.submitLoading = false; that.submitLoading = false
throw Error(e); throw Error(e)
} }
}) })
.catch((r) => { .catch((r) => {
that.submitLoading = false; that.submitLoading = false
that.$router that.$router
.push({ .push({
path: "/login", path: '/login'
}) })
.catch((error) => { .catch((error) => {
throw Error(error); throw Error(error)
}); })
throw Error(r); 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: { methods: {
fullScreenFun: function () { fullScreenFun: function () {
window.parent.location.href = this.ifreame_content; window.parent.location.href = this.ifreame_content
function launchFullscreen(element) { function launchFullscreen (element) {
if (element.requestFullscreen) { if (element.requestFullscreen) {
element.requestFullscreen(); element.requestFullscreen()
} else if (element.mozRequestFullScreen) { } else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen(); element.mozRequestFullScreen()
} else if (element.msRequestFullscreen) { } else if (element.msRequestFullscreen) {
element.msRequestFullscreen(); element.msRequestFullscreen()
} else if (element.webkitRequestFullscreen) { } else if (element.webkitRequestFullscreen) {
element.webkitRequestFullScreen(); element.webkitRequestFullScreen()
} }
} }
launchFullscreen(document.documentElement); launchFullscreen(document.documentElement)
// launchFullscreen(document.getElementById('iframeId')) // 某个元素进入全屏 // launchFullscreen(document.getElementById('iframeId')) // 某个元素进入全屏
window.parent.location.href = this.ifreame_content; window.parent.location.href = this.ifreame_content
}, },
li_errorClass: function () { li_errorClass: function () {
}, },
get_ifreame: function (index) { get_ifreame: function (index) {
let that = this; // that let that = this // that
that.ifreame_content = that.css_path[index]; // 路径 that.ifreame_content = that.css_path[index] // 路径
that.css_loc = index; // 索引传递 that.css_loc = index // 索引传递
that.now_title = index + 1 + ". " + that.css_title[index]; // 标题 that.now_title = index + 1 + '. ' + that.css_title[index] // 标题
}, },
getCss: function () { getCss: function () {
try { try {
document.getElementById("mainappid").style.padding = "0"; document.getElementById('mainappid').style.padding = '0'
document.getElementById("mainappid").style.margin = "0"; document.getElementById('mainappid').style.margin = '0'
} catch (e) { } catch (e) {
throw Error(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>
......
...@@ -55,92 +55,90 @@ ...@@ -55,92 +55,90 @@
</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(""); return Promise.resolve('')
},
trigger: "blur",
}, },
trigger: 'blur'
}
], ],
content: [ content: [
{ {
type: "string", type: 'string',
required: true, required: true,
message: "内容不能为空", message: '内容不能为空',
trigger: "blur", trigger: 'blur'
}, }
], ]
}, }
}, }
}; }
}, },
methods: { methods: {
//关闭抽屉 // 关闭抽屉
handleDrawClose() { handleDrawClose () {
const that = this; const that = this
that.drawObj.show = false; that.drawObj.show = false
that.emailForm.title = ""; that.emailForm.title = ''
that.emailForm.email = ""; that.emailForm.email = ''
that.emailForm.content = ""; that.emailForm.content = ''
}, },
// 发送消息 // 发送消息
sendEmail(formName) { sendEmail (formName) {
// 发送email内容 // 发送email内容
try { try {
const that = this; const that = this
that.loading = true; that.loading = true
that.$refs[formName].validate((valid) => { that.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
const params = { const params = {
title: that.emailForm.title, title: that.emailForm.title,
email: that.emailForm.email, email: that.emailForm.email,
content: that.emailForm.content, content: that.emailForm.content
}; }
try { try {
axios this.$axios
.post(that.baseUrl + that.basePath, params) .post(that.baseUrl + that.basePath, params)
.then((res) => { .then((res) => {
if ( if (
...@@ -149,47 +147,47 @@ export default { ...@@ -149,47 +147,47 @@ export default {
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) => { .catch((r) => {
that.loading = false; that.loading = false
that.$message({ that.$message({
message: "邮件发送失败!", message: '邮件发送失败!',
type: "warning", type: 'warning'
}); })
throw Error(r); throw Error(r)
}); })
} catch (r) { } catch (r) {
that.loading = false; that.loading = false
that.$message({ that.$message({
message: "邮件发送失败!", message: '邮件发送失败!',
type: "warning", type: 'warning'
}); })
throw Error(r); throw Error(r)
} }
} else { } else {
that.loading = false; that.loading = false
} }
}); })
} catch (r) { } catch (r) {
that.loading = false; that.loading = false
throw Error(r); 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
......
...@@ -11,8 +11,8 @@ export function loginUser (data) { ...@@ -11,8 +11,8 @@ export function loginUser (data) {
localStorage.setItem( localStorage.setItem(
'yma16siteUserInfo', 'yma16siteUserInfo',
JSON.stringify({ JSON.stringify({
username: data.name, //保存一个用户名 username: data.name, // 保存一个用户名
password: data.password, password: data.password
}) })
) )
}) })
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册