123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <template>
- <div class="query-area"
- @dragover.prevent=""
- @dragenter.prevent="handleDragOver($event)"
- @drop="handleDrop($event)"
- @dragleave="handleDragleave($event)"
- >
- <template v-for="(it, index) in tagList">
- <div :class="(this.index == index?'query-area-item query-area-item-active':'query-area-item')"
- draggable="true"
- @dragstart="childDragstart($event, index)"
- @dragenter.prevent="childDragEnter($event, index)"
- @dragleave="childDragleave($event, index)">
- <div class="query-area-item-title" @click="handleDisplay(index)">{{it.displayName?it.displayName : it.fieldName}}</div>
- <div v-if="(queryType=='measure')" class="query-area-item-select">
- <a-select v-model:value="tagList[index].operation" :options="aggregates"></a-select>
- </div>
- <div class="query-area-item-close" @click="childDelete(index)"><CloseOutlined style="color: white;"/></div>
- </div>
- </template>
- </div>
- <a-modal v-model:visible="modelName.open" title="修改显示名称" @ok="handleDisplayOk">
- <div style="line-height: 30px;">属性名称:{{modelName.fieldName}}</div>
- <div>
- <a-input v-model:value="modelName.displayName"
- :placeholder="(modelName.fieldName+'...')" />
- </div>
- </a-modal>
- </template>
- <script lang="ts">
- import {defineComponent, computed} from "vue";
- //import {message} from "ant-design-vue";
- export default defineComponent ({
- props:{
- queryType : String,
- keyName : String,
- subjectId : String
- },
- emits: ['change'],
- name : 'DragBase',
- data() {
- return{
- tagList : [] as any,
- counter : 0,
- index : -1,
- aggregates : [],
- modelName : {
- open : false,
- fieldName: '',
- displayName : '',
- index : -1
- }
- }
- },
- setup(props, context){
- console.log("base setup" , props);
- const dataChange = (list, obj) => {
- context.emit('change', list, obj)
- }
- const subjectId = computed(() => {
- return props.subjectId? props.subjectId : null
- });
- return{
- queryType: props.queryType ? props.queryType : 'dimen',
- keyName : props.keyName == null || props.keyName == undefined ? 'tempFeildId' : props.keyName,
- dataChange,
- subjectId
- }
- },
- mounted(){
- console.log("mounted" , "");
- },
- methods:{
- getObject:function (data){
- return {
- tempFeildId: data.tempFeildId,
- tempId: data.tempId ? data.tempId : null,
- fieldId: data.fieldId ? data.fieldId : null,
- fieldCode: data.fieldCode ? data.fieldCode : null,
- dataType : data.dataType ? data.dataType : 'int',
- fieldAlias: data.fieldAlias,
- fieldName: data.fieldName,
- isDrag: 1,
- displayName: data.displayName ? data.displayName : null,
- operation: data.operation ? data.operation : 'sum',
- subId : data.subId? data.subId : null,
- subjectName : data.subjectName? data.subjectName : null
- };
- },
- handleDragOver : function (ev) {
- ev.preventDefault();
- this.counter++;
- const data = window["dragData"];
- console.log("keyName", this.keyName, data[this.keyName])
- const tag = this.findTag(data[this.keyName]);
- if(tag != null) return;
- this.index = this.tagList.length;
- const obj = this.getObject(data);
- //检查主题是否合法
- console.log("handleDragOver", data, obj, this.tagList);
- if(obj.subId==null || obj.subjectName==null) return; //主题不合法
- if(this.subjectId && this.subjectId != obj.subId) {
- //message.error("无法放置,同一模板只能放置统一主题的维度、度量!");
- return;//有主题,但是和当前模板中的主题不同
- }
- this.tagList.push(obj);
- },
- handleDrop : function (ev) {
- ev.preventDefault();
- const data = window["dragData"];
- const tag = this.findTag(data[this.keyName]);
- console.log("handleDrop", data, tag);
- if(tag==null) return;
- this.tagList[tag.index]['isDrag'] = 0;
- this.index = -1;
- this.counter = 0;
- this.dataChange(this.getTagList(), this.tagList[tag.index]);
- },
- handleDragleave : function(ev) {
- console.log(ev);
- this.counter--;
- const data = window["dragData"];
- const tag = this.findTag(data[this.keyName]);
- console.log("handleDragleave", data, tag, this.counter);
- if(tag==null) return;
- if(this.counter==0) {
- this.tagList.splice(tag.index,1);
- this.index = -1;
- this.dataChange(this.getTagList(), null);
- }
- },
- childDragEnter : function (ev, index) {
- ev.preventDefault();
- this.counter++;
- //重新排序
- if(index == this.index || this.index==-1) return;
- const data = window["dragData"];
- //检查主题是否合法
- if(data.subId==null || data.subjectName==null) return; //主题不合法
- if(this.subjectId && this.subjectId != data.subId) return;//有主题,但是和当前模板中的主题不同
- this.tagList.splice(this.index,1)
- this.index = index;
- this.tagList.splice(index, 0, this.getObject(data));
- console.log("childDragEnter","位置切换");
- this.dataChange(this.getTagList(), this.getObject(data));
- },
- childDragleave : function (ev) {
- ev.preventDefault();
- this.counter--;
- },
- childDragstart : function (ev, index) {
- console.log(ev);
- window["dragData"] = JSON.parse(JSON.stringify(this.tagList[index]));
- this.index = -1;
- setTimeout(()=>{
- this.tagList.splice(index,1);
- console.log("childDragstart", window["dragData"], index, this.tagList);
- this.dataChange(this.getTagList(), null);
- },20);
- },
- childDelete : function (index){
- this.index = -1;
- this.tagList.splice(index,1);
- this.dataChange(this.getTagList(), null);
- },
- findTag : function (key) {
- for (let i = 0; i < this.tagList.length; i++) {
- if (this.tagList[i][this.keyName] == key) {
- console.log("findTag",this.tagList, key, this.tagList[i][this.keyName]);
- return {obj: this.tagList[i], index: i}
- }
- }
- console.log("findTag",this.tagList, key, "null");
- return null;
- },
- handleDisplay(index){
- this.modelName.index = index;
- this.modelName.open = true;
- this.modelName.fieldName = this.tagList[index]["fieldName"];
- this.modelName.displayName = this.tagList[index]["displayName"]?
- this.tagList[index]["displayName"]:this.tagList[index]["fieldName"];
- },
- handleDisplayOk(){
- if(this.modelName.displayName!=null && this.modelName.displayName!=undefined && this.modelName.displayName.length>0) {
- this.modelName.open = false;
- this.tagList[this.modelName.index]["displayName"] = this.modelName.displayName;
- this.modelName.index = -1;
- }
- },
- getTagList(){
- this.tagList.forEach((row, index)=>{
- row.disOrder = index;
- });
- return this.tagList;
- },
- setTagList(list){
- this.tagList = list;
- }
- }
- })
- </script>
- <style lang="less" scoped>
- @import 'drag-base.less';
- </style>
|