Skip to content

Commit

Permalink
Merge branch 'master' of github.com:szuprefix/vue-django
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed May 1, 2020
2 parents 3370de8 + 8cc2152 commit c8a8eef
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 39 deletions.
8 changes: 1 addition & 7 deletions src/components/media/qcloud/Controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
</template>
<script>
import {Popup, Radio, Group} from 'vux'
import {get, throttle} from 'lodash'
import Cache from 'vue-django/src/utils/user_storage'
import {get} from 'lodash'
import {duration} from 'vue-django/src/utils/filters'
export default{
props: {
Expand Down Expand Up @@ -71,12 +70,7 @@
this.getEl().currentTime = ct
this.$vux.toast.text(`从上次断点${duration(ct)}继续播放.`)
}
// this.currentTime = ct
// this.saveCurrentTime()
},
// saveCurrentTime: throttle(function () {
// this.cache.save(this.currentTime)
// }, 2000),
setCurrentTime (ct) {
setTimeout(() => {
this.getEl().currentTime = ct
Expand Down
2 changes: 2 additions & 0 deletions src/components/mobile/model/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<slot name="icon" v-bind="scope"></slot>
</template>
</cells>

<load-more :tip="tip" :show-loading="loading" v-if="pageSize < count"></load-more>
<div v-if="!loading && count<=0" style="text-align: center;margin: 2rem 0;">暂无数据</div>
</div>
</template>
<script>
Expand Down
3 changes: 1 addition & 2 deletions src/components/mobile/model/Relations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
</template>
<script>
import {Tab, TabItem} from 'vux'
import Cache from '../../../utils/user_storage'
export default{
props: {
items: Array,
owner: Object
},
data () {
return {
cache: Cache(`${this.owner.appModel}.n${this.owner.id}.relations.tab`, this.$store.state.user.id),
cache: this.$store.state.storage.newCache(`${this.owner.appModel}.n${this.owner.id}.relations.tab`),
tab: undefined,
modelListComponents: [],
relationComponent: undefined
Expand Down
2 changes: 0 additions & 2 deletions src/mixins/form_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export default{
valid = false
}
procedure(valid)
}).catch(e => {
console.log(e)
})
}

Expand Down
11 changes: 5 additions & 6 deletions src/router/permission.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import router from './index'
import {asyncRouterMap} from './index'
import store from '../store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'// progress bar style
import {getToken, setToken, getLoginMode, removeToken} from '../utils/auth' // getToken from cookie
import {getToken, setToken} from '../utils/auth' // getToken from cookie

NProgress.configure({showSpinner: false})// NProgress Configuration
const loginUrl = '/auth/login/'
const loginUrl = '/auth/login'

router.beforeEach((to, from, next) => {
NProgress.start() // start progress bar
Expand All @@ -28,7 +27,7 @@ router.beforeEach((to, from, next) => {
// router.addRoutes(asyncRouterMap) //todo: make dynamics routers
next({...to, replace: true}) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
}).catch((error) => {
Vue.prototype.$message({message:'身份认证失败, 请重新登录', type:'error'})
Vue.$message({message:'身份认证失败, 请重新登录', type:'error'})
next({path: loginUrl, query: {redirect: to.fullPath}})
})
} else {
Expand All @@ -39,7 +38,7 @@ router.beforeEach((to, from, next) => {
if (isAllowed) {
next()
} else {
next({path: '/notallow/'})
next({path: '/notallow'})
}
}
}
Expand All @@ -53,5 +52,5 @@ router.afterEach(() => {
router.onError((err) => {
NProgress.done()
console.error(err)
Vue.prototype.$message({message:`发生异常:${err}`, type:'error'})
Vue.$message({message:`发生异常:${err}`, type:'error'})
})
5 changes: 4 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import Vue from 'vue'
import Vuex from 'vuex'
import apps from '@/configs/apps'
import {logout} from '../utils/auth'
import dailyLog from 'vue-django/src/utils/dailylog'
import dailyLog from '../utils/dailylog'
import {UserStorage} from '../utils/user_storage'
Vue.use(Vuex)
const state = {
bus: new Vue(),
user: {},
dailyLog,
storage: UserStorage(),
apps,
system_name: '',
logo: require('../assets/logo.png')
Expand All @@ -22,6 +24,7 @@ var store = new Vuex.Store({
setUser (state, payload) {
// console.log(payload)
state.user = payload
state.storage = UserStorage(payload.id)
state.bus.$emit('get-user-info', payload)
},
clearUser (state) {
Expand Down
25 changes: 14 additions & 11 deletions src/utils/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,39 @@
* Created by denishuang on 2020/1/7.
*/

export default function (options) {
import {duration} from './filters'
import {throttle} from 'lodash'
export default function (cache) {
let t = {
value: 0,
...options,
cache,
init () {
if (this.key) {
this.value = Number.parseInt(localStorage.getItem(this.key) || 0)
if (this.cache) {
this.value = this.cache.read() || 0
}
},
run () {
this.handler = setInterval(() => {
this.value++
if (this.key && this.value % 10 === 0) {
localStorage.setItem(this.key, this.value)
if (this.cache) {
this.saveCache()
}
}, 1000)
},
saveCache: throttle(function () {
this.cache.save(this.value)
}, 10000),
stop () {
clearInterval(this.handler)
},
clear () {
this.value = 0
if (this.key) {
localStorage.removeItem(this.key)
if (this.cache) {
this.cache.destroy()
}
},
toString () {
let m = Math.floor(this.value / 60)
let s = this.value % 60
return `${m}'${s}''`
return duration(this.value)
}
}
t.init()
Expand Down
38 changes: 28 additions & 10 deletions src/utils/user_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage'

export function Cache (key, db) {
if (Number.isInteger(db) || db === undefined) {
db = `userStore${db}`
}
if (typeof db === 'string') {
let adapter = new LocalStorage(db)
db = low(adapter)
db.read()
}
return {
db,
save (v) {
db.set(key, v).write()
try {
db.set(key, v).write()
} catch (e) {
alert(e.toString())
}
},
read (k) {
return db.get(k || key).value()
},
destroy () {
db.unset(key).write()
try {
db.unset(key).write()
} catch (e) {
alert(e.toString())
}
}
}
}
Expand All @@ -34,6 +34,7 @@ export function BCache (key, db) {
ps[2] = ps[2].replace(/^n/, '')
return ps.join('.')
}

let cache = Cache(key, db)
return {
...cache,
Expand All @@ -44,3 +45,20 @@ export function BCache (key, db) {
}

export default BCache

export function UserStorage (key) {
if (key === undefined) {
key = 'userStore'
}
if (Number.isInteger(key)) {
key = `userStore${key}`
}
let adapter = new LocalStorage(key)
let db = low(adapter)
return {
db,
newCache: function (key) {
return BCache(key, db)
}
}
}

0 comments on commit c8a8eef

Please sign in to comment.