Skip to content

Commit

Permalink
上传组件
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaotoday committed May 21, 2018
1 parent 734ef83 commit fb1dd28
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/Editor/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 重写插入图片插件
* @param editHandler {Function} edit 事件
*/
export const overrideImagePlugin = (editHandler) => {
KindEditor.plugin('image', function (K) {
export const overrideImagePlugin = editHandler => {
window.KindEditor.plugin('image', function (K) {
this.plugin.image = {
edit: editHandler,
delete: () => {
Expand Down
10 changes: 9 additions & 1 deletion src/components/Uploader/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
:on-format-error="handleFormatError"
:on-exceeded-size="handleMaxSize"
:before-upload="handleBeforeUpload"
action="//jsonplaceholder.typicode.com/posts/">
:headers="headers"
action="//localhost:3002/apis/v1/files">
<Button type="ghost" icon="ios-cloud-upload-outline">上传文件</Button>
</Upload>
<Modal title="查看图片" v-model="visible">
Expand All @@ -31,6 +32,8 @@
</div>
</template>
<script>
import restHelpers from '@/utils/helpers/restHelpers'
export default {
data () {
return {
Expand All @@ -40,6 +43,11 @@
uploadList: []
}
},
computed: {
headers () {
return restHelpers.getHeaders()
}
},
props: {
value: {
type: Number,
Expand Down
7 changes: 6 additions & 1 deletion src/modules/Articles/Form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<Editor ref="editor" v-model="formValidate.content" @change="handleEditorChange"></Editor>
<Input v-model="formValidate.content" style="display: none;"></Input>
</Form-item>
<Form-item label="文件" prop="content">
<Uploader></Uploader>
</Form-item>
<Form-item>
<Button type="primary" @click="handleSave" class="margin-right-sm">保存</Button>
<Button type="ghost" @click="$router.push('/articles')">返回</Button>
Expand All @@ -31,11 +34,13 @@
<script>
import { mapState } from 'vuex'
import Editor from '@/components/Editor'
import Uploader from '@/components/Uploader'
export default {
name: 'form',
components: {
Editor
Editor,
Uploader
},
created () {
this.id = this.$route.params.id
Expand Down
14 changes: 11 additions & 3 deletions src/utils/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ export default class extends REST {
* @override
*/
request (method = 'GET', options = {}) {
// 转 options.query.where 对象为字符串
if (options.query && options.query.where) {
options.query.where = restHelpers.whereToStr(options.query.where)
if (method === 'GET') {
if (!options.query) {
options.query = {}
}

// 转 options.query.where 对象为字符串
if (options.query.where) {
options.query.where = restHelpers.whereToStr(options.query.where)
}

options.query._ = new Date().getTime()
}

iView.Spin.show()
Expand Down

0 comments on commit fb1dd28

Please sign in to comment.