context-menu-drag.vue 7.4 KB
Newer Older
tony001's avatar
tony001 committed
1
<template>
tony001's avatar
tony001 committed
2
  <Drawer class-name="sider-drawer" placement="left" :closable="false" :mask="false" width="200" v-model="leftDrawerVisiable">
tony001's avatar
tony001 committed
3 4
    <div class="context-menu-drag">
      <div class="menu-list">
tony001's avatar
tony001 committed
5
        <div class="menu-header" @click="rightDrawerVisiable=!rightDrawerVisiable">
tony001's avatar
tony001 committed
6 7 8 9
          <div class="menuicon">
            <Icon type="md-apps" />
          </div>
          <div class="content">
10
            <span>{{$t('components.contextMenuDrag.allApp')}}</span>
tony001's avatar
tony001 committed
11 12 13 14 15 16
          </div>
          <div class="forward">
            <Icon type="ios-arrow-forward" />
          </div>
        </div>
        <div style="padding:8px 0px;" class="col-6">
tony001's avatar
tony001 committed
17
          <draggable class="list-group" tag="ul" v-model="selectlist" v-bind="dragOptionsVal" @start="drag=true" @end="drag=false" :animation="250" handle=".handle" ghost-class="ghost">
tony001's avatar
tony001 committed
18
            <transition-group type="transition" :name="!drag ? 'flip-list' : null">
tony001's avatar
tony001 committed
19
              <li @click="skipTo(item)" class="list-group-item" v-for="(item,index) in selectlist" :key="item.id">
tony001's avatar
tony001 committed
20 21 22 23 24 25 26 27
                <el-row>
                  <el-col class="menuicon" :span="4">
                    <span>
                      <Icon v-if="item.icon" :type="item.icon" />
                      <Icon v-else type="md-menu" />
                    </span>
                  </el-col>
                  <el-col :span="14">
28
                    <span>{{ item.fullName ? item.fullName:item.label }}</span>
tony001's avatar
tony001 committed
29 30 31 32
                  </el-col>
                  <el-col :span="6">
                    <div class="bar">
                      <div>
tony001's avatar
tony001 committed
33
                        <Icon type="ios-close" @click.stop="removeAt(index)" />
tony001's avatar
tony001 committed
34 35 36 37 38 39 40 41 42 43 44 45
                      </div>
                      <div>
                        <Icon type="ios-move handle" />
                      </div>
                    </div>
                  </el-col>
                </el-row>
              </li>
            </transition-group>
          </draggable>
        </div>
      </div>
tony001's avatar
tony001 committed
46
      <Drawer class-name="menu-drawer" width="60" :closable="true" :mask="false" placement="left" v-model="rightDrawerVisiable">
tony001's avatar
tony001 committed
47
        <div class="menuItems">
tony001's avatar
tony001 committed
48
          <div @click="skipTo(item)" class="item" v-for="(item) in list" :key="item.id">
49
            <span class="title">{{ item.fullName ? item.fullName:item.label }}</span>
tony001's avatar
tony001 committed
50
            <span v-if="isStar(item.id)" class="star" @click.stop="outStar(item)">
tony001's avatar
tony001 committed
51 52
              <Icon type="ios-star" />
            </span>
tony001's avatar
tony001 committed
53
            <span v-else class="star" @click.stop="onStar(item)">
tony001's avatar
tony001 committed
54 55 56 57 58 59 60 61 62 63 64
              <Icon type="ios-star-outline" />
            </span>
          </div>
        </div>
      </Drawer>
    </div>
  </Drawer>
</template>

<script lang="ts">
import draggable from "vuedraggable";
tony001's avatar
tony001 committed
65 66
import EntityService from '@/service/entity-service';
import { Vue,Component,Provide,Watch,Prop,Model } from "vue-property-decorator";
tony001's avatar
tony001 committed
67 68 69 70 71 72 73 74 75

