1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
<div class="app-content" style="max-height:75vh;overflow:auto;">
<a-spin :spinning="loading" style="width:100%;height:100%;">
<a-form-model ref="from" :model="formData" :rules="rules" style="border-top: 0px" class="from-table font-line-space">
<a-row>
<a-col :span="24" style="border-top: 0px;">
<div class="tb-title">
<span>通知发布</span>
</div>
</a-col>
</a-row>
<a-row type="flex">
<a-col :span="2" class="bg-gray">
<div class="special-middle">
<div class="required">标题</div>
</div>
</a-col>
<a-col :span="22">
<a-form-model-item prop="title">
<a-input placeholder="项目合同编号" v-model="formData.title" :maxLength="100" style="width: 80%" />
</a-form-model-item>
</a-col>
</a-row>
<a-row>
<a-col :span="24" style="border-top: 0px;">
<div class="tb-title">
<span>内容</span>
</div>
</a-col>
</a-row>
<a-row>
<a-col :span="24">
<a-form-model-item prop="content">
<textarea name="" id="tinymce_dom" v-model="formData.content"></textarea>
</a-form-model-item>
<!-- <a-col :span="24" style="line-height: 1.5;">
<span>当前字数:{{tinymceWordCount}}</span>
<span style="margin-left: 50px;">还可以输入{{tinymceLimit - tinymceWordCount}}字</span>
</a-col> -->
</a-col>
</a-row>
</a-form-model>
</a-spin>
</div>
</template>
<script>
export default {
name: "noticeEdit",
components: {},
props: {
value: {
type: String,
default: () => {
return null;
},
},
},
data () {
return {
formData: { title: null, content: null },
rules: {
title: [{ required: true, message: '请填写标题', trigger: 'blur' },],
content: [{ required: true, message: '请填写内容', trigger: 'blur' },],
},
loading: false,
// 富文本字数
tinymceLimit: 15000,
tinymceWordCount: 0,
};
},
watch: {
},
computed: {
textContent () {
return tinymce.activeEditor.getContent()
}
},
mounted () {
this.tinymceSet()
},
created () {
this.getById()
},
computed: {
},
methods: {
getById () {
if (!!this.value) {
this.loading = true
this.$api.notice.getById({ id: this.value }).then(({ data = {} }) => {
if (data) {
this.formData = data
tinyMCE.activeEditor.setContent(data.content)
}
this.loading = false
}).catch(() => {
this.loading = false
})
}
},
submit () {
this.formData.content = tinymce.activeEditor.getContent()
this.$refs.from.validate(valid => {
if (valid) {
this.loading = true
this.$api.notice.save(this.formData).then(({ data = {} }) => {
if (data) {
this.formData.id = data
this.$emit('close', 'edit')
}
}).catch(() => { this.loading = false })
} else {
this.$message.error('信息未填写完全,请检查!')
return false
}
})
},
tinymceSet () {
tinymce.remove('#tinymce_dom')
tinymce.init({
selector: '#tinymce_dom',
language: 'zh_CN',
content_style: "img {max-width:100%;}",
// menubar: false,
// 隐藏底部状态栏
statusbar: false,
height: 800,
plugins: 'code advlist autolink link image lists preview table wordcount',
toolbar: `undo redo | styleselect | fontsizeselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist | link image
| table tabledelete | tableprops tablerowprops tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow
| tableinsertcolbefore tableinsertcolafter tabledeletecol | wordcount`,
// 初始化完成回调
init_instance_callback: (editor) => {
// let wordcount = editor.plugins.wordcount
// this.tinymceWordCount = wordcount.body.getWordCount()
},
// 图片上传路径
// images_upload_url: 'http://192.168.1.185:8888/profile',
// 图片上传操作
images_upload_handler: (blobInfo, succFun, failFun) => {
this.$api.base.asyncUpload(this.uploadHandle(blobInfo.blob(), blobInfo.filename())).then(({ data = {} }) => {
if (data) {
succFun(data.downloadUrl)
}
}).catch((err) => { failFun(err) })
}
})
// 设置富文本内容
// tinymce.activeEditor.setContent(htmlText)
// 监听输入计算字数
let mark = 1
tinymce.activeEditor.on('keyup', (e) => {
if (mark === 1) {
// let wordcount = tinymce.activeEditor.plugins.wordcount
// this.tinymceWordCount = wordcount.body.getWordCount()
mark = 0
setTimeout(() => { mark = 1 }, 500)
}
})
},
uploadHandle (file, fileName) {
let formData = new FormData()
formData.append('file', file)
formData.append('fileName', fileName)
return formData
},
},
};
</script>
<style scoped lang="less">
</style>