前端娱乐圈

技术杂记


  • Home

  • Archives

table模拟Excel滚动查看固定表头和第一列

Posted on 2018-09-19 |

web前端下载网络图片压缩打包

Posted on 2018-09-19 |

Flutter预研

Posted on 2018-09-10 |

安装开发环境

https://flutter.io/get-started/install/

腾讯LIVE开发者大会

Posted on 2018-08-18 |

世界杯直播背后的黑科技-音视频解码

极速高清基本原理:不降低视频质量下降低视频码率,减少码率。
极速高清基本架构:

vue webpack项目中图片途径使用方法

Posted on 2018-08-17 |

前端调试工具收集

Posted on 2018-08-15 |

工具参考

工具 参考链接 简介
vConsole vConsole A lightweight, extendable front-end developer tool for mobile web page.
eruda eruda Console for Mobile Browsers.
weinre weinre weinre is WEb INspector REmote. Pronounced like the word “winery”. Or maybe like the word “weiner”. Who knows, really.
whistle whistle HTTP, HTTPS, WebSocket debugging proxy
Charles Charles Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet.
fiddler fiddler Fiddler(中文名称:小提琴)是一个HTTP的调试代理,以代理服务器的方式,监听系统的Http网络数据流动,Fiddler可以也可以让你检查所有的HTTP通讯,设置断点,以及Fiddle所有的“进出”的数据(我一般用来抓包),Fiddler还包含一个简单却功能强大的基于JScript .NET事件脚本子系统,它可以支持众多的HTTP调试任务。

参考文章
移动端调试痛点?——送你五款前端开发利器

web前端操作Excel

Posted on 2018-08-14 |

1、上传并预览Excel

效果图:

vue.js上传组件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<template>
<div>
<input id="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx, .xls" @change="handleClick">
<div id="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
Drop excel file here or
<el-button :loading="loading" style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">Browse</el-button>
</div>
</div>
</template>
<script>
import XLSX from 'xlsx'

export default {
props: {
beforeUpload: Function,
onSuccess: Function
},
data() {
return {
loading: false,
excelData: {
header: null,
results: null
}
}
},
methods: {
generateDate({ header, results }) {
this.excelData.header = header
this.excelData.results = results
this.onSuccess && this.onSuccess(this.excelData)
},
handleDrop(e) {
e.stopPropagation()
e.preventDefault()
if (this.loading) return
const files = e.dataTransfer.files
if (files.length !== 1) {
this.$message.error('Only support uploading one file!')
return
}
const rawFile = files[0] // only use files[0]

if (!this.isExcel(rawFile)) {
this.$message.error('Only supports upload .xlsx, .xls, .csv suffix files')
return false
}
this.upload(rawFile)
e.stopPropagation()
e.preventDefault()
},
handleDragover(e) {
e.stopPropagation()
e.preventDefault()
e.dataTransfer.dropEffect = 'copy'
},
handleUpload() {
document.getElementById('excel-upload-input').click()
},
handleClick(e) {
const files = e.target.files
const rawFile = files[0] // only use files[0]
if (!rawFile) return
this.upload(rawFile)
},
upload(rawFile) {
this.$refs['excel-upload-input'].value = null // fix can't select the same excel

if (!this.beforeUpload) {
this.readerData(rawFile)
return
}
const before = this.beforeUpload(rawFile)
if (before) {
this.readerData(rawFile)
}
},

// https://developer.mozilla.org/zh-CN/docs/Web/API/FormData/Using_FormData_Objects
// https://stackoverflow.com/questions/43013858/ajax-post-a-file-from-a-form-with-axios
readerData(rawFile) {
this.loading = true
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = e => {
const data = e.target.result
const fixedData = this.fixdata(data)
const workbook = XLSX.read(btoa(fixedData), { type: 'base64' })
const firstSheetName = workbook.SheetNames[0]
const worksheet = workbook.Sheets[firstSheetName]
const header = this.get_header_row(worksheet)
const results = XLSX.utils.sheet_to_json(worksheet)
this.generateDate({ header, results })
this.loading = false
resolve()
}
reader.readAsArrayBuffer(rawFile)
})
},
fixdata(data) {
let o = ''
let l = 0
const w = 10240
for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)))
o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)))
return o
},
get_header_row(sheet) {
const headers = []
const range = XLSX.utils.decode_range(sheet['!ref'])
let C
const R = range.s.r /* start in the first row */
for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */
var hdr = 'UNKNOWN ' + C // <-- replace with your desired default
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
headers.push(hdr)
}
return headers
},
isExcel(file) {
return /\.(xlsx|xls|csv)$/.test(file.name)
}
}
}
</script>

