Skip to content

Commit

Permalink
List
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Feb 7, 2020
1 parent 143383f commit 5a2cc77
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
50 changes: 50 additions & 0 deletions src/components/mobile/List.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<panel v-bind="[$attrs]" :list="list" v-if="list.length>0"></panel>
</template>
<script>
import {Panel} from 'vux'
export default{
props: {
items: {type: Array, default: []},
value: {type: Array, default: []}
},
data () {
return {
list: []
}
},
components: {Panel},
methods: {
normailizeList () {
let ls = []
this.value.map((a) => {
let d = {meta: {}}
this.items.forEach((f) => {
let p = f.placeholder || 'meta'
let v = a[f.name]
if (f.format) {
v = f.format(v)
}
if (['source', 'date', 'other'].includes(p)) {
d['meta'][p] = v
} else {
d[p] = v
}
})
ls.push(d)
})
this.list = ls
// console.log(this.list)
}
},
created () {
this.normailizeList()
},
computed: {},
watch: {
value (v) {
this.normailizeList()
}
}
}
</script>
6 changes: 3 additions & 3 deletions src/utils/array_normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
export default function (items, templates, normalize) {
return items.map((a) => {
let d = {}
if (typeof a == 'string' || a instanceof String) {
if (typeof a === 'string' || a instanceof String) {
Object.assign(d, templates[a])
d.name = a
} else if(a instanceof Array){
} else if (a instanceof Array) {
d = a
} else {
Object.assign(d, templates[a.name], a)
Expand All @@ -18,4 +18,4 @@ export default function (items, templates, normalize) {
}
return d
})
}
}
40 changes: 40 additions & 0 deletions src/utils/timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Created by denishuang on 2020/1/7.
*/

export default function (options) {
let t = {
value: 0,
...options,
init () {
if (this.key) {
this.value = Number.parseInt(localStorage.getItem(this.key) || 0)
}
},
run () {
this.handler = setInterval(() => {
this.value++
if (this.key && this.value % 10 === 0) {
localStorage.setItem(this.key, this.value)
}
}, 1000)
},
stop () {
clearInterval(this.handler)
},
clear () {
this.value = 0
if (this.key) {
localStorage.removeItem(this.key)
}
},
toString () {
let m = Math.floor(this.value / 60)
let s = this.value % 60
return `${m}'${s}''`
}
}
t.init()
t.run()
return t
}

0 comments on commit 5a2cc77

Please sign in to comment.