|
@@ -35,7 +35,7 @@ var articleEdit = new Vue({
|
|
|
// 来源
|
|
|
source: '',
|
|
|
// 状态
|
|
|
- status: 1,
|
|
|
+ status: 0,
|
|
|
// 文章分类
|
|
|
typeId: ''
|
|
|
},
|
|
@@ -89,7 +89,10 @@ var articleEdit = new Vue({
|
|
|
formValidate: {},
|
|
|
variable: '',
|
|
|
remoteLoading: false,
|
|
|
- labelList: []
|
|
|
+ labelList: [],
|
|
|
+ validTime: null,
|
|
|
+ isValidSave: 0, // 是否开启自动保存
|
|
|
+ isFocus: false, // 是否聚焦
|
|
|
},
|
|
|
watch: {
|
|
|
chooseLabels: function chooseLabels(newVal) {
|
|
@@ -101,7 +104,7 @@ var articleEdit = new Vue({
|
|
|
}
|
|
|
if (newVal === oldVal) return;
|
|
|
this.chooseLabels = newVal.split(',');
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
created: function created() {
|
|
|
this.init();
|
|
@@ -115,6 +118,16 @@ var articleEdit = new Vue({
|
|
|
localStorage.removeItem('articleId');
|
|
|
},
|
|
|
methods: {
|
|
|
+ onFocused() {
|
|
|
+ this.validTime = null
|
|
|
+ console.log(111)
|
|
|
+ clearTimeout(this.validTime)
|
|
|
+ },
|
|
|
+ onBlured() {
|
|
|
+ this.isFocus = true
|
|
|
+ this.validFormRule()
|
|
|
+ console.log(222)
|
|
|
+ },
|
|
|
// 页面初始化
|
|
|
init: function init() {
|
|
|
var articleId = localStorage.getItem('articleId') || 0;
|
|
@@ -141,6 +154,28 @@ var articleEdit = new Vue({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ // 自动保存校验
|
|
|
+ validFormRule() {
|
|
|
+ let allow = true
|
|
|
+ const ruleData = Object.keys(this.rules)
|
|
|
+ for(let i of ruleData){
|
|
|
+ if (!this.formData[i]) {
|
|
|
+ allow = false
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (allow) {
|
|
|
+ this.validTime = null
|
|
|
+ clearTimeout(this.validTime)
|
|
|
+ this.validTime = setTimeout(() => {
|
|
|
+ if (this.validTime) {
|
|
|
+ this.handleSave()
|
|
|
+ }
|
|
|
+ clearTimeout(this.validTime)
|
|
|
+ this.validTime = null
|
|
|
+ }, 5000)
|
|
|
+ }
|
|
|
+ },
|
|
|
// 设置表单初始数据
|
|
|
setFormData: function setFormData(shopArticle) {
|
|
|
for (var key in this.formData) {
|
|
@@ -193,6 +228,7 @@ var articleEdit = new Vue({
|
|
|
handleUploadSuccess: function handleUploadSuccess(response, file, fileList) {
|
|
|
this.formData.guidanceImage = response.data;
|
|
|
this.articleImageList = fileList;
|
|
|
+ console.log(fileList)
|
|
|
},
|
|
|
// 图片移除
|
|
|
handleImageRemove: function handleImageRemove(response, file, fileList) {
|
|
@@ -205,7 +241,7 @@ var articleEdit = new Vue({
|
|
|
this.$refs.ruleForm.validate(valide=>{
|
|
|
if(!valide) return;
|
|
|
// _this.save();
|
|
|
- const params = {..._this.formData, labelIds: _this.formData.labelIds.join(',')}
|
|
|
+ const params = {..._this.formData, labelIds: (_this.formData.labelIds && _this.formData.labelIds.length > 0) ? _this.formData.labelIds.join(',') : ''}
|
|
|
_this.sensitiveWordsValidate(params)
|
|
|
});
|
|
|
},
|
|
@@ -220,7 +256,7 @@ var articleEdit = new Vue({
|
|
|
if(!valide) return;
|
|
|
// _this.save();
|
|
|
const date = new Date()
|
|
|
- const params = {..._this.formData, labelIds: _this.formData.labelIds.join(','), publishDate: date.getFullYear() + '-'+(date.getMonth() +1)+'-'+date.getDay() +' ' + date.getHours() + ':' +date.getMinutes() + ':' +date.getSeconds()}
|
|
|
+ const params = {..._this.formData, labelIds: (_this.formData.labelIds && _this.formData.labelIds.length > 0) ? _this.formData.labelIds.join(',') : '', publishDate: date.getFullYear() + '-'+(date.getMonth() +1)+'-'+date.getDay() +' ' + date.getHours() + ':' +date.getMinutes() + ':' +date.getSeconds()}
|
|
|
window.localStorage.setItem('articelData', JSON.stringify(params))
|
|
|
window.open('/supplier/article/preview.html');
|
|
|
});
|