暂存-fix刷新路由跳转丢失和name不存在bug

This commit is contained in:
祝梦园 2024-03-06 16:49:05 +08:00
parent 0faa495d95
commit 0e669aab00
5 changed files with 499 additions and 501 deletions

View File

@ -75,13 +75,8 @@ export default {
methods: { methods: {
onSubmit() { onSubmit() {
this.$refs.cropper.getCropData(data => { this.$refs.cropper.getCropData(data => {
// console.log(data)
this.$emit('onSubmit',data) this.$emit('onSubmit',data)
}); });
/*
this.$emit('onSubmit',this.cropImg)
*/
}, },
onOpen() { onOpen() {
this.oldAvatarUrl = JSON.parse(JSON.stringify(this.avatarUrl)) this.oldAvatarUrl = JSON.parse(JSON.stringify(this.avatarUrl))

View File

@ -1,13 +1,13 @@
<template> <template>
<el-row type="flex" justify="center" :gutter="8"> <el-row type="flex" justify="center" :gutter="8">
<el-col v-if="hasPermissions" :span="20"> <el-col v-if="hasPermissions" :span="20">
<el-col :span="4"> <el-col :span="4" v-if="menus">
<el-menu <el-menu
:default-active="activeMenu" :default-active="activeMenu"
class="el-menu-vertical-demo" class="el-menu-vertical-demo"
@select="handleSelectMenu"> @select="handleSelectMenu">
<template v-for="menu in menus"> <template v-for="menu in menus">
<el-menu-item :key="menu.name" :index="menu.name"> <el-menu-item v-if="!(menu.isEdit)||false" :key="menu.name" :index="menu.name">
<i :class="menu.icon"></i> <i :class="menu.icon"></i>
<span slot="title">{{ menu.title }}</span> <span slot="title">{{ menu.title }}</span>
</el-menu-item> </el-menu-item>
@ -131,10 +131,18 @@ export default {
}, },
{ {
title: '产品管理', title: '产品管理',
name: 'admin-products', name: 'admin-product',
path: '/admin/products', path: '/admin/product/index',
icon: 'el-icon-box', icon: 'el-icon-box',
closable: true closable: true
},
{
title: '产品编辑',
name: 'admin-product-post-product_id',
path: '/admin/product/post/:id?',
icon: 'el-icon-postcard',
closable: true,
isEdit: true
} }
] ]
} }
@ -189,11 +197,13 @@ export default {
_ts.$store.commit('admin/pushTags', _ts.menus[index]) _ts.$store.commit('admin/pushTags', _ts.menus[index])
reset = '1' reset = '1'
} }
let params = _ts.$route.params
params.reset = reset
let query = _ts.$route.query
_ts.$router.push({ _ts.$router.push({
name: item, name: item,
params: { params,
reset: reset query
}
}) })
}, },
handleSelectMenu(item) { handleSelectMenu(item) {

View File

@ -7,6 +7,9 @@
<el-breadcrumb-item>产品管理</el-breadcrumb-item> <el-breadcrumb-item>产品管理</el-breadcrumb-item>
</el-breadcrumb> </el-breadcrumb>
</el-col> </el-col>
<el-col>
<el-button type="primary" @click="handleAdd">新增产品</el-button>
</el-col>
<el-col> <el-col>
<el-table <el-table
:data="products.list" :data="products.list"
@ -74,43 +77,39 @@
</el-pagination> </el-pagination>
</el-col> </el-col>
</el-row> </el-row>
<el-dialog :title="`物流公司-${isEdit?'修改':'新增'}项目`" :visible.sync='editVisible' <!-- <el-dialog :title="`物流公司-${isEdit?'修改':'新增'}项目`" :visible.sync='editVisible'-->
center width='880px'> <!-- center width='880px'>-->
<el-form ref='formStore' :model='formStore' :rules='rules' label-poionsit='right' label-width='110px'> <!-- <el-form ref='formStore' :model='formStore' :rules='rules' label-poionsit='right' label-width='110px'>-->
<div style="margin-bottom:20px"> <!-- <div style="margin-bottom:20px">-->
<img @click="cropperVisible=true" :src="formStore.productImgUrl" <!-- <img @click="cropperVisible=true" :src="formStore.productImgUrl"-->
style="width: 120px;height: 120px;margin: 0 auto;display: block"> <!-- style="width: 120px;height: 120px;margin: 0 auto;display: block">-->
</div> <!-- </div>-->
<el-form-item label='产品名称' prop='productTitle'> <!-- <el-form-item label='产品名称' prop='productTitle'>-->
<el-input v-model='formStore.productTitle' placeholder='请输入产品名称'/> <!-- <el-input v-model='formStore.productTitle' placeholder='请输入产品名称'/>-->
</el-form-item> <!-- </el-form-item>-->
<el-form-item label='产品价格' prop='code'> <!-- <el-form-item label='产品价格' prop='code'>-->
<el-input v-model='formStore.productPrice' placeholder='请输入产品价格'/> <!-- <el-input v-model='formStore.productPrice' placeholder='请输入产品价格'/>-->
</el-form-item> <!-- </el-form-item>-->
<el-form-item label='产品描述' prop='type'> <!-- <el-form-item label='产品描述' prop='type'>-->
<el-input v-model='formStore.productDescription' placeholder='请输入产品描述'/> <!-- <el-input v-model='formStore.productDescription' placeholder='请输入产品描述'/>-->
</el-form-item> <!-- </el-form-item>-->
<el-form-item label='tags' prop='order'> <!-- <el-form-item label='tags' prop='order'>-->
<el-input v-model='formStore.tags' placeholder='请输入tags'/> <!-- <el-input v-model='formStore.tags' placeholder='请输入tags'/>-->
</el-form-item> <!-- </el-form-item>-->
</el-form> <!-- </el-form>-->
<span slot='footer' class='dialog-footer'> <!-- <span slot='footer' class='dialog-footer'>-->
<el-button @click='cropperVisible = false'> </el-button> <!-- <el-button @click='cropperVisible = false'> </el-button>-->
<el-button type='primary' @click='handelStore'> </el-button> <!-- <el-button type='primary' @click='handelStore'> </el-button>-->
</span> <!-- </span>-->
</el-dialog> <!-- </el-dialog>-->
<ImgCropper append-to-body @onSubmit="updateUser" :visible.sync='cropperVisible'
:avatarUrl="formStore.productImgUrl||''"></ImgCropper>
</div> </div>
</template> </template>
<script> <script>
import ImgCropper from "~/components/ImgCropper.vue";
import {mapState} from 'vuex'; import {mapState} from 'vuex';
import VueCropper from "vue-cropper"; // import VueCropper from "vue-cropper";
const rules = { const rules = {
productTitle: [ productTitle: [
@ -121,7 +120,7 @@ const rules = {
} }
export default { export default {
name: "products", name: "productsList",
middleware: 'auth', middleware: 'auth',
fetch() { fetch() {
let {store, params, error} = this.$nuxt.context let {store, params, error} = this.$nuxt.context
@ -146,15 +145,12 @@ export default {
isEdit: false isEdit: false
} }
}, },
components: {
ImgCropper, VueCropper
},
methods: { methods: {
onRouter(name, data) { // onRouter(name, data) {
this.$router.push({ // this.$router.push({
path: `/${name}/${data}` // path: `/${name}/${data}`
}) // })
}, // },
toggleStatus(index, product) { toggleStatus(index, product) {
let _ts = this; let _ts = this;
let title, status; let title, status;
@ -206,34 +202,37 @@ export default {
}) })
}, },
handleEdit(index, row) { handleEdit(index, row) {
this.formStore = row // this.formStore = {...row}
this.editVisible = true // this.editVisible = true
// this.$router.push({ this.$router.push({
// path: `/admin/product/post/${row.idProduct}` path: `/admin/product/post/${row.idProduct}`,
// }) })
}, },
handelStore() { handelStore() {
// let _ts = this;
this.formStore.idProduct = this.formStore.idProduct ? this.formStore.idProduct : 0
_ts.$axios[this.formStore.idProduct ? '$put' : '$post']('/api/product/post', this.formStore).then(function (res) {
if (res) {
console.log('res')
// _ts.$router.push({
// path: `/product/${res}`
// })
}
})
}, },
updateUser(data) { updateUser(data) {
//
let _ts = this; let _ts = this;
if (data) { if (data) {
// let user = _ts.user;
this.formStore.productImgUrl = data this.formStore.productImgUrl = data
// user.avatarType = 1 this.formStore.productImgType = 1
_ts.$axios[this.formStore.idProduct ? '$put' : '$post']('/api/product/post', this.formStore).then(function (res) { // this.cropperVisible = false
if (res) {
console.log('res')
// _ts.$router.push({
// path: `/product/${res}`
// })
}
})
} else _ts.$message.error('失败,请重试'); } else _ts.$message.error('失败,请重试');
}, },
handleAdd() {
this.isEdit = false
this.formStore = {}
this.editVisible = true
}
} }
} }
</script> </script>

View File

@ -1,440 +1,435 @@
<template> <template>
<el-row class="products"> <div>
<el-col v-if="hasPermissions"> test
<el-col> test
<el-input </div>
v-model="productTitle"
class="product-title"
placeholder="请输入标题"
@change="setLocalstorage('title',productTitle)">
</el-input>
</el-col>
<el-col>
<div id="contentEditor"></div>
</el-col>
<el-col style="margin-top: 1rem;">
<el-select
style="width: 100%;"
v-model="productTags"
multiple
filterable
allow-create
default-first-option
remote
:remote-method="remoteMethod"
placeholder="请选择文章标签"
:loading="loading"
@change="setLocalstorage('tags',productTags)">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-col>
<el-col v-if="!isEdit" style="margin-top: 1rem;padding-right:3rem;text-align: right;">
<el-button :loading="doLoading" @click="saveArticle" plain>保存草稿</el-button>
<el-button type="primary" :loading="doLoading" @click="postArticle" plain>发布</el-button>
</el-col>
<el-col v-else style="margin-top: 1rem;padding-right:3rem;text-align: right;">
<el-button type="danger" :loading="doLoading" @click="deleteArticle" plain>删除</el-button>
<el-button v-if="productStatus === '1'" :loading="doLoading" @click="saveArticle" plain>保存草稿</el-button>
<el-button v-if="productStatus === '0'" :loading="doLoading" type="primary" @click="postArticle" plain>更新</el-button>
<el-button v-else type="primary" :loading="doLoading" @click="postArticle" plain>发布</el-button>
</el-col>
</el-col>
<el-col v-else class="text-center">
<el-alert
title="用户无权限"
type="warning"
center
show-icon
:closable="false">
</el-alert>
</el-col>
</el-row>
</template> </template>
<!--<template>-->
<!-- <el-row class="products">-->
<!-- <el-col>-->
<!-- <el-col>-->
<!-- <el-input-->
<!-- v-model="productTitle"-->
<!-- class="product-title"-->
<!-- placeholder="请输入标题"-->
<!-- @change="setLocalstorage('title',productTitle)">-->
<!-- </el-input>-->
<!-- </el-col>-->
<!-- <el-col>-->
<!-- <div id="contentEditor"></div>-->
<!-- </el-col>-->
<!-- <el-col style="margin-top: 1rem;">-->
<!-- </el-col>-->
<!-- <el-col v-if="!isEdit" style="margin-top: 1rem;padding-right:3rem;text-align: right;">-->
<!-- <el-button :loading="doLoading" @click="saveArticle" plain>保存草稿</el-button>-->
<!-- <el-button type="primary" :loading="doLoading" @click="postArticle" plain>发布</el-button>-->
<!-- </el-col>-->
<!-- <el-col v-else style="margin-top: 1rem;padding-right:3rem;text-align: right;">-->
<!-- <el-button type="danger" :loading="doLoading" @click="deleteArticle" plain>删除</el-button>-->
<!-- <el-button v-if="productStatus === '1'" :loading="doLoading" @click="saveArticle" plain>保存草稿</el-button>-->
<!-- <el-button v-if="productStatus === '0'" :loading="doLoading" type="primary" @click="postArticle" plain>更新</el-button>-->
<!-- <el-button v-else type="primary" :loading="doLoading" @click="postArticle" plain>发布</el-button>-->
<!-- </el-col>-->
<!-- </el-col>-->
<!--&lt;!&ndash; <el-col v-else class="text-center">&ndash;&gt;-->
<!--&lt;!&ndash; <el-alert&ndash;&gt;-->
<!--&lt;!&ndash; title="用户无权限"&ndash;&gt;-->
<!--&lt;!&ndash; type="warning"&ndash;&gt;-->
<!--&lt;!&ndash; center&ndash;&gt;-->
<!--&lt;!&ndash; show-icon&ndash;&gt;-->
<!--&lt;!&ndash; :closable="false">&ndash;&gt;-->
<!--&lt;!&ndash; </el-alert>&ndash;&gt;-->
<!--&lt;!&ndash; </el-col>&ndash;&gt;-->
<!-- </el-row>-->
<!--</template>-->
<script> <!--<script>-->
import Vue from 'vue'; <!--import Vue from 'vue';-->
import {mapState} from 'vuex'; <!--import {mapState} from 'vuex';-->
import apiConfig from '~/config/api.config'; <!--import apiConfig from '~/config/api.config';-->
export default { <!--export default {-->
name: "PostProducts", <!-- name: "PostProducts",-->
middleware: 'auth', <!-- middleware: 'auth',-->
validate({params, store}) { <!-- validate({params, store}) {-->
if (typeof params.product_id === 'undefined') { <!-- if (typeof params.product_id === 'undefined') {-->
return true; <!-- return true;-->
} <!-- }-->
return params.product_id && !isNaN(Number(params.product_id)) <!-- return params.product_id && !isNaN(Number(params.product_id))-->
}, <!-- },-->
asyncData({store, params, error}) { <!-- asyncData({store, params, error}) {-->
return Promise.all([ <!-- return Promise.all([-->
store.dispatch('product/fetchPostDetail', params) <!-- store.dispatch('product/fetchPostDetail', params)-->
.catch(err => error({statusCode: 404})) <!-- .catch(err => error({statusCode: 404}))-->
]) <!-- ])-->
}, <!-- },-->
computed: { <!-- computed: {-->
...mapState({ <!-- ...mapState({-->
product: state => state.product.detail.data <!-- product: state => state.product.detail.data-->
}), <!-- }),-->
hasPermissions() { <!-- // hasPermissions() {-->
let account = this.$store.state.auth.user?.nickname; <!-- // let account = this.$store.state.auth.user?.nickname;-->
if (account) { <!-- // if (account) {-->
if (this.$route.params.product_id) { <!-- // if (this.$route.params.product_id) {-->
if (account === this.product.productAuthor.userNickname) { <!-- // if (account === this.product.productAuthor.userNickname) {-->
return true; <!-- // return true;-->
} <!-- // }-->
} else { <!-- // } else {-->
return true; <!-- // return true;-->
} <!-- // }-->
} <!-- // }-->
return this.$auth.hasScope('blog_admin') || this.$auth.hasScope('admin'); <!-- // return this.$auth.hasScope('blog_admin') || this.$auth.hasScope('admin');-->
} <!-- // }-->
}, <!-- },-->
data() { <!-- data() {-->
return { <!-- return {-->
contentEditor: null, <!-- contentEditor: null,-->
tokenURL: { <!-- tokenURL: {-->
URL: '', <!-- URL: '',-->
linkToImageURL: '', <!-- linkToImageURL: '',-->
token: '' <!-- token: ''-->
}, <!-- },-->
idArticle: 0, <!-- formStore:{-->
productTitle: '', <!-- idArticle: 0,-->
productContent: '', <!-- productTitle: '',-->
productType: 0, <!-- productContent: '',-->
productTags: [], <!-- productType: 0,-->
productStatus: '0', <!-- productTags: [],-->
options: [], <!-- productStatus: '0',-->
list: [], <!-- },-->
loading: false, <!-- idArticle: 0,-->
doLoading: false, <!-- productTitle: '',-->
isEdit: false, <!-- productContent: '',-->
notificationFlag: true <!-- productType: 0,-->
} <!-- productTags: [],-->
}, <!-- productStatus: '0',-->
methods: { <!-- options: [],-->
_initEditor(data) { <!-- list: [],-->
let _ts = this; <!-- loading: false,-->
<!-- doLoading: false,-->
<!-- isEdit: false,-->
<!-- notificationFlag: true-->
<!-- }-->
<!-- },-->
<!-- methods: {-->
<!-- _initEditor(data) {-->
<!-- let _ts = this;-->
let toolbar = [ <!-- let toolbar = [-->
'emoji', <!-- 'emoji',-->
'headings', <!-- 'headings',-->
'bold', <!-- 'bold',-->
'italic', <!-- 'italic',-->
'strike', <!-- 'strike',-->
'link', <!-- 'link',-->
'|', <!-- '|',-->
'list', <!-- 'list',-->
'ordered-list', <!-- 'ordered-list',-->
'check', <!-- 'check',-->
'outdent', <!-- 'outdent',-->
'indent', <!-- 'indent',-->
'|', <!-- '|',-->
'quote', <!-- 'quote',-->
'line', <!-- 'line',-->
'code', <!-- 'code',-->
'inline-code', <!-- 'inline-code',-->
'insert-before', <!-- 'insert-before',-->
'insert-after', <!-- 'insert-after',-->
'|', <!-- '|',-->
'upload', <!-- 'upload',-->
// 'record', <!-- // 'record',-->
'table', <!-- 'table',-->
'|', <!-- '|',-->
'undo', <!-- 'undo',-->
'redo', <!-- 'redo',-->
'|', <!-- '|',-->
'edit-mode', <!-- 'edit-mode',-->
{ <!-- {-->
name: 'more', <!-- name: 'more',-->
toolbar: [ <!-- toolbar: [-->
'fullscreen', <!-- 'fullscreen',-->
'both', <!-- 'both',-->
'preview', <!-- 'preview',-->
'info' <!-- 'info'-->
], <!-- ],-->
}] <!-- }]-->
return new Vue.Vditor(data.id, { <!-- return new Vue.Vditor(data.id, {-->
toolbar, <!-- toolbar,-->
mode: 'sv', <!-- mode: 'sv',-->
tab: '\t', <!-- tab: '\t',-->
cdn: apiConfig.VDITOR, <!-- cdn: apiConfig.VDITOR,-->
cache: { <!-- cache: {-->
enable: this.$route.params.product_id ? false : true, <!-- enable: this.$route.params.product_id ? false : true,-->
id: this.$route.params.product_id ? this.$route.params.product_id : '', <!-- id: this.$route.params.product_id ? this.$route.params.product_id : '',-->
}, <!-- },-->
after() { <!-- after() {-->
_ts.contentEditor.setValue(data.value ? data.value : ''); <!-- _ts.contentEditor.setValue(data.value ? data.value : '');-->
}, <!-- },-->
hint: { <!-- hint: {-->
emoji: Vue.emoji <!-- emoji: Vue.emoji-->
}, <!-- },-->
preview: { <!-- preview: {-->
hljs: { <!-- hljs: {-->
enable: true, <!-- enable: true,-->
lineNumber: true, <!-- lineNumber: true,-->
style: 'github' <!-- style: 'github'-->
}, <!-- },-->
markdown: { <!-- markdown: {-->
toc: true, <!-- toc: true,-->
autoSpace: true <!-- autoSpace: true-->
}, <!-- },-->
math: { <!-- math: {-->
inlineDigit: true <!-- inlineDigit: true-->
}, <!-- },-->
delay: 500, <!-- delay: 500,-->
mode: data.mode, <!-- mode: data.mode,-->
/*url: `${process.env.Server}/api/console/markdown`,*/ <!-- /*url: `${process.env.Server}/api/console/markdown`,*/-->
parse: (element) => { <!-- parse: (element) => {-->
if (element.style.display === 'none') { <!-- if (element.style.display === 'none') {-->
return <!-- return-->
} <!-- }-->
// LazyLoadImage(); <!-- // LazyLoadImage();-->
// Vue.Vditor.highlightRender({style: 'github'}, element, this.contentEditor); <!-- // Vue.Vditor.highlightRender({style: 'github'}, element, this.contentEditor);-->
}, <!-- },-->
theme: { <!-- theme: {-->
cdn: apiConfig.VDITOR_CSS <!-- cdn: apiConfig.VDITOR_CSS-->
} <!-- }-->
}, <!-- },-->
upload: { <!-- upload: {-->
max: 10 * 1024 * 1024, <!-- max: 10 * 1024 * 1024,-->
url: this.tokenURL.URL, <!-- url: this.tokenURL.URL,-->
linkToImgUrl: this.tokenURL.linkToImageURL, <!-- linkToImgUrl: this.tokenURL.linkToImageURL,-->
token: this.tokenURL.token, <!-- token: this.tokenURL.token,-->
filename: name => name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, ''). <!-- filename: name => name.replace(/[^(a-zA-Z0-9\u4e00-\u9fa5\.)]/g, '').-->
replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, ''). <!-- replace(/[\?\\/:|<>\*\[\]\(\)\$%\{\}@~]/g, '').-->
replace('/\\s/g', '') <!-- replace('/\\s/g', '')-->
}, <!-- },-->
height: data.height, <!-- height: data.height,-->
counter: 102400, <!-- counter: 102400,-->
resize: { <!-- resize: {-->
enable: data.resize, <!-- enable: data.resize,-->
}, <!-- },-->
lang: this.$store.state.locale, <!-- lang: this.$store.state.locale,-->
placeholder: data.placeholder, <!-- placeholder: data.placeholder,-->
}) <!-- })-->
}, <!-- },-->
setLocalstorage(type) { <!-- setLocalstorage(type) {-->
if (typeof arguments[0] === 'object') { <!-- if (typeof arguments[0] === 'object') {-->
localStorage.setItem('productTags', arguments[1]); <!-- localStorage.setItem('productTags', arguments[1]);-->
return <!-- return-->
} <!-- }-->
switch (type) { <!-- switch (type) {-->
case 'title': { <!-- case 'title': {-->
localStorage.setItem('product-title', arguments[1]) <!-- localStorage.setItem('product-title', arguments[1])-->
break; <!-- break;-->
} <!-- }-->
case 'tags': { <!-- case 'tags': {-->
localStorage.setItem('product-tags', arguments[1]); <!-- localStorage.setItem('product-tags', arguments[1]);-->
break; <!-- break;-->
} <!-- }-->
} <!-- }-->
}, <!-- },-->
remoteMethod(query) { <!-- remoteMethod(query) {-->
if (query !== '') { <!-- if (query !== '') {-->
this.loading = true; <!-- this.loading = true;-->
setTimeout(() => { <!-- setTimeout(() => {-->
this.loading = false; <!-- this.loading = false;-->
this.options = this.list.filter(item => { <!-- this.options = this.list.filter(item => {-->
return item.label.toLowerCase() <!-- return item.label.toLowerCase()-->
.indexOf(query.toLowerCase()) > -1; <!-- .indexOf(query.toLowerCase()) > -1;-->
}); <!-- });-->
}, 200); <!-- }, 200);-->
} else { <!-- } else {-->
this.options = []; <!-- this.options = [];-->
} <!-- }-->
}, <!-- },-->
deleteArticle() { <!-- deleteArticle() {-->
let _ts = this; <!-- let _ts = this;-->
_ts.doLoading = true; <!-- _ts.doLoading = true;-->
this.$confirm('确定删除吗?', '提示', { <!-- this.$confirm('确定删除吗?', '提示', {-->
confirmButtonText: '确定', <!-- confirmButtonText: '确定',-->
cancelButtonText: '取消', <!-- cancelButtonText: '取消',-->
type: 'warning' <!-- type: 'warning'-->
}).then(() => { <!-- }).then(() => {-->
let id = _ts.$route.params.product_id; <!-- let id = _ts.$route.params.product_id;-->
_ts.$axios.$delete('/api/product/delete/' + id).then(function (res) { <!-- _ts.$axios.$delete('/api/product/delete/' + id).then(function (res) {-->
if (res && res.message) { <!-- if (res && res.message) {-->
_ts.$message(res.message); <!-- _ts.$message(res.message);-->
return false; <!-- return false;-->
} <!-- }-->
localStorage.removeItem('product-title'); <!-- localStorage.removeItem('product-title');-->
localStorage.removeItem('product-tags'); <!-- localStorage.removeItem('product-tags');-->
_ts.contentEditor.setValue(''); <!-- _ts.contentEditor.setValue('');-->
_ts.$set(_ts, 'notificationFlag', false); <!-- _ts.$set(_ts, 'notificationFlag', false);-->
_ts.$router.push({ <!-- _ts.$router.push({-->
name: 'index' <!-- name: 'index'-->
}) <!-- })-->
}) <!-- })-->
}).catch(() => { <!-- }).catch(() => {-->
_ts.doLoading = false; <!-- _ts.doLoading = false;-->
}); <!-- });-->
}, <!-- },-->
async postArticle() { <!-- async postArticle() {-->
let _ts = this; <!-- let _ts = this;-->
_ts.doLoading = true; <!-- _ts.doLoading = true;-->
let id = _ts.$route.params.product_id; <!-- let id = _ts.$route.params.product_id;-->
let productContent = _ts.contentEditor.getValue(); <!-- let productContent = _ts.contentEditor.getValue();-->
let productContentHtml = await _ts.contentEditor.getHTML(); <!-- let productContentHtml = await _ts.contentEditor.getHTML();-->
if (!(_ts.productTitle && productContent)) { <!-- if (!(_ts.productTitle && productContent)) {-->
_ts.$message("标题/正文不能为空!"); <!-- _ts.$message("标题/正文不能为空!");-->
_ts.doLoading = false; <!-- _ts.doLoading = false;-->
return false; <!-- return false;-->
} <!-- }-->
let product = { <!-- let product = {-->
idArticle: _ts.idArticle, <!-- idArticle: _ts.idArticle,-->
productTitle: _ts.productTitle, <!-- productTitle: _ts.productTitle,-->
productContent: productContent, <!-- productContent: productContent,-->
productContentHtml: productContentHtml, <!-- productContentHtml: productContentHtml,-->
productTags: _ts.productTags.join(","), <!-- productTags: _ts.productTags.join(","),-->
productStatus: 0 <!-- productStatus: 0-->
}; <!-- };-->
_ts.$axios[id ? '$put' : '$post']('/api/product/post', product).then(function (res) { <!-- _ts.$axios[id ? '$put' : '$post']('/api/product/post', product).then(function (res) {-->
if (res) { <!-- if (res) {-->
if (res.message) { <!-- if (res.message) {-->
_ts.$message(res.message); <!-- _ts.$message(res.message);-->
_ts.doLoading = false; <!-- _ts.doLoading = false;-->
return false; <!-- return false;-->
} <!-- }-->
localStorage.removeItem('product-title'); <!-- localStorage.removeItem('product-title');-->
localStorage.removeItem('product-tags'); <!-- localStorage.removeItem('product-tags');-->
_ts.contentEditor.setValue(''); <!-- _ts.contentEditor.setValue('');-->
_ts.$store.commit('product/clearDetailData') <!-- _ts.$store.commit('product/clearDetailData')-->
_ts.$set(_ts, 'notificationFlag', false); <!-- _ts.$set(_ts, 'notificationFlag', false);-->
_ts.$router.push({ <!-- _ts.$router.push({-->
path: `/product/${res}` <!-- path: `/product/${res}`-->
}) <!-- })-->
} <!-- }-->
}) <!-- })-->
}, <!-- },-->
async saveArticle() { <!-- async saveArticle() {-->
let _ts = this; <!-- let _ts = this;-->
_ts.doLoading = true; <!-- _ts.doLoading = true;-->
let id = _ts.$route.params.product_id; <!-- let id = _ts.$route.params.product_id;-->
let productContent = _ts.contentEditor.getValue(); <!-- let productContent = _ts.contentEditor.getValue();-->
let productContentHtml = await _ts.contentEditor.getHTML(); <!-- let productContentHtml = await _ts.contentEditor.getHTML();-->
if (!(_ts.productTitle && productContent)) { <!-- if (!(_ts.productTitle && productContent)) {-->
_ts.$message("标题/正文不能为空!"); <!-- _ts.$message("标题/正文不能为空!");-->
_ts.doLoading = false; <!-- _ts.doLoading = false;-->
return false; <!-- return false;-->
} <!-- }-->
let product = { <!-- let product = {-->
idArticle: _ts.idArticle, <!-- idArticle: _ts.idArticle,-->
productTitle: _ts.productTitle, <!-- productTitle: _ts.productTitle,-->
productContent: productContent, <!-- productContent: productContent,-->
productContentHtml: productContentHtml, <!-- productContentHtml: productContentHtml,-->
productTags: _ts.productTags.join(","), <!-- productTags: _ts.productTags.join(","),-->
productStatus: 1 <!-- productStatus: 1-->
}; <!-- };-->
_ts.$axios[id ? '$put' : '$post']('/api/product/post', product).then(function (res) { <!-- _ts.$axios[id ? '$put' : '$post']('/api/product/post', product).then(function (res) {-->
if (res) { <!-- if (res) {-->
if (res.message) { <!-- if (res.message) {-->
_ts.$message(res.message); <!-- _ts.$message(res.message);-->
_ts.doLoading = false; <!-- _ts.doLoading = false;-->
return false; <!-- return false;-->
} <!-- }-->
localStorage.removeItem('product-title'); <!-- localStorage.removeItem('product-title');-->
localStorage.removeItem('product-tags'); <!-- localStorage.removeItem('product-tags');-->
_ts.contentEditor.setValue(''); <!-- _ts.contentEditor.setValue('');-->
_ts.$set(_ts, 'notificationFlag', false); <!-- _ts.$set(_ts, 'notificationFlag', false);-->
_ts.$router.push({ <!-- _ts.$router.push({-->
path: `/draft/${res}` <!-- path: `/draft/${res}`-->
}) <!-- })-->
} <!-- }-->
}) <!-- })-->
}, <!-- },-->
getTags() { <!-- getTags() {-->
let _ts = this; <!-- let _ts = this;-->
_ts.$axios.$get('/api/tag/tags').then(function (res) { <!-- _ts.$axios.$get('/api/tag/tags').then(function (res) {-->
if (res) { <!-- if (res) {-->
_ts.$set(_ts, 'list', res); <!-- _ts.$set(_ts, 'list', res);-->
} <!-- }-->
}) <!-- })-->
} <!-- }-->
}, <!-- },-->
beforeRouteLeave(to, from, next) { <!-- beforeRouteLeave(to, from, next) {-->
let _ts = this; <!-- let _ts = this;-->
if (_ts.notificationFlag) { <!-- if (_ts.notificationFlag) {-->
_ts.$confirm('系统可能不会保存您所做的更改。', '离开此网站?', { <!-- _ts.$confirm('系统可能不会保存您所做的更改。', '离开此网站?', {-->
confirmButtonText: '确定', <!-- confirmButtonText: '确定',-->
cancelButtonText: '取消', <!-- cancelButtonText: '取消',-->
type: 'warning' <!-- type: 'warning'-->
}).then(() => { <!-- }).then(() => {-->
next(); <!-- next();-->
}).catch(() => { <!-- }).catch(() => {-->
return false <!-- return false-->
}); <!-- });-->
_ts.$store.commit("setActiveMenu", "product-post"); <!-- _ts.$store.commit("setActiveMenu", "product-post");-->
} else { <!-- } else {-->
next(); <!-- next();-->
} <!-- }-->
}, <!-- },-->
beforeDestroy() { <!-- beforeDestroy() {-->
window.onbeforeunload = null; <!-- window.onbeforeunload = null;-->
}, <!-- },-->
async mounted() { <!-- async mounted() {-->
console.log('??') <!-- console.log('??')-->
if (!this.hasPermissions) { <!-- // if (!this.hasPermissions) {-->
return <!-- // return-->
} <!-- // }-->
window.addEventListener('beforeunload', e => { <!-- window.addEventListener('beforeunload', e => {-->
e = e || window.event; <!-- e = e || window.event;-->
// IE8Firefox 4 <!-- // IE8Firefox 4-->
if (e) { <!-- if (e) {-->
e.returnValue = '关闭提示'; <!-- e.returnValue = '关闭提示';-->
} <!-- }-->
// Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+ <!-- // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+-->
return '关闭提示'; <!-- return '关闭提示';-->
}); <!-- });-->
let _ts = this; <!-- let _ts = this;-->
_ts.$store.commit('setActiveMenu', 'product-post'); <!-- _ts.$store.commit('setActiveMenu', 'product-post');-->
const responseData = await _ts.$axios.$get('/api/upload/token'); <!-- const responseData = await _ts.$axios.$get('/api/upload/token');-->
if (responseData) { <!-- if (responseData) {-->
_ts.$set(_ts, 'tokenURL', { <!-- _ts.$set(_ts, 'tokenURL', {-->
token: responseData.uploadToken || '', <!-- token: responseData.uploadToken || '',-->
URL: responseData.uploadURL || '', <!-- URL: responseData.uploadURL || '',-->
linkToImageURL: responseData.linkToImageURL || '' <!-- linkToImageURL: responseData.linkToImageURL || ''-->
}) <!-- })-->
} <!-- }-->
_ts.getTags(); <!-- _ts.getTags();-->
Vue.nextTick(() => { <!-- Vue.nextTick(() => {-->
let productContent = ''; <!-- let productContent = '';-->
if (_ts.$route.params.product_id) { <!-- if (_ts.$route.params.product_id) {-->
_ts.$set(_ts, 'isEdit', true); <!-- _ts.$set(_ts, 'isEdit', true);-->
let product = _ts.product; <!-- let product = _ts.product;-->
_ts.$set(_ts, 'idArticle', product.idArticle); <!-- _ts.$set(_ts, 'idArticle', product.idArticle);-->
_ts.$set(_ts, 'productTitle', product.productTitle); <!-- _ts.$set(_ts, 'productTitle', product.productTitle);-->
_ts.$set(_ts, 'productContent', product.productContent); <!-- _ts.$set(_ts, 'productContent', product.productContent);-->
_ts.$set(_ts, 'productStatus', product.productStatus); <!-- _ts.$set(_ts, 'productStatus', product.productStatus);-->
_ts.$set(_ts, 'productTags', (product.productTags).split(',')); <!-- _ts.$set(_ts, 'productTags', (product.productTags).split(','));-->
localStorage.setItem("product-title", product.productTitle); <!-- localStorage.setItem("product-title", product.productTitle);-->
localStorage.setItem("product-tags", (product.productTags).split(',')); <!-- localStorage.setItem("product-tags", (product.productTags).split(','));-->
productContent = product.productContent <!-- productContent = product.productContent-->
} else { <!-- } else {-->
_ts.$set(_ts, 'isEdit', false); <!-- _ts.$set(_ts, 'isEdit', false);-->
} <!-- }-->
_ts.contentEditor = _ts._initEditor({ <!-- _ts.contentEditor = _ts._initEditor({-->
id: 'contentEditor', <!-- id: 'contentEditor',-->
mode: 'both', <!-- mode: 'both',-->
height: 480, <!-- height: 480,-->
placeholder: '', //_ts.$t('inputContent', _ts.$store.state.locale) <!-- placeholder: '', //_ts.$t('inputContent', _ts.$store.state.locale)-->
resize: false, <!-- resize: false,-->
value: productContent <!-- value: productContent-->
}); <!-- });-->
}) <!-- })-->
} <!-- }-->
} <!--}-->
</script> <!--</script>-->
<style lang="less"> <!--<style lang="less">-->
@import "~vditor/src/assets/less/index.less"; <!--@import "~vditor/src/assets/less/index.less";-->
</style> <!--</style>-->

View File

@ -93,7 +93,6 @@
<script> <script>
import {mapState} from 'vuex'; import {mapState} from 'vuex';
import ImgCropper from "~/components/ImgCropper.vue"; import ImgCropper from "~/components/ImgCropper.vue";
import VueCropper from "vue-cropper";
import saveSvg from "save-svg-as-png"; import saveSvg from "save-svg-as-png";
import Avataaars from 'vuejs-avataaars'; import Avataaars from 'vuejs-avataaars';
@ -103,7 +102,7 @@ export default {
name: "account", name: "account",
middleware: 'auth', middleware: 'auth',
components: { components: {
ImgCropper, VueCropper, Avataaars ImgCropper, Avataaars
}, },
computed: { computed: {
...mapState({ ...mapState({