优化随机 key 生成方法

Former-commit-id: 2348f6645bc354fc5f5e2c1291c5d2cebf047348 [formerly 2348f6645bc354fc5f5e2c1291c5d2cebf047348 [formerly 2348f6645bc354fc5f5e2c1291c5d2cebf047348 [formerly 2348f6645bc354fc5f5e2c1291c5d2cebf047348 [formerly 6ae432905579811cde8979f29eee143da2706ca9 [formerly b335fc640794be976eaf84839c300e516cc56a0d]]]]]
Former-commit-id: 7f8133308daa457b267e5a160df57530c69b92d7
Former-commit-id: 542ece96fc0188c1b72ead599382a9401d5a8035
Former-commit-id: 6c9fb38e18e09335d8369c19d657df742f1cac2c [formerly 1e2ccbec826a2f09cf17b40c3177b7b2b1ededbf]
Former-commit-id: 672b25396325dc96564258784081f3d9fc2b3645
Former-commit-id: 6dea504c5f475fee69c9a7bde160173168bcc81f
Former-commit-id: 63c30f7c3133c8ff0fce3b82c915c064412e0c46
Former-commit-id: f761a3e86ec11791a9199b5e095542aea4f310b6
Former-commit-id: 9ea8078a4da3547446a5b00d0939b3dd67d38215
This commit is contained in:
liyang
2018-08-18 22:12:41 +08:00
parent c3786ef7ff
commit 56b43aa08f
5 changed files with 17 additions and 17 deletions

View File

@@ -31,7 +31,7 @@
</template> </template>
<script> <script>
import day from 'dayjs' import { uniqueId } from 'lodash'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
export default { export default {
data () { data () {
@@ -113,12 +113,12 @@ export default {
* 添加一个随机数据 * 添加一个随机数据
*/ */
async handleSetRandom () { async handleSetRandom () {
const id = day().valueOf() const id = uniqueId()
const db = await this.databasePage({ const db = await this.databasePage({
vm: this vm: this
}) })
db db
.set(id, Math.round(id * Math.random())) .set(`uniqueKey${id}`, `value${id}`)
.write() .write()
this.load() this.load()
} }

View File

@@ -31,7 +31,7 @@
</template> </template>
<script> <script>
import day from 'dayjs' import { uniqueId } from 'lodash'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
export default { export default {
data () { data () {
@@ -117,13 +117,13 @@ export default {
* 添加一个随机数据 * 添加一个随机数据
*/ */
async handleSetRandom () { async handleSetRandom () {
const id = day().valueOf() const id = uniqueId()
const db = await this.databasePage({ const db = await this.databasePage({
vm: this, vm: this,
user: true user: true
}) })
db db
.set(id, Math.round(id * Math.random())) .set(`uniqueKey${id}`, `value${id}`)
.write() .write()
this.load() this.load()
} }

View File

@@ -31,7 +31,7 @@
</template> </template>
<script> <script>
import day from 'dayjs' import { uniqueId } from 'lodash'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
export default { export default {
data () { data () {
@@ -105,10 +105,10 @@ export default {
* 添加一个随机数据 * 添加一个随机数据
*/ */
async handleSetRandom () { async handleSetRandom () {
const id = day().valueOf() const id = uniqueId()
const db = await this.database() const db = await this.database()
db db
.set(id, Math.round(id * Math.random())) .set(`uniqueKey${id}`, `value${id}`)
.write() .write()
this.load() this.load()
} }

View File

@@ -31,7 +31,7 @@
</template> </template>
<script> <script>
import day from 'dayjs' import { uniqueId } from 'lodash'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
export default { export default {
data () { data () {
@@ -105,10 +105,10 @@ export default {
* 添加一个随机数据 * 添加一个随机数据
*/ */
async handleSetRandom () { async handleSetRandom () {
const id = day().valueOf() const id = uniqueId()
const db = await this.database({ user: true }) const db = await this.database({ user: true })
db db
.set(id, Math.round(id * Math.random())) .set(`uniqueKey${id}`, `value${id}`)
.write() .write()
this.load() this.load()
} }

View File

@@ -120,7 +120,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
resolve(db.get(pathInit({ resolve(db.get(pathInit({
dbName: 'database', dbName: 'database',
path: vm.$route[basis], path: `$page.${vm.$route[basis]}`,
user, user,
defaultValue: {} defaultValue: {}
}))) })))
@@ -141,7 +141,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
resolve(db.get(pathInit({ resolve(db.get(pathInit({
dbName: 'database', dbName: 'database',
path: vm.$route[basis], path: `$page.${vm.$route[basis]}`,
user, user,
validator: () => false, validator: () => false,
defaultValue: {} defaultValue: {}
@@ -163,7 +163,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
resolve(db.get(pathInit({ resolve(db.get(pathInit({
dbName: 'database', dbName: 'database',
path: `${vm.$route[basis]}.$data`, path: `$page.${vm.$route[basis]}.$data`,
user, user,
validator: () => false, validator: () => false,
defaultValue: vm.$data defaultValue: vm.$data
@@ -185,7 +185,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
resolve(db.get(pathInit({ resolve(db.get(pathInit({
dbName: 'database', dbName: 'database',
path: `${vm.$route[basis]}.$data`, path: `$page.${vm.$route[basis]}.$data`,
user, user,
defaultValue: vm.$data defaultValue: vm.$data
})).value()) })).value())
@@ -206,7 +206,7 @@ export default {
return new Promise(resolve => { return new Promise(resolve => {
resolve(db.get(pathInit({ resolve(db.get(pathInit({
dbName: 'database', dbName: 'database',
path: `${vm.$route[basis]}.$data`, path: `$page.${vm.$route[basis]}.$data`,
user, user,
validator: () => false, validator: () => false,
defaultValue: {} defaultValue: {}