context-menu-drag.vue 7.3 KB
Newer Older
1
<template>
2
  <Drawer class-name="sider-drawer" placement="left" :closable="false" :mask="false" width="200" v-model="leftDrawerVisiable">
3 4
    <div class="context-menu-drag">
      <div class="menu-list">
5
        <div class="menu-header" @click="rightDrawerVisiable=!rightDrawerVisiable">
6 7 8 9
          <div class="menuicon">
            <Icon type="md-apps" />
          </div>
          <div class="content">
10
            <span>{{$t('components.contextMenuDrag.allApp')}}</span>
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">
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">
18
            <transition-group type="transition" :name="!drag ? 'flip-list' : null">
19
              <li @click="skipTo(item)" class="list-group-item" v-for="(item,index) in selectlist" :key="item.id">
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>
29 30 31 32
                  </el-col>
                  <el-col :span="6">
                    <div class="bar">
                      <div>
33
                        <Icon type="ios-close" @click.stop="removeAt(index)" />
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>
46
      <Drawer class-name="menu-drawer" width="60" :closable="true" :mask="false" placement="left" v-model="rightDrawerVisiable">
47
        <div class="menuItems">
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>
50
            <span v-if="isStar(item.id)" class="star" @click.stop="outStar(item)">
51 52
              <Icon type="ios-star" />
            </span>
53
            <span v-else class="star" @click.stop="onStar(item)">
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";
65 66
import EntityService from '@/service/entity-service';
import { Vue,Component,Provide,Watch,Prop,Model } from "vue-property-decorator";
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 {

76 77
  public panelShow: boolean = true;

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

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

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

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

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

118 119 120 121 122 123 124
  /**
   * 已选择的应用数据
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
  public selectlist: Array<any> = [];
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
  /**
   * 拖拽列表
   * 
   * @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();
157

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

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

  /**
196 197 198 199
   * 判断是否已选择该应用
   * 
   * @returns
   * @memberof ContextMenuDrag
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;
  }

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));
225 226 227
     }
   }

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

  /**
   * 从列表中删除
241 242 243
   * 
   * @returns
   * @memberof ContextMenuDrag
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);
      }
    });
  }
255 256 257 258 259 260
  /**
   * 删除已选择应用
   *
   * @returns
   * @memberof ContextMenuDrag
   */
261 262 263
  removeAt(index: any) {
    this.selectlist.splice(index, 1);
  }
264 265 266 267

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

  /**
   * 过滤已选择的应用
   * 
   * @returns
   * @memberof ContextMenuDrag
   */
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);
      }
    });
  }
287 288 289 290 291 292
  /**
   * vue 生命周期
   *
   * @returns
   * @memberof ContextMenuDrag
   */
293 294
  mounted() {
    let that: any = this;
295
    const get: Promise<any> = this.entityService.getAllApp(null,{});
296 297
    get
      .then((response: any) => {
298 299 300 301 302 303 304 305 306 307
        if (response) {
          that.list = response.data.model;
          that.listFilter();
        }
      });
  }
}
</script>

<style lang='less'>
308
@import './context-menu-drag.less';
309
</style>