<style scoped>
#excel-upload-input{
display: none;
z-index: -9999;
}
#drop{
border: 2px dashed #bbb;
width: 600px;
height: 160px;
line-height: 160px;
margin: 0 auto;
font-size: 24px;
border-radius: 5px;
text-align: center;
color: #bbb;
position: relative;
}
</style>

引用上面组件进行上传和预览

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<template>
<div class="upload-container">
<label>上传附件: {{fileName}}</label>
<upload-excel-component :on-success='handleSuccess' :before-upload="beforeUpload"></upload-excel-component>
<!-- <el-table :data="tableData" border highlight-current-row style="width: 100%;margin-top:20px;">
<el-table-column v-for='item of tableHeader' :prop="item" :label="item" :key='item'>
</el-table-column>
</el-table> -->
</div>
<el-row>
<el-button type="success" @click="submitHandler">确定</el-button>
<el-button type="info" @click="cancelHandler">取消</el-button>
</el-row>
</div>
</template>

<script>
import UploadExcelComponent from '@/components/UploadExcel/index.vue'
import { createFilm } from '@/api/movie'

export default {
components: {
UploadExcelComponent
},
data() {
return {
tableData: [],
tableHeader: [],
filmName: '',
fileName: '',
goal: '',
releaseTime: '',
enantiomerTime: ''
}
},
methods: {
beforeUpload(file) {
const isLt1M = file.size / 1024 / 1024 < 1

if (isLt1M) {
this.fileName = file.name
this.file = file
return true
}

this.$message({
message: 'Please do not upload files larger than 1m in size.',
type: 'warning'
})
return false
},
handleSuccess({
results,
header
}) {
this.tableData = results
this.tableHeader = header
},
submitHandler() {
const { filmName, goal, file } = this
let { releaseTime, enantiomerTime } = this

if (!filmName || !goal || !releaseTime || !enantiomerTime || !file) {
this.$message.error('表单数据未填写完~')
return false
}

const currentTime = Math.floor(new Date().getTime() / 1000)
releaseTime = Math.floor(new Date(releaseTime).getTime() / 1000)
enantiomerTime = Math.floor(new Date(enantiomerTime).getTime() / 1000)

if (enantiomerTime < currentTime || enantiomerTime < releaseTime) {
this.$message.error('【下映时间】不得早于当前日期,且下映时间不能早于上映时间')
return
}

const formData = new FormData()
formData.append('film_name', filmName)
formData.append('film_row_piece_volume', goal)
formData.append('start_show_time', releaseTime)
formData.append('end_show_time', enantiomerTime)
formData.append('file', file)

createFilm(formData).then(res => {
if (res.ret === 200) {
this.$message({
message: '新建成功~',
type: 'success'
})
} else {
this.$message.error(res.message)
console.log(res)
}
this.filmName = ''
this.goal = ''
this.file = ''
this.fileName = ''
}, err => {
this.$message.error(err)
console.log(err)
})
},
cancelHandler() {}
}
}

</script>

<style lang="scss" scoped>
.film-form-box {
padding: 20px;
}

.row {
margin-bottom: 20px;
}

.label {
font-size: 15px;
margin-right: 10px;
}

.goal {
width: 50%;
}

</style>

2、预览Excel

3、下载Excel

web开发中操作文件

Posted on 2018-08-13 |

如何在web应用程序中使用文件

操作文件常见的api:

1、Blob
2、File
3、FileReader
4、URL.createObjectURL

Blob

Blob 对象表示一个不可变、原始数据的类文件对象。Blob 表示的不一定是JavaScript原生格式的数据。File 接口基于Blob,继承了 blob 的功能并将其扩展使其支持用户系统上的文件。

File

文件(File) 接口提供有关文件的信息,并允许网页中的 JavaScript 访问其内容。

FileReader

FileReader对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据。

URL.createObjectURL