// tslint:disable-next-line:max-classes-per-file
@Component({
  components: {
    draggable
  }
})
export default class ContextMenuDrag extends Vue {

tony001's avatar
tony001 committed
76 77
  public panelShow: boolean = true;

tony001's avatar
tony001 committed
78 79 80 81 82 83 84
  /**
   * 抽屉菜单状态
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  @Prop() public contextMenuDragVisiable?: boolean;
tony001's avatar
tony001 committed
85

tony001's avatar
tony001 committed
86 87 88 89 90 91 92
  /**
   * 拖拽列表配置对象
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  @Model("change") public dragOptions: any;
tony001's avatar
tony001 committed
93

tony001's avatar
tony001 committed
94 95 96 97 98 99 100
  /**
   * 右侧飘窗状态
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  public rightDrawerVisiable: boolean = false;
tony001's avatar
tony001 committed
101

tony001's avatar
tony001 committed
102 103 104 105 106 107 108
  /**
   * 左侧飘窗状态
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  public leftDrawerVisiable: boolean = false;
tony001's avatar
tony001 committed
109

tony001's avatar
tony001 committed
110 111 112 113 114 115 116
  /**
   * 全部应用数据
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  public list: Array<any> = [];
tony001's avatar
tony001 committed
117

tony001's avatar
tony001 committed
118 119 120 121 122 123 124
  /**
   * 已选择的应用数据
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  public selectlist: Array<any> = [];
tony001's avatar
tony001 committed
125

tony001's avatar
tony001 committed
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
  /**
   * 拖拽列表
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  public drag: boolean = false;

  /**
   * 拖拽列表配置项
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  get dragOptionsVal() {
    return {
      animation: 200,
      group: "description",
      disabled: false,
      ghostClass: "ghost"
    };
  }
  
  /**
   * 实体服务对象
   *
   * @protected
   * @type {EntityService}
   * @memberof ContextMenuDrag
   */
  protected entityService: EntityService = new EntityService();
tony001's avatar
tony001 committed
157

tony001's avatar
tony001 committed
158 159 160 161 162 163
  /**
   * 监听抽屉菜单状态
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
tony001's avatar
tony001 committed
164 165 166
  @Watch("contextMenuDragVisiable")
  public onVisiableChange(newVal: any, oldVal: any) {
    if (newVal) {
tony001's avatar
tony001 committed
167
      this.leftDrawerVisiable = newVal;
tony001's avatar
tony001 committed
168 169 170 171
    } else {
      let that: any = this;
      let params: any = {};
      params.model = this.selectlist;
tony001's avatar
tony001 committed
172 173
      const put: Promise<any> = this.entityService.updateChooseApp(null,params);
      this.rightDrawerVisiable = false;
tony001's avatar
tony001 committed
174
      setTimeout(() => {
tony001's avatar
tony001 committed
175
        that.leftDrawerVisiable = false;
tony001's avatar
tony001 committed
176 177 178 179
      }, 300);
    }
  }

tony001's avatar
tony001 committed
180 181 182 183 184 185
  /**
   * 鼠标移入服务时显示右侧飘窗
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
tony001's avatar
tony001 committed
186 187 188 189
  public showMenuDrawer() {
    let that: any = this;
    if(this.contextMenuDragVisiable){
      setTimeout(() => {
tony001's avatar
tony001 committed
190
        that.rightDrawerVisiable = true;
tony001's avatar
tony001 committed
191 192 193 194 195
      }, 300);
    }
  }

  /**
tony001's avatar
tony001 committed
196 197 198 199
   * 判断是否已选择该应用
   * 
   * @returns
   * @memberof ContextMenuDrag
tony001's avatar
tony001 committed
200 201 202 203 204 205 206 207 208 209 210
   */
  public isStar(id: any) {
    let istar: boolean = false;
    this.selectlist.forEach((item: any) => {
      if (Object.is(item.id, id)) {
        istar = true;
      }
    });
    return istar;
  }

tony001's avatar
tony001 committed
211 212 213 214 215 216 217 218 219 220 221 222 223
  /**
   * 跳转到应用
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
   public skipTo(item: any){
     if(item.addr){
      let params: any = {};
      params.model = this.selectlist;
      const put: Promise<any> = this.entityService.updateChooseApp(null,params);
      window.location.href = item.addr;
     }else{
224
       this.$message.info((this.$t('components.contextMenuDrag.noFind') as string));
tony001's avatar
tony001 committed
225 226 227
     }
   }

tony001's avatar
tony001 committed
228 229
  /**
   * 加入列表
tony001's avatar
tony001 committed
230 231 232
   * 
   * @returns
   * @memberof ContextMenuDrag
tony001's avatar
tony001 committed
233 234 235 236 237 238 239 240
   */
  public onStar(item: any) {
    item.visabled = 1;
    this.selectlist.push(item);
  }

  /**
   * 从列表中删除
tony001's avatar
tony001 committed
241 242 243
   * 
   * @returns
   * @memberof ContextMenuDrag
tony001's avatar
tony001 committed
244 245 246 247 248 249 250 251 252 253 254
   */
  public outStar(item: any) {
    item.visabled = 0;
    let index: number = 0;
    let that: any = this;
    this.selectlist.forEach((select: any, index: number) => {
      if (Object.is(item.id, select.id)) {
        that.selectlist.splice(index,1);
      }
    });
  }
tony001's avatar
tony001 committed
255 256 257 258 259 260
  /**
   * 删除已选择应用
   *
   * @returns
   * @memberof ContextMenuDrag
   */
tony001's avatar
tony001 committed
261 262 263
  removeAt(index: any) {
    this.selectlist.splice(index, 1);
  }
tony001's avatar
tony001 committed
264 265 266 267

  /**
   * 拖拽列表排序
   */
tony001's avatar
tony001 committed
268 269 270
  sort() {
    this.selectlist = this.selectlist.sort((a, b) => a.order - b.order);
  }
tony001's avatar
tony001 committed
271 272 273 274 275 276 277

  /**
   * 过滤已选择的应用
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
tony001's avatar
tony001 committed
278 279 280 281 282 283 284 285 286
  listFilter() {
    let that: any = this;
    that.selectlist = [];
    this.list.forEach((item: any) => {
      if (item.visabled === 1) {
        that.selectlist.push(item);
      }
    });
  }
tony001's avatar
tony001 committed
287 288 289 290 291 292
  /**
   * vue 生命周期
   *
   * @returns
   * @memberof ContextMenuDrag
   */
tony001's avatar
tony001 committed
293 294
  mounted() {
    let that: any = this;
tony001's avatar
tony001 committed
295
    const get: Promise<any> = this.entityService.getAllApp(null,{});
296
    get.then((response: any) => {
tony001's avatar
tony001 committed
297 298 299 300
        if (response) {
          that.list = response.data.model;
          that.listFilter();
        }
301 302
      }).catch((error:any) =>{
        console.warn("加载数据错误")
tony001's avatar
tony001 committed
303 304 305 306 307 308
      });
  }
}
</script>

<style lang='less'>
tony001's avatar
tony001 committed
309
@import './context-menu-drag.less';
tony001's avatar
tony001 committed
310
</style>