Skip to content

Commit

Permalink
upload, store modules, excel
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed May 16, 2020
1 parent 93dd1ae commit 24c55a5
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<template v-else>
<el-menu class="el-menu-demo" mode="horizontal" router>
<el-menu-item index="/" class="brand">
<img :src="logo" height="32">
<b v-if="user.as_saas_worker">{{user.as_saas_worker.party}}</b>
<img :src="party.logo" height="32">
<b v-if="user.as_saas_worker">{{party.name}}</b>
{{system_name}}
</el-menu-item>
<el-submenu index="2" style="float:right">
Expand Down Expand Up @@ -51,7 +51,7 @@
layout (){
return this.$route.meta.layout
},
...mapState(['user', 'system_name', 'logo'])
...mapState(['user', 'system_name', 'party'])
},
methods: {
logout(){
Expand Down
2 changes: 1 addition & 1 deletion src/components/media/VideoInput.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<q-video :width="field.width" :height="field.height" :appID="$store.state.qcloud.vod.appId" :fileID="fileId">
<q-video :width="field.width" :height="field.height" :appID="$store.state.party.settings.media.qcloud.vod.appid" :fileID="fileId">
</q-video>
</template>
<script>
Expand Down
2 changes: 1 addition & 1 deletion src/components/media/VideoWidget.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<q-video :width="field.width" :height="field.height" :appID="$store.state.qcloud.vod.appId"
<q-video :width="field.width" :height="field.height" :appID="$store.state.party.settings.media.qcloud.vod.appid"
:fileID="fileId" ref="video">
</q-video>
</template>
Expand Down
24 changes: 17 additions & 7 deletions src/components/media/qcloud/ImageUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="image-uploader"
ref="upload"
action="noaction"
accept=".jpg,.png,.jpeg"
accept=".jpg,.png,.jpeg,.gif"
list-type="picture-card"
:file-list="fileList"
v-bind="[$attrs, $props]"
Expand Down Expand Up @@ -78,14 +78,14 @@
this.dialogVisible = true
},
onProgress(event, file, fileList){
console.log(['progress', event, file, fileList])
// console.log(['progress', event, file, fileList])
},
onError(err, file, fileList){
console.log(['error', err, file, fileList])
},
onSuccess(response, file, fileList){
let sf = fileList.find(f => f.uid = file.uid)
let sf = fileList.find(f => f.uid === file.uid)
if (!sf) {
console.error('file not found:', file.uid)
return
Expand All @@ -98,12 +98,12 @@
this.$emit('remove', {file, fileList})
},
onChange (file, fileList) {
console.log('change')
// console.log('change')
this.fileList = fileList
},
toggleAdd () {
if (this.$attrs.limit === 1) {
console.debug(this.$attrs.limit, this.fileList.length)
// console.debug(this.$attrs.limit, this.fileList.length)
if (this.fileList.length>0) {
this.elUploader.classList.add('hidden')
} else {
Expand All @@ -119,6 +119,13 @@
let url = URL.createObjectURL(file)
return url
},
getFileNumber(fn) {
let re = /(\d+)\./g
let m =re.exec(fn)
if(m) {
return m[1]
}
},
getFileNameContext (fn) {
let ps = fn.split('.')
let extName = undefined
Expand All @@ -134,14 +141,16 @@
extName,
fileName,
baseName,
dateTime
dateTime,
number: this.getFileNumber(fn)
}
},
uploadFile (req) {
let file = req.file
let fn = file.name
let ctx = {...this.context, ...this.getFileNameContext(fn)}
console.log(ctx)
file.uploadContext = ctx
// console.log(ctx)
let fileName = template(this.fileName || '${dateTime}.${extName}')(ctx)
// console.log(fileName)
// return
Expand All @@ -153,6 +162,7 @@
Key: fileName,
Body: req.file,
onProgress: function (info) {
console.log('tcCos.onProgress', info, req)
req.onProgress(info)
}
}, function (err, data) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/mobile/model/Relations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
data () {
return {
cache: this.$store.state.storage.newCache(`${this.owner.appModel}.n${this.owner.id}.relations.tab`),
cache: this.$store.state.user.storage.newCache(`${this.owner.appModel}.n${this.owner.id}.relations.tab`),
tab: undefined,
modelListComponents: [],
relationComponent: undefined
Expand Down
1 change: 0 additions & 1 deletion src/components/model/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
return {multiple: false, ...a, label, widget: this.defaultWidget(a)}
})
this.filterFields = this.reorder(ffields)
console.log(search.filter_fields, ffields, this.filterFields)
this.filters = Object.assign({}, this.getFilters())
},
defaultWidget (item) {
Expand Down
45 changes: 45 additions & 0 deletions src/components/sheets/ExcelReader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template>
<div>
<el-upload :http-request="readFile" ref="uploader" accept=".xls,.xlsx"
:show-file-list="false"
:on-change="onChange">
<el-button size="small" type="primary">打开文件</el-button>
<div slot="tip" class="el-upload__tip">只能上传excel文件,且不超过5MB</div>
</el-upload>
</div>
</template>
<script>
function readWorkbookFromLocalFile(XLSX, file, callback) {
var reader = new FileReader()
reader.onload = function (e) {
var data = e.target.result
var workbook = XLSX.read(data, {type: 'binary'})
if (callback) callback(workbook)
}
reader.readAsBinaryString(file)
}
export default{
data () {
return {}
},
components: {},
methods: {
onChange(file, fileList) {
console.log(file)
},
readFile(req) {
let file = req.file
import('xlsx').then(XLSX => {
readWorkbookFromLocalFile(XLSX, file, (wb) => {
let data = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
this.$emit('read', {file, data, wb})
})
})
}
},
computed: {}
}
</script>
21 changes: 21 additions & 0 deletions src/components/table/widgets/Html.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div v-html="value[field.name]">
html
</div>
</template>
<script>
export default{
props: {
value: String,
field: Object,
context: Object
},
data () {
return {}
},
components: {},
methods: {},
computed: {}
}
</script>

32 changes: 5 additions & 27 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,24 @@ import Vue from 'vue'
import Vuex from 'vuex'
import apps from '@/configs/apps'
import {logout} from '../utils/auth'
import user from './modules/user'
import party from './modules/party'
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')
}

var store = new Vuex.Store({
state: state,
mutations: {
setUser (state, payload) {
// console.log(payload)
state.user = payload
state.storage = UserStorage(payload.id)
state.bus.$emit('get-user-info', payload)
},
clearUser (state) {
state.user = {}
state.bus.$emit('user-logout')
}
},
actions: {
getUserInfo (context) {
return Vue.http.get('/auth/user/current/').then(({data}) => {
context.commit('setUser', data)
return data
})
},
logout (context) {
return logout().then((data) => {
context.commit('clearUser')
return data
})
}
modules: {
user,
party
},
plugins: []
})
Expand Down
24 changes: 24 additions & 0 deletions src/store/modules/party.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Vue from 'vue'

const party = {
state: {
name: null,
logo: null
},

mutations: {
setParty(state, payload){
Object.assign(state, payload)
}
},
actions: {
getPartyInfo ({commit, rootState}){
return Vue.http.get("/saas/party/current/").then(({data}) => {
commit("setParty", data)
return data
})
}
}
}

export default party
35 changes: 35 additions & 0 deletions src/store/modules/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Created by denishuang on 2020/5/15.
*/
import UserStorage from '../../utils/user_storage'
import {logout} from '../../utils/auth'
export default {
state: {
storage: UserStorage()
},
mutations: {
setUser (state, payload) {
Object.assign(state, payload)
state.storage = UserStorage(payload.id)
},
clearUser (state) {
state.user = {}
}
},
actions: {
getUserInfo ({commit, rootState}) {
return Vue.http.get('/auth/user/current/').then(({data}) => {
commit('setUser', data)
rootState.bus.$emit('get-user-info', data)
return data
})
},
logout ({commit, rootState}) {
return logout().then((data) => {
commit('clearUser')
rootState.bus.$emit('user-logout')
return data
})
}
}
}
27 changes: 27 additions & 0 deletions src/utils/blob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Created by denishuang on 2020/4/29.
*/

export function img2canvas(img) {
let canvas = document.createElement('canvas')
canvas.width = img.width
canvas.height = img.height
canvas.getContext('2d').drawImage(img, 0, 0)
return canvas
}

export function dataurl2blob(durl) {
let arr = durl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new Blob([u8arr], {type:mime})
}

export function img2blob(img) {
return dataurl2blob(img2canvas(img).toDataURL('image/png'))
}

0 comments on commit 24c55a5

Please sign in to comment.