URL.createObjectURL()方法会根据传入的参数创建一个指向该参数对象的URL. 这个URL的生命仅存在于它被创建的这个文档里. 新的对象URL指向执行的File对象或者是Blob对象.

参考文章

Web 开发中 Blob 与 FileAPI 使用简述

FileReader与URL.createObjectURL实现图片、视频上传预览

文件和二进制数据的操作

微信小程序文字段落展开收起组件

Posted on 2018-07-23 |

实现原理:

  1. 计算每行高度
  2. 文字段落总高度除以每行高度得出总共多少行可以显示完成
  3. js设置初始显示的高度(行数*每行高度=初始高度)

引用方法:

1
<spread-text out-class="movie-review" show-num="6" text="{{detail.movie_review}}"></spread-text>

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// spread-text.json
{
"component": true
}

// spread-text.wxml
<view class="box">
<view id="J-text" class="component spread-text out-class" style="{{textStyle}}">
{{text}}
</view>
<view class="toggle" id="J-toggle" catchtap="toggleHandler" style="display: {{showToggle}}">
<image class="arrow {{toggleText}}" src="../../images/arrow.png"></image>
</view>
<view id="J-placeholder" class="out-class" style="display: {{showPlaceholder}};">测试</view>
</view>

// spread-text.wxss
:host {
font-size: 30rpx;
color: #333;
}

.box {
position: relative;
}

.spread-text {
opacity: 0;
height: auto;
word-wrap: break-word;
transition: all 100ms linear 0s;
}

.toggle {
display: flex;
align-items: center;
justify-content: center;
height: 46rpx;
}

.toggle image {
width: 22rpx;
height: 14rpx;
}

.toggle .arrow.up {
transform: rotateZ(180deg);
}

// spread-text.js
Component({
externalClasses: ['out-class'],
properties: {
text: String,
showNum: {
type: Number,
value: 3
}
},
data: {
showPlaceholder: 'block',
textStyle: '',
toggleText: 'down',
showToggle: 'none'
},
methods: {
toggleHandler() {
if (this.data.toggleText === 'down') {
this.setData({
toggleText: 'up',
textStyle: `height: ${
this.textHeight
}px; opacity: 1; overflow: hidden;`
});
} else {
this.setData({
toggleText: 'down',
textStyle: `height: ${this.showH}px; opacity: 1; overflow: hidden;`
});
}
}
},
ready() {
const query = wx.createSelectorQuery().in(this);

query.select('#J-text').boundingClientRect();
query.select('#J-placeholder').boundingClientRect();

query.exec(res => {
const textElement = res[0];
const placeholderEelement = res[1];

const textHeight = textElement.height;
const placeholderHeight = parseInt(placeholderEelement.height, 10);

this.showH = placeholderHeight * this.data.showNum;
this.textHeight = textHeight;

if (this.showH < textHeight) {
this.setData({
showToggle: 'flex',
showPlaceholder: 'none',
textStyle: `height: ${this.showH}px; opacity: 1; overflow: hidden;`
});
} else {
this.setData({
showToggle: 'none',
showPlaceholder: 'none',
textStyle: `height: ${
this.textHeight
}px; opacity: 1; overflow: hidden;`
});
}
});
}
});

Hello Hexo

Posted on 2018-01-15 |

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

开始步骤

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

计划完成事项

  1. Hexo 框架介绍
  2. 框架的本地安装与运行
  3. 框架的基本结构与打包后的文件介绍
  4. Hexo 博客主题的安装与推荐
  5. 如何自定义你的博客结构
  6. 如何开始写博客文章以及文章的分类与标签
  7. 如何让代码在 Hexo 下显示的更加美观
  8. 本地写作时图床的最佳解决方案
  9. 插件的安装与必备插件介绍
  10. 如何让你的博客接入评论系统
  11. 如何给你的博客增加搜索功能
  12. 多个博客统计系统的接入方案分析
  13. 部署博客到 GitHub 的技巧
  14. Hexo 其他资源的介绍与分享
123
Luxlu(boylufeng@gmail.com)

Luxlu(boylufeng@gmail.com)

HTML CSS Javascript Node.js HTTP

22 posts
6 categories
6 tags
© 2019 Luxlu(boylufeng@gmail.com)
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4