Skip to content

Commit

Permalink
Merge branch 'master' of github.com:szuprefix/vue-django
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Feb 19, 2020
2 parents 2babcfb + ac2d6e5 commit 8288f99
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 21 deletions.
37 changes: 29 additions & 8 deletions src/components/layout/BatchActions.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<span>
<el-select v-model="scope" v-if="scopes.select.count>0 && scopes.exclude.count>0" style="width:8rem">
<el-option :value="k" :label="v.label" v-for="v, k in scopes" :key="k"></el-option>
</el-select>
<el-button plain :icon="a.icon" v-for="a in items" @click="onCommand(a)" :title="a.notice"
:disabled="count===0" :type="a.type"
:disabled="scopes.select.count===0" :type="a.type"
:key="a.name">{{a.label}}
</el-button>
</span>
Expand All @@ -11,23 +14,24 @@
props: {
items: Array,
context: Object,
count: {type: Number, default: 0}
},
data () {
return {}
return {
scope: 'select'
}
},
components: {},
methods: {
onCommand(action){
let rc = this.count
if (rc == 0) {
let scope = this.scopes[this.scope]
if (scope.count === 0) {
this.$message('请先勾选至少一条记录')
return
}
if (action && action.do) {
let confirm = action.confirm === false ? () => Promise.resolve() : () => this.$confirm(action.notice, `确定要对勾选中的${rc}条记录执行"${action.label}"操作吗?`, {type: 'warning'})
let confirm = action.confirm === false ? () => Promise.resolve() : () => this.$confirm(action.notice, `确定要对${scope.label}记录执行"${action.label}"操作吗?`, {type: 'warning'})
confirm().then(() => {
action.do({action, ...this.context}).then(({data}) => {
action.do({action, ...this.context, scope: this.scope}).then(({data}) => {
let countInfo = data.rows >= 0 ? `${data.rows}条记录` : ''
this.$message({message: `操作成功${countInfo}.`, type: 'success'})
this.$emit("done", data)
Expand All @@ -38,6 +42,23 @@
this.$emit("command", name)
}
},
computed: {}
computed: {
scopes () {
let sc = this.context.selection.length
let ac = this.context.count
return {
select: {count: sc, label: `选中${sc}`},
all: {count: ac, label: `全部${ac}`},
exclude: {count: ac - sc, label: `其余${ac - sc}`}
}
},
},
watch: {
context(v) {
if (v.selection.length === 0) {
this.scope = 'select'
}
}
}
}
</script>
9 changes: 7 additions & 2 deletions src/components/media/VideoInput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<q-video :width="field.width" :height="field.height" :appID="$store.state.qcloud.vod.appId" :fileID="value.fileId">
<q-video :width="field.width" :height="field.height" :appID="$store.state.qcloud.vod.appId" :fileID="fileId">
</q-video>
</template>
<script>
Expand All @@ -17,6 +17,11 @@
},
components: {QVideo},
methods: {},
computed: {}
computed: {
fileId () {
let ct = this.value
return ct.FileId || ct.fileId
}
}
}
</script>
9 changes: 7 additions & 2 deletions src/components/media/VideoWidget.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<q-video :width="field.width" :height="field.height" :appID="$store.state.qcloud.vod.appId"
:fileID="value[field.name].fileId" ref="video">
:fileID="fileId" ref="video">
</q-video>
</template>
<script>
Expand All @@ -18,7 +18,12 @@
},
components: {QVideo},
methods: {},
computed: {},
computed: {
fileId () {
let ct = this.value[this.field.name]
return ct.FileId || ct.fileId
}
},
watch: {
value(v) {
this.$refs.video.createPlayer()
Expand Down
16 changes: 12 additions & 4 deletions src/components/model/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
</el-select>
<model-select :field="f" v-model="value[f.name]" @input="onSearch"
:showCreate="false" :appModel="f.model"
v-if="f.model" :pageSize="100"></model-select>
v-else-if="f.model" :pageSize="100"></model-select>
</template>

<template v-for="f in filterFields" v-if="! (f.name in exclude)">
<array-input v-if="f.type === 'string' && f.lookups && f.lookups.includes('in')"
v-model="value[`${f.name}__in`]" :placeholder="`批量查询${f.label}`" style="width: 10rem;"
:autosize="{minRows:1,maxRows:4}" @change="onSearch"></array-input>
</template>
</div>
</template>
<script>
import ModelSelect from './Select.vue'
import ArrayInput from '../widgets/ArrayInput.vue'
import array_normalize from '../../utils/array_normalize'
export default{
props: {
model: Object,
Expand All @@ -39,7 +47,7 @@
baseQueries: {}
}
},
components: {ModelSelect},
components: {ModelSelect, ArrayInput},
created () {
},
methods: {
Expand All @@ -50,8 +58,8 @@
let search = this.model.options.actions.SEARCH
this.searchFields = search.search_fields
let filterItems = this.items || search.filter_fields
this.filterFields = filterItems.map((a) => {
return Object.assign({multiple: false}, this.model.fieldConfigs[a])
this.filterFields = array_normalize(filterItems, this.model.fieldConfigs, (a) => {
return {multiple: false, ...a}
})
this.filters = Object.assign({}, this.getFilters())
},
Expand Down
11 changes: 7 additions & 4 deletions src/components/model/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<search v-model="search" :model="model" :items="searchItems" :exclude="_baseQueries" ref="search"
v-if="showSearch"
@change="onSearch"></search>
<batch-actions :items="batchActionItems" :count="selection.length" @done="refresh" :context="{selection}"
<batch-actions :items="batchActionItems" @done="refresh" :context="{selection,count}"
v-if="batchActionItems.length>0"></batch-actions>
<el-drawer :visible.sync="editing" direction="rtl"
:title="`${parentMultipleRelationField?'添加':'创建'}${model.config.verbose_name}`" size="66%">
Expand All @@ -18,7 +18,7 @@
</el-drawer>

<remote-table :items="tableItems" :url="model.getListUrl()" ref="table" v-if="optionLoaded"
v-bind="rtAttrs" v-on="$listeners" @selection-change="onSelectionChange">
@loaded="onLoaded" v-bind="rtAttrs" v-on="$listeners" @selection-change="onSelectionChange">

<template slot="left" v-if="$slots.left">
<slot name="left"></slot>
Expand Down Expand Up @@ -78,6 +78,7 @@
batchActionItems: [],
selection: [],
parentQueries: {},
count: 0,
avairableActions: {
'create': {
icon: 'plus',
Expand Down Expand Up @@ -146,6 +147,7 @@
this.$refs.table.refresh()
},
onLoaded (v) {
this.count = v.count
this.$emit('loaded', v)
},
onSearch () {
Expand Down Expand Up @@ -219,9 +221,10 @@
})
},
defaultBatchActionDo (action) {
return ({selection}) => {
return ({selection, scope}) => {
let ids = selection.map((a) => a.id)
return this.$http.post(`${this.model.getListUrl()}${action.api || action.name}/`, {id__in: ids, ...action.context})
let qd = {...this._baseQueries, ...this.search}
return this.$http.post(`${this.model.getListUrl()}${action.api || action.name}/?${Qs.stringify(qd, {arrayFormat: 'comma'})}`, {batch_action_ids: ids, ...action.context, scope})
}
},
addToParent ({selection}) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/table/RemoteTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
this.data = data.results
this.count = data.count
this.loading = false
this.$emit("loaded", this.data)
this.$emit("loaded", data)
}).catch(this.onServerResponseError)
},
onSearch(){
Expand Down
38 changes: 38 additions & 0 deletions src/components/widgets/ArrayInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<el-input v-model="value_" v-bind="[$attrs,$props]" clearable type="textarea" @change="onChange"></el-input>
</template>
<script>
import {uniq} from 'lodash'
export default{
model: {
event: 'change'
},
props: {
value: Array,
field: Object,
},
data () {
return {
value_: ''
}
},
created(){
this.setValue()
},
components: {},
methods: {
setValue(){
this.value_ = this.value && this.value.join('\n') || ''
},
onChange(v){
let l = this.value_.split(/[,\n;]/g).map(a => a.trim()).filter(a => a !== '')
this.$emit('change', uniq(l))
}
},
watch: {
value(v){
this.setValue()
}
}
}
</script>

0 comments on commit 8288f99

Please sign in to comment.