研发图纸文件管理系统-前端项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
<template>
  <div >
    <div :class="['mask', openDrawer ? 'open' : 'close']" @click="close"></div>
    <div :class="['drawer', placement, openDrawer ? 'open' : 'close']">
      <div ref="drawer" class="content">
        <slot></slot>
      </div>
      <div v-if="showHandler" :class="['handler-container', placement, openDrawer ? 'open' : 'close']" ref="handler" @click="handle">
        <slot v-if="$slots.handler" name="handler"></slot>
        <div v-else class="handler">
          <a-icon :type="openDrawer ? 'close'  : 'bars'" />
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  name: 'Drawer',
  data () {
    return {
      drawerWidth: 0
    }
  },
  props: {
    openDrawer: {
      type: Boolean,
      required: false,
      default: false
    },
    placement: {
      type: String,
      required: false,
      default: 'left'
    },
    showHandler: {
      type: Boolean,
      required: false,
      default: true
    }
  },
  mounted () {
    this.drawerWidth = this.getDrawerWidth()
  },
  watch: {
    'drawerWidth': function () {
      if (this.placement === 'left') {
        //this.$refs.handler.style.left = val + 'px'
      } else {
        //this.$refs.handler.style.right = val + 'px'
      }
    }
  },
  methods: {
    open () {
      this.$emit('change', true)
    },
    close () {
      this.$emit('change', false)
    },
    handle () {
      this.$emit('change', !this.openDrawer)
    },
    getDrawerWidth () {
      return this.$refs.drawer.clientWidth
    }
  }
}
</script>
 
<style lang="less" scoped>
  .mask{
    position: fixed;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    transition: all 0.5s;
    z-index: 100;
    &.open{
      display: inline-block;
    }
    &.close{
      display: none;
    }
  }
  .drawer{
    position: fixed;
    height: 100%;
    transition: all 0.5s;
    z-index: 100;
    &.left{
      left: 0px;
      &.open{
        .content{
          box-shadow: 2px 0 8px rgba(0,0,0,.15);
        }
      }
      &.close{
        transform: translateX(-100%) translateX(40px);
      }
    }
    &.right{
      right: 0px;
      .content{
        float: right;
      }
      &.open{
        .content{
          box-shadow: -2px 0 8px rgba(0,0,0,.15);
        }
      }
      &.close{
        transform: translateX(100%) translateX(-40px);
      }
    }
    .sider{
      height: 100%;
    }
  }
  .content{
    display: inline-block;
    height: 100%;
  }
  .handler-container{
    display: inline-block;
    text-align: center;
    transition: all 0.5s;
    cursor: pointer;
    vertical-align: top;
    margin-top: 200px;
    z-index: 100;
    .handler {
      height: 40px;
      width: 40px;
      background-color: #fff;
      font-size: 26px;
      box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
      line-height: 40px;
    }
    &.left{
      .handler{
        border-radius: 0 5px 5px 0;
      }
    }
    &.right{
      .handler{
        border-radius: 5px 0 0 5px;
      }
    }
  }
</style>