ref: Remove eslint-disbale.

This commit is contained in:
EdwinBetanc0urt 2020-08-27 10:41:41 -04:00
parent 5e7113935c
commit e56c0f5d35
9 changed files with 208 additions and 145 deletions

View File

@ -247,9 +247,8 @@ export default {
lang, lang,
// //
isSupported, isSupported,
// // Does the browser support touch screen events?
// eslint-disable-next-line no-prototype-builtins isSupportTouch: Object.prototype.hasOwnProperty.call(document, 'ontouchstart'),
isSupportTouch: document.hasOwnProperty('ontouchstart'),
// //
step: 1, // 1 2 3 step: 1, // 1 2 3
// //
@ -574,7 +573,9 @@ export default {
const dY = nY - mY const dY = nY - mY
let rX = x + dX let rX = x + dX
let rY = y + dY let rY = y + dY
if (!on) return if (!on) {
return
}
if (rX > 0) { if (rX > 0) {
rX = 0 rX = 0
} }

View File

@ -16,8 +16,12 @@ import 'codemirror/addon/lint/json-lint'
export default { export default {
name: 'JsonEditor', name: 'JsonEditor',
/* eslint-disable vue/require-prop-types */ props: {
props: ['value'], value: {
type: [Array, Boolean, Number, Object, String, Symbol],
default: undefined
}
},
data() { data() {
return { return {
jsonEditor: false jsonEditor: false

View File

@ -111,26 +111,38 @@
<script> <script>
// source:https://github.com/wemake-services/vue-material-input/blob/master/src/components/MaterialInput.vue // source:https://github.com/wemake-services/vue-material-input/blob/master/src/components/MaterialInput.vue
const propString = {
type: String,
default: undefined
}
export default { export default {
name: 'MdInput', name: 'MdInput',
props: { props: {
/* eslint-disable */ icon: propString,
icon: String, name: propString,
name: String,
type: { type: {
type: String, type: String,
default: 'text' default: 'text'
}, },
value: [String, Number], value: {
placeholder: String, type: [String, Number],
default: undefined
},
placeholder: propString,
readonly: Boolean, readonly: Boolean,
disabled: Boolean, disabled: Boolean,
min: String, min: propString,
max: String, max: propString,
step: String, step: propString,
minlength: Number, minlength: {
maxlength: Number, type: Number,
default: -Infinity
},
maxlength: {
type: Number,
default: +Infinity
},
required: { required: {
type: Boolean, type: Boolean,
default: true default: true

View File

@ -5,8 +5,7 @@
<slot /> <slot />
</div> </div>
</div> </div>
<!-- eslint-disable-next-line --> <div :style="{backgroundImage: `url(${image})`}" class="pan-thumb" />
<div :style="{backgroundImage: `url(${image})`}" class="pan-thumb"></div>
</div> </div>
</template> </template>

View File

@ -15,8 +15,14 @@ import XLSX from 'xlsx'
export default { export default {
props: { props: {
beforeUpload: Function, // eslint-disable-line beforeUpload: {
onSuccess: Function// eslint-disable-line type: Function,
default: () => {}
},
onSuccess: {
type: Function,
default: () => {}
}
}, },
data() { data() {
return { return {
@ -36,7 +42,9 @@ export default {
handleDrop(e) { handleDrop(e) {
e.stopPropagation() e.stopPropagation()
e.preventDefault() e.preventDefault()
if (this.loading) return if (this.loading) {
return
}
const files = e.dataTransfer.files const files = e.dataTransfer.files
if (files.length !== 1) { if (files.length !== 1) {
this.$message.error('Only support uploading one file!') this.$message.error('Only support uploading one file!')
@ -63,7 +71,9 @@ export default {
handleClick(e) { handleClick(e) {
const files = e.target.files const files = e.target.files
const rawFile = files[0] // only use files[0] const rawFile = files[0] // only use files[0]
if (!rawFile) return if (!rawFile) {
return
}
this.upload(rawFile) this.upload(rawFile)
}, },
upload(rawFile) { upload(rawFile) {
@ -106,7 +116,9 @@ export default {
const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })]
/* find the cell in the first row */ /* find the cell in the first row */
let hdr = 'UNKNOWN ' + C // <-- replace with your desired default let hdr = 'UNKNOWN ' + C // <-- replace with your desired default
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell) if (cell && cell.t) {
hdr = XLSX.utils.format_cell(cell)
}
headers.push(hdr) headers.push(hdr)
} }
return headers return headers

View File

@ -12,16 +12,20 @@ export default {
el._v_clipboard_error = binding.value el._v_clipboard_error = binding.value
} else { } else {
const clipboard = new Clipboard(el, { const clipboard = new Clipboard(el, {
text() { return binding.value }, text() {
action() { return binding.arg === 'cut' ? 'cut' : 'copy' } return binding.value
},
action() {
return binding.arg === 'cut' ? 'cut' : 'copy'
}
}) })
clipboard.on('success', e => { clipboard.on('success', e => {
const callback = el._v_clipboard_success const callback = el._v_clipboard_success
callback && callback(e) // eslint-disable-line callback && callback(e)
}) })
clipboard.on('error', e => { clipboard.on('error', e => {
const callback = el._v_clipboard_error const callback = el._v_clipboard_error
callback && callback(e) // eslint-disable-line callback && callback(e)
}) })
el._v_clipboard = clipboard el._v_clipboard = clipboard
} }
@ -32,8 +36,12 @@ export default {
} else if (binding.arg === 'error') { } else if (binding.arg === 'error') {
el._v_clipboard_error = binding.value el._v_clipboard_error = binding.value
} else { } else {
el._v_clipboard.text = function() { return binding.value } el._v_clipboard.text = function() {
el._v_clipboard.action = function() { return binding.arg === 'cut' ? 'cut' : 'copy' } return binding.value
}
el._v_clipboard.action = function() {
return binding.arg === 'cut' ? 'cut' : 'copy'
}
} }
}, },
unbind(el, binding) { unbind(el, binding) {

View File

@ -13,8 +13,7 @@ const state = {
const mutations = { const mutations = {
CHANGE_SETTING: (state, { key, value }) => { CHANGE_SETTING: (state, { key, value }) => {
// eslint-disable-next-line no-prototype-builtins if (Object.prototype.hasOwnProperty.call(state, key)) {
if (state.hasOwnProperty(key)) {
state[key] = value state[key] = value
} }
} }
@ -32,4 +31,3 @@ export default {
mutations, mutations,
actions actions
} }

View File

@ -1,33 +1,36 @@
/* eslint-disable */
import { saveAs } from 'file-saver' import { saveAs } from 'file-saver'
import XLSX from 'xlsx' import XLSX from 'xlsx'
function generateArray(table) { function generateArray(table) {
var out = []; const out = []
var rows = table.querySelectorAll('tr'); const rows = table.querySelectorAll('tr')
var ranges = []; const ranges = []
for (var R = 0; R < rows.length; ++R) { for (let R = 0; R < rows.length; ++R) {
var outRow = []; const outRow = []
var row = rows[R]; const row = rows[R]
var columns = row.querySelectorAll('td'); const columns = row.querySelectorAll('td')
for (var C = 0; C < columns.length; ++C) { for (let C = 0; C < columns.length; ++C) {
var cell = columns[C]; const cell = columns[C]
var colspan = cell.getAttribute('colspan'); let colspan = cell.getAttribute('colspan')
var rowspan = cell.getAttribute('rowspan'); let rowspan = cell.getAttribute('rowspan')
var cellValue = cell.innerText; let cellValue = cell.innerText
if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue; if (cellValue !== '' && cellValue === +cellValue) {
cellValue = +cellValue
}
//Skip ranges // Skip ranges
ranges.forEach(function (range) { ranges.forEach(function(range) {
if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) { if (R >= range.s.r && R <= range.e.r && outRow.length >= range.s.c && outRow.length <= range.e.c) {
for (var i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null); for (let i = 0; i <= range.e.c - range.s.c; ++i) {
outRow.push(null)
}
} }
}); })
//Handle Row Span // Handle Row Span
if (rowspan || colspan) { if (rowspan || colspan) {
rowspan = rowspan || 1; rowspan = rowspan || 1
colspan = colspan || 1; colspan = colspan || 1
ranges.push({ ranges.push({
s: { s: {
r: R, r: R,
@ -37,30 +40,35 @@ function generateArray(table) {
r: R + rowspan - 1, r: R + rowspan - 1,
c: outRow.length + colspan - 1 c: outRow.length + colspan - 1
} }
}); })
}; }
//Handle Value // Handle Value
outRow.push(cellValue !== "" ? cellValue : null); outRow.push(cellValue !== '' ? cellValue : null)
//Handle Colspan // Handle Colspan
if (colspan) if (colspan) {
for (var k = 0; k < colspan - 1; ++k) outRow.push(null); for (let k = 0; k < colspan - 1; ++k) {
outRow.push(null)
}
}
} }
out.push(outRow); out.push(outRow)
} }
return [out, ranges]; return [out, ranges]
}; }
function datenum(v, date1904) { function datenum(v, date1904) {
if (date1904) v += 1462; if (date1904) {
var epoch = Date.parse(v); v += 1462
return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); }
const epoch = Date.parse(v)
return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000)
} }
function sheet_from_array_of_arrays(data, opts) { function sheet_from_array_of_arrays(data, opts) {
var ws = {}; const ws = {}
var range = { const range = {
s: { s: {
c: 10000000, c: 10000000,
r: 10000000 r: 10000000
@ -69,79 +77,99 @@ function sheet_from_array_of_arrays(data, opts) {
c: 0, c: 0,
r: 0 r: 0
} }
}; }
for (var R = 0; R != data.length; ++R) { for (let R = 0; R !== data.length; ++R) {
for (var C = 0; C != data[R].length; ++C) { for (let C = 0; C !== data[R].length; ++C) {
if (range.s.r > R) range.s.r = R; if (range.s.r > R) {
if (range.s.c > C) range.s.c = C; range.s.r = R
if (range.e.r < R) range.e.r = R; }
if (range.e.c < C) range.e.c = C; if (range.s.c > C) {
var cell = { range.s.c = C
}
if (range.e.r < R) {
range.e.r = R
}
if (range.e.c < C) {
range.e.c = C
}
const cell = {
v: data[R][C] v: data[R][C]
}; }
if (cell.v == null) continue; if (cell.v === null) {
var cell_ref = XLSX.utils.encode_cell({ continue
}
const cell_ref = XLSX.utils.encode_cell({
c: C, c: C,
r: R r: R
}); })
if (typeof cell.v === 'number') cell.t = 'n'; if (typeof cell.v === 'number') {
else if (typeof cell.v === 'boolean') cell.t = 'b'; cell.t = 'n'
else if (cell.v instanceof Date) { } else if (typeof cell.v === 'boolean') {
cell.t = 'n'; cell.t = 'b'
cell.z = XLSX.SSF._table[14]; } else if (cell.v instanceof Date) {
cell.v = datenum(cell.v); cell.t = 'n'
} else cell.t = 's'; cell.z = XLSX.SSF._table[14]
cell.v = datenum(cell.v)
} else {
cell.t = 's'
}
ws[cell_ref] = cell; ws[cell_ref] = cell
} }
} }
if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); if (range.s.c < 10000000) {
return ws; ws['!ref'] = XLSX.utils.encode_range(range)
}
return ws
} }
function Workbook() { function Workbook() {
if (!(this instanceof Workbook)) return new Workbook(); if (!(this instanceof Workbook)) {
this.SheetNames = []; return new Workbook()
this.Sheets = {}; }
this.SheetNames = []
this.Sheets = {}
} }
function s2ab(s) { function s2ab(s) {
var buf = new ArrayBuffer(s.length); const buf = new ArrayBuffer(s.length)
var view = new Uint8Array(buf); const view = new Uint8Array(buf)
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; for (let i = 0; i !== s.length; ++i) {
return buf; view[i] = s.charCodeAt(i) & 0xFF
}
return buf
} }
export function export_table_to_excel(id) { export function export_table_to_excel(id) {
var theTable = document.getElementById(id); const theTable = document.getElementById(id)
var oo = generateArray(theTable); const oo = generateArray(theTable)
var ranges = oo[1]; const ranges = oo[1]
/* original data */ // original data
var data = oo[0]; const data = oo[0]
var ws_name = "SheetJS"; const ws_name = 'SheetJS'
var wb = new Workbook(), const wb = new Workbook()
ws = sheet_from_array_of_arrays(data); const ws = sheet_from_array_of_arrays(data)
/* add ranges to worksheet */ // add ranges to worksheet
// ws['!cols'] = ['apple', 'banan']; // ws['!cols'] = ['apple', 'banan']
ws['!merges'] = ranges; ws['!merges'] = ranges
/* add worksheet to workbook */ // add worksheet to workbook
wb.SheetNames.push(ws_name); wb.SheetNames.push(ws_name)
wb.Sheets[ws_name] = ws; wb.Sheets[ws_name] = ws
var wbout = XLSX.write(wb, { const wbout = XLSX.write(wb, {
bookType: 'xlsx', bookType: 'xlsx',
bookSST: false, bookSST: false,
type: 'binary' type: 'binary'
}); })
saveAs(new Blob([s2ab(wbout)], { saveAs(new Blob([s2ab(wbout)], {
type: "application/octet-stream" type: 'application/octet-stream'
}), "test.xlsx") }), 'test.xlsx')
} }
export function export_json_to_excel({ export function export_json_to_excel({
@ -153,68 +181,69 @@ export function export_json_to_excel({
autoWidth = true, autoWidth = true,
bookType = 'xlsx' bookType = 'xlsx'
} = {}) { } = {}) {
/* original data */ // original data
filename = filename || 'excel-list' filename = filename || 'excel-list'
data = [...data] data = [...data]
data.unshift(header); data.unshift(header)
for (let i = multiHeader.length - 1; i > -1; i--) { for (let i = multiHeader.length - 1; i > -1; i--) {
data.unshift(multiHeader[i]) data.unshift(multiHeader[i])
} }
var ws_name = "SheetJS"; const ws_name = 'SheetJS'
var wb = new Workbook(), const wb = new Workbook()
ws = sheet_from_array_of_arrays(data); const ws = sheet_from_array_of_arrays(data)
if (merges.length > 0) { if (merges.length > 0) {
if (!ws['!merges']) ws['!merges'] = []; if (!ws['!merges']) {
ws['!merges'] = []
}
merges.forEach(item => { merges.forEach(item => {
ws['!merges'].push(XLSX.utils.decode_range(item)) ws['!merges'].push(XLSX.utils.decode_range(item))
}) })
} }
if (autoWidth) { if (autoWidth) {
/*设置worksheet每列的最大宽度*/ // set the maximum width of each column of the worksheet
const colWidth = data.map(row => row.map(val => { const colWidth = data.map(row => row.map(val => {
/*先判断是否为null/undefined*/ // determine first if it is null/undefined
if (val == null) { if (val === null || val === undefined) {
return { return {
'wch': 10 'wch': 10
}; }
} } else if (val.toString().charCodeAt(0) > 255) {
/*再判断是否为中文*/ // and then determine if it's Chinese
else if (val.toString().charCodeAt(0) > 255) {
return { return {
'wch': val.toString().length * 2 'wch': val.toString().length * 2
}; }
} else { } else {
return { return {
'wch': val.toString().length 'wch': val.toString().length
}; }
} }
})) }))
/*以第一行为初始值*/ // initial value in the first action
let result = colWidth[0]; const result = colWidth[0]
for (let i = 1; i < colWidth.length; i++) { for (let i = 1; i < colWidth.length; i++) {
for (let j = 0; j < colWidth[i].length; j++) { for (let j = 0; j < colWidth[i].length; j++) {
if (result[j]['wch'] < colWidth[i][j]['wch']) { if (result[j]['wch'] < colWidth[i][j]['wch']) {
result[j]['wch'] = colWidth[i][j]['wch']; result[j]['wch'] = colWidth[i][j]['wch']
} }
} }
} }
ws['!cols'] = result; ws['!cols'] = result
} }
/* add worksheet to workbook */ // add worksheet to workbook
wb.SheetNames.push(ws_name); wb.SheetNames.push(ws_name)
wb.Sheets[ws_name] = ws; wb.Sheets[ws_name] = ws
var wbout = XLSX.write(wb, { const wbout = XLSX.write(wb, {
bookType: bookType, bookType: bookType,
bookSST: false, bookSST: false,
type: 'binary' type: 'binary'
}); })
saveAs(new Blob([s2ab(wbout)], { saveAs(new Blob([s2ab(wbout)], {
type: "application/octet-stream" type: 'application/octet-stream'
}), `${filename}.${bookType}`); }), `${filename}.${bookType}`)
} }

View File

@ -1,4 +1,3 @@
/* eslint-disable */
import { saveAs } from 'file-saver' import { saveAs } from 'file-saver'
import JSZip from 'jszip' import JSZip from 'jszip'
@ -15,10 +14,11 @@ export function export_txt_to_zip(th, jsonData, txtName, zipName) {
}) })
zip.file(`${txt_name}.txt`, txtData) zip.file(`${txt_name}.txt`, txtData)
zip.generateAsync({ zip.generateAsync({
type: "blob" type: 'blob'
}).then((blob) => { }).then((blob) => {
saveAs(blob, `${zip_name}.zip`) saveAs(blob, `${zip_name}.zip`)
}, (err) => { }, (error) => {
alert('导出失败') alert('Export Failure')
console.warn(error)
}) })
} }