Procházet zdrojové kódy

gambleMember sorting

Unknown %!s(int64=7) %!d(string=před) roky
rodič
revize
b0ae598bb3

+ 4 - 1
src/api/gambleMember.js

@@ -6,7 +6,10 @@ export function fetchList(query) {
6 6
     method: 'get',
7 7
     params: {
8 8
       limit: query.limit,
9
-      offset: (query.page - 1) * query.limit
9
+      offset: (query.page - 1) * query.limit,
10
+      name: query.name,
11
+      chipsSort: query.chipsSort,
12
+      updatedSort: query.updatedSorts
10 13
     }
11 14
   })
12 15
 }

+ 49 - 0
src/directive/clipboard/clipboard.js

@@ -0,0 +1,49 @@
1
+// Inspired by https://github.com/Inndy/vue-clipboard2
2
+const Clipboard = require('clipboard')
3
+if (!Clipboard) {
4
+  throw new Error('you shold npm install `clipboard` --save at first ')
5
+}
6
+
7
+export default {
8
+  bind(el, binding) {
9
+    if (binding.arg === 'success') {
10
+      el._v_clipboard_success = binding.value
11
+    } else if (binding.arg === 'error') {
12
+      el._v_clipboard_error = binding.value
13
+    } else {
14
+      const clipboard = new Clipboard(el, {
15
+        text() { return binding.value },
16
+        action() { return binding.arg === 'cut' ? 'cut' : 'copy' }
17
+      })
18
+      clipboard.on('success', e => {
19
+        const callback = el._v_clipboard_success
20
+        callback && callback(e) // eslint-disable-line
21
+      })
22
+      clipboard.on('error', e => {
23
+        const callback = el._v_clipboard_error
24
+        callback && callback(e) // eslint-disable-line
25
+      })
26
+      el._v_clipboard = clipboard
27
+    }
28
+  },
29
+  update(el, binding) {
30
+    if (binding.arg === 'success') {
31
+      el._v_clipboard_success = binding.value
32
+    } else if (binding.arg === 'error') {
33
+      el._v_clipboard_error = binding.value
34
+    } else {
35
+      el._v_clipboard.text = function() { return binding.value }
36
+      el._v_clipboard.action = function() { return binding.arg === 'cut' ? 'cut' : 'copy' }
37
+    }
38
+  },
39
+  unbind(el, binding) {
40
+    if (binding.arg === 'success') {
41
+      delete el._v_clipboard_success
42
+    } else if (binding.arg === 'error') {
43
+      delete el._v_clipboard_error
44
+    } else {
45
+      el._v_clipboard.destroy()
46
+      delete el._v_clipboard
47
+    }
48
+  }
49
+}

+ 13 - 0
src/directive/clipboard/index.js

@@ -0,0 +1,13 @@
1
+import Clipboard from './clipboard'
2
+
3
+const install = function(Vue) {
4
+  Vue.directive('Clipboard', Clipboard)
5
+}
6
+
7
+if (window.Vue) {
8
+  window.clipboard = Clipboard
9
+  Vue.use(install); // eslint-disable-line
10
+}
11
+
12
+Clipboard.install = install
13
+export default Clipboard

+ 91 - 0
src/directive/sticky.js

@@ -0,0 +1,91 @@
1
+const vueSticky = {}
2
+let listenAction
3
+vueSticky.install = Vue => {
4
+  Vue.directive('sticky', {
5
+    inserted(el, binding) {
6
+      const params = binding.value || {}
7
+      const stickyTop = params.stickyTop || 0
8
+      const zIndex = params.zIndex || 1000
9
+      const elStyle = el.style
10
+
11
+      elStyle.position = '-webkit-sticky'
12
+      elStyle.position = 'sticky'
13
+      // if the browser support css sticky(Currently Safari, Firefox and Chrome Canary)
14
+      // if (~elStyle.position.indexOf('sticky')) {
15
+      //     elStyle.top = `${stickyTop}px`;
16
+      //     elStyle.zIndex = zIndex;
17
+      //     return
18
+      // }
19
+      const elHeight = el.getBoundingClientRect().height
20
+      const elWidth = el.getBoundingClientRect().width
21
+      elStyle.cssText = `top: ${stickyTop}px; z-index: ${zIndex}`
22
+
23
+      const parentElm = el.parentNode || document.documentElement
24
+      const placeholder = document.createElement('div')
25
+      placeholder.style.display = 'none'
26
+      placeholder.style.width = `${elWidth}px`
27
+      placeholder.style.height = `${elHeight}px`
28
+      parentElm.insertBefore(placeholder, el)
29
+
30
+      let active = false
31
+
32
+      const getScroll = (target, top) => {
33
+        const prop = top ? 'pageYOffset' : 'pageXOffset'
34
+        const method = top ? 'scrollTop' : 'scrollLeft'
35
+        let ret = target[prop]
36
+        if (typeof ret !== 'number') {
37
+          ret = window.document.documentElement[method]
38
+        }
39
+        return ret
40
+      }
41
+
42
+      const sticky = () => {
43
+        if (active) {
44
+          return
45
+        }
46
+        if (!elStyle.height) {
47
+          elStyle.height = `${el.offsetHeight}px`
48
+        }
49
+
50
+        elStyle.position = 'fixed'
51
+        elStyle.width = `${elWidth}px`
52
+        placeholder.style.display = 'inline-block'
53
+        active = true
54
+      }
55
+
56
+      const reset = () => {
57
+        if (!active) {
58
+          return
59
+        }
60
+
61
+        elStyle.position = ''
62
+        placeholder.style.display = 'none'
63
+        active = false
64
+      }
65
+
66
+      const check = () => {
67
+        const scrollTop = getScroll(window, true)
68
+        const offsetTop = el.getBoundingClientRect().top
69
+        if (offsetTop < stickyTop) {
70
+          sticky()
71
+        } else {
72
+          if (scrollTop < elHeight + stickyTop) {
73
+            reset()
74
+          }
75
+        }
76
+      }
77
+      listenAction = () => {
78
+        check()
79
+      }
80
+
81
+      window.addEventListener('scroll', listenAction)
82
+    },
83
+
84
+    unbind() {
85
+      window.removeEventListener('scroll', listenAction)
86
+    }
87
+  })
88
+}
89
+
90
+export default vueSticky
91
+

+ 13 - 0
src/directive/waves/index.js

@@ -0,0 +1,13 @@
1
+import waves from './waves'
2
+
3
+const install = function(Vue) {
4
+  Vue.directive('waves', waves)
5
+}
6
+
7
+if (window.Vue) {
8
+  window.waves = waves
9
+  Vue.use(install); // eslint-disable-line
10
+}
11
+
12
+waves.install = install
13
+export default waves

+ 26 - 0
src/directive/waves/waves.css

@@ -0,0 +1,26 @@
1
+.waves-ripple {
2
+    position: absolute;
3
+    border-radius: 100%;
4
+    background-color: rgba(0, 0, 0, 0.15);
5
+    background-clip: padding-box;
6
+    pointer-events: none;
7
+    -webkit-user-select: none;
8
+    -moz-user-select: none;
9
+    -ms-user-select: none;
10
+    user-select: none;
11
+    -webkit-transform: scale(0);
12
+    -ms-transform: scale(0);
13
+    transform: scale(0);
14
+    opacity: 1;
15
+}
16
+
17
+.waves-ripple.z-active {
18
+    opacity: 0;
19
+    -webkit-transform: scale(2);
20
+    -ms-transform: scale(2);
21
+    transform: scale(2);
22
+    -webkit-transition: opacity 1.2s ease-out, -webkit-transform 0.6s ease-out;
23
+    transition: opacity 1.2s ease-out, -webkit-transform 0.6s ease-out;
24
+    transition: opacity 1.2s ease-out, transform 0.6s ease-out;
25
+    transition: opacity 1.2s ease-out, transform 0.6s ease-out, -webkit-transform 0.6s ease-out;
26
+}

+ 42 - 0
src/directive/waves/waves.js

@@ -0,0 +1,42 @@
1
+import './waves.css'
2
+
3
+export default{
4
+  bind(el, binding) {
5
+    el.addEventListener('click', e => {
6
+      const customOpts = Object.assign({}, binding.value)
7
+      const opts = Object.assign({
8
+        ele: el, // 波纹作用元素
9
+        type: 'hit', // hit点击位置扩散center中心点扩展
10
+        color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色
11
+      }, customOpts)
12
+      const target = opts.ele
13
+      if (target) {
14
+        target.style.position = 'relative'
15
+        target.style.overflow = 'hidden'
16
+        const rect = target.getBoundingClientRect()
17
+        let ripple = target.querySelector('.waves-ripple')
18
+        if (!ripple) {
19
+          ripple = document.createElement('span')
20
+          ripple.className = 'waves-ripple'
21
+          ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px'
22
+          target.appendChild(ripple)
23
+        } else {
24
+          ripple.className = 'waves-ripple'
25
+        }
26
+        switch (opts.type) {
27
+          case 'center':
28
+            ripple.style.top = (rect.height / 2 - ripple.offsetHeight / 2) + 'px'
29
+            ripple.style.left = (rect.width / 2 - ripple.offsetWidth / 2) + 'px'
30
+            break
31
+          default:
32
+            ripple.style.top = (e.pageY - rect.top - ripple.offsetHeight / 2 - document.body.scrollTop) + 'px'
33
+            ripple.style.left = (e.pageX - rect.left - ripple.offsetWidth / 2 - document.body.scrollLeft) + 'px'
34
+        }
35
+        ripple.style.backgroundColor = opts.color
36
+        ripple.className = 'waves-ripple z-active'
37
+        return false
38
+      }
39
+    }, false)
40
+  }
41
+}
42
+

+ 29 - 6
src/views/gambleMember/index.vue

@@ -1,9 +1,21 @@
1 1
 <template>
2 2
 <div class="app-container calendar-list-container">
3 3
     <div class="app-container">
4
+      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="名稱" v-model="listQuery.name">
5
+      </el-input>
6
+      <el-select clearable @change='handleFilter' style="width: 90px" class="filter-item" v-model="listQuery.chipsSort" placeholder="點數">
7
+        <el-option v-for="item in chipsSortOptions" :key="item.label" :label="item.label" :value="item.key">
8
+        </el-option>
9
+      </el-select>
10
+      <el-select clearable @change='handleFilter' style="width: 120px" class="filter-item" v-model="listQuery.updatedSort" placeholder="更新時間">
11
+        <el-option v-for="item in updatedSortOptions" :key="item.label" :label="item.label" :value="item.key">
12
+        </el-option>
13
+      </el-select>
14
+      <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜尋</el-button>
4 15
         <el-button class="filter-item" @click="handleCreate" type="primary" icon="el-icon-edit">創建</el-button>
5 16
     </div>
6
-    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
17
+    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row
18
+      style="width: 100%">
7 19
       <el-table-column align="center" label='ID' >
8 20
         <template slot-scope="scope">
9 21
           {{scope.row.id}}
@@ -61,8 +73,13 @@
61 73
 
62 74
 <script>
63 75
 import { fetchList, updateChips, createGambleMember } from '@/api/gambleMember'
76
+import waves from '@/directive/waves' // 水波纹指令
64 77
 
65 78
 export default {
79
+  name: 'gambleMemberTable',
80
+  directives: {
81
+    waves
82
+  },
66 83
   data() {
67 84
     return {
68 85
       list: null,
@@ -81,7 +98,7 @@ export default {
81 98
         importance: 1,
82 99
         name: '',
83 100
         chips: '',
84
-        depositChips: '',
101
+        depositChips: ''
85 102
       },
86 103
       dialogFormVisible: false,
87 104
       dialogStatus: '',
@@ -89,10 +106,12 @@ export default {
89 106
         deposit: '儲值',
90 107
         create: '新增'
91 108
       },
109
+      chipsSortOptions: [{ label: '多到少', key: 'DESC' }, { label: '少到多', key: 'ASC' }],
110
+      updatedSortOptions: [{ label: '新到舊', key: 'DESC' }, { label: '舊到新', key: 'ASC' }],
92 111
       rules: {
93 112
         depositChips: [{ pattern: /^\+?[1-9][0-9]*$/, required: true, message: '請輸入整數', trigger: 'change' }],
94 113
         chips: [{ pattern: /^\+?[1-9][0-9]*$/, required: true, message: '請輸入整數', trigger: 'change' }],
95
-        name: [{ type: 'string', required: true, message: '必填', trigger: 'change' }]        
114
+        name: [{ type: 'string', required: true, message: '必填', trigger: 'change' }]
96 115
       }
97 116
     }
98 117
   },
@@ -146,7 +165,7 @@ export default {
146 165
         id: undefined,
147 166
         name: '',
148 167
         chips: '',
149
-        depositChips: '',
168
+        depositChips: ''
150 169
       }
151 170
     },
152 171
     handleCreate() {
@@ -169,11 +188,15 @@ export default {
169 188
               type: 'success',
170 189
               duration: 2000
171 190
             })
172
-            // this.getList() 
173
-          }) 
191
+            // this.getList()
192
+          })
174 193
         }
175 194
       })
176 195
     },
196
+    handleFilter() {
197
+      this.listQuery.page = 1
198
+      this.getList()
199
+    },
177 200
     handleSizeChange(val) {
178 201
       this.listQuery.limit = val
179 202
       this.getList()