Commit 4e9b3417 by wangyalan-git

评论管理模块/资讯管理模块/用户下级查看/导出

parent a637534e
...@@ -11610,6 +11610,12 @@ ...@@ -11610,6 +11610,12 @@
"unpipe": "1.0.0" "unpipe": "1.0.0"
} }
}, },
"raw-loader": {
"version": "0.5.1",
"resolved": "https://registry.npm.taobao.org/raw-loader/download/raw-loader-0.5.1.tgz?cache=0&sync_timestamp=1602255313867&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fraw-loader%2Fdownload%2Fraw-loader-0.5.1.tgz",
"integrity": "sha1-DD0L6u2KAclm2Xh793goElKpeao=",
"dev": true
},
"read-cache": { "read-cache": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npm.taobao.org/read-cache/download/read-cache-1.0.0.tgz", "resolved": "https://registry.npm.taobao.org/read-cache/download/read-cache-1.0.0.tgz",
...@@ -12195,6 +12201,15 @@ ...@@ -12195,6 +12201,15 @@
} }
} }
}, },
"script-loader": {
"version": "0.7.2",
"resolved": "https://registry.npm.taobao.org/script-loader/download/script-loader-0.7.2.tgz",
"integrity": "sha1-IBbbb4byX1z1baOJFdgzeLsWa6c=",
"dev": true,
"requires": {
"raw-loader": "~0.5.1"
}
},
"scss-tokenizer": { "scss-tokenizer": {
"version": "0.2.3", "version": "0.2.3",
"resolved": "https://registry.npm.taobao.org/scss-tokenizer/download/scss-tokenizer-0.2.3.tgz", "resolved": "https://registry.npm.taobao.org/scss-tokenizer/download/scss-tokenizer-0.2.3.tgz",
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
"cross-spawn": "5.0.1", "cross-spawn": "5.0.1",
"css-loader": "0.28.0", "css-loader": "0.28.0",
"eslint": "3.19.0", "eslint": "3.19.0",
"script-loader": "^0.7.2",
"eslint-config-standard": "10.2.1", "eslint-config-standard": "10.2.1",
"eslint-friendly-formatter": "3.0.0", "eslint-friendly-formatter": "3.0.0",
"eslint-loader": "1.7.1", "eslint-loader": "1.7.1",
......
...@@ -11,7 +11,8 @@ export const tableOption = { ...@@ -11,7 +11,8 @@ export const tableOption = {
column: [ column: [
{ {
label: '用户昵称', label: '用户昵称',
prop: 'nickName' prop: 'nickName',
search: true
}, },
{ {
label: '用户头像', label: '用户头像',
...@@ -21,6 +22,7 @@ export const tableOption = { ...@@ -21,6 +22,7 @@ export const tableOption = {
{ {
label: '资讯标题', label: '资讯标题',
prop: 'consultTitle', prop: 'consultTitle',
search: true
}, },
{ {
label: '评论内容', label: '评论内容',
...@@ -31,6 +33,22 @@ export const tableOption = { ...@@ -31,6 +33,22 @@ export const tableOption = {
prop: 'createTime' prop: 'createTime'
}, },
{ {
label: '资讯类型',
prop: 'consultType',
search: true,
slot: true,
type: 'select',
dicData: [
{
label: '全供头条',
value: 1
}, {
label: '热议专区',
value: 2
}
]
},
{
label: '状态', label: '状态',
prop: 'status', prop: 'status',
search: true, search: true,
......
...@@ -80,6 +80,11 @@ export const tableOption = { ...@@ -80,6 +80,11 @@ export const tableOption = {
label: '时间', label: '时间',
prop: 'createTime' prop: 'createTime'
}, },
{
label: '查看评论',
prop: 'view',
slot: true
},
] ]
} }
...@@ -21,27 +21,35 @@ export const tableOption = { ...@@ -21,27 +21,35 @@ export const tableOption = {
label: '用户昵称', label: '用户昵称',
prop: 'nickName', prop: 'nickName',
search: true search: true
}, { },
label: '用户头像', {
prop: 'pic', label: '用户头像',
type: 'upload', prop: 'pic',
imgWidth: 60, type: 'upload',
listType: 'picture-img' imgWidth: 60,
}, { listType: 'picture-img'
label: '状态', }, {
prop: 'status', label: '状态',
search: true, prop: 'status',
type: 'select', search: true,
slot: true, type: 'select',
dicData: [ slot: true,
{ dicData: [
label: '禁用', {
value: 0 label: '禁用',
}, { value: 0
label: '正常', }, {
value: 1 label: '正常',
} value: 1
] }
]
},
{
label: '查看下级',
prop: 'view',
slot: true
}] }]
} }
...@@ -133,7 +133,7 @@ export default { ...@@ -133,7 +133,7 @@ export default {
var ids = row.hotSearchId ? [row.hotSearchId] : this.dataListSelections.map(item => { var ids = row.hotSearchId ? [row.hotSearchId] : this.dataListSelections.map(item => {
return item.hotSearchId return item.hotSearchId
}) })
this.$confirm(`确定对[id=${ids.join(',')}]进行[${row.hotSearchId ? '删除' : '批量删除'}]操作?`, '提示', { this.$confirm(`确定对[id=${ids.join(',')}]进行[${row.hotSearchId ? '删除' : '批量删除'}]操作?`, ':span="8"', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
......
...@@ -13,6 +13,16 @@ ...@@ -13,6 +13,16 @@
<img :src="scope.row.pic" style="width: 60px;" alt=""> <img :src="scope.row.pic" style="width: 60px;" alt="">
</template> </template>
<template slot-scope="scope" <template slot-scope="scope"
slot="consultType">
<el-tag v-if="scope.row.consultType === 1"
size="small"
type="success"
>全供头条</el-tag>
<el-tag v-else
size="small"
>热议专区</el-tag>
</template>
<template slot-scope="scope"
slot="status"> slot="status">
<el-tag v-if="scope.row.status === 0" <el-tag v-if="scope.row.status === 0"
size="small" size="small"
...@@ -48,6 +58,7 @@ import { tableOption } from '@/crud/shop/comments' ...@@ -48,6 +58,7 @@ import { tableOption } from '@/crud/shop/comments'
export default { export default {
data () { data () {
return { return {
id: '',
dataList: [], dataList: [],
page: { page: {
total: 0, // 总页数 total: 0, // 总页数
...@@ -68,6 +79,7 @@ export default { ...@@ -68,6 +79,7 @@ export default {
created () { created () {
}, },
mounted () { mounted () {
this.id = this.$route.query.id || ''
}, },
methods: { methods: {
getDataList (page, params) { getDataList (page, params) {
...@@ -77,7 +89,8 @@ export default { ...@@ -77,7 +89,8 @@ export default {
method: 'get', method: 'get',
params: this.$http.adornParams(Object.assign({ params: this.$http.adornParams(Object.assign({
current: page == null ? this.page.currentPage : page.currentPage, current: page == null ? this.page.currentPage : page.currentPage,
size: page == null ? this.page.pageSize : page.pageSize size: page == null ? this.page.pageSize : page.pageSize,
consultId: this.$route.query.id
}, params)) }, params))
}).then(({ data }) => { }).then(({ data }) => {
this.dataList = data.records this.dataList = data.records
...@@ -126,7 +139,7 @@ export default { ...@@ -126,7 +139,7 @@ export default {
}).then(() => { }).then(() => {
this.$http({ this.$http({
url: this.$http.adornUrl('/consultComment/deleteCommentById?id='+id), url: this.$http.adornUrl('/consultComment/deleteCommentById?id='+id),
method: 'post', method: 'delete',
data: this.$http.adornData({id: id}) data: this.$http.adornData({id: id})
}).then(({ data }) => { }).then(({ data }) => {
this.$message({ this.$message({
...@@ -149,6 +162,12 @@ export default { ...@@ -149,6 +162,12 @@ export default {
searchChange (params) { searchChange (params) {
this.getDataList(this.page, params) this.getDataList(this.page, params)
} }
},
watch: {
$route(){
this.id = this.$route.query.id
this.refreshChange()
},
} }
} }
</script> </script>
......
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
size="small" size="small"
type="success">禁用</el-tag> type="success">禁用</el-tag>
</template> </template>
<template slot-scope="scope"
slot="view">
<el-button type="text" @click="toComment(scope.row.id)">查看评论</el-button>
</template>
<template slot="menuLeft"> <template slot="menuLeft">
<el-button v-if="isAuth('shop:notice:save')" <el-button v-if="isAuth('shop:notice:save')"
...@@ -94,6 +98,14 @@ export default { ...@@ -94,6 +98,14 @@ export default {
mounted () { mounted () {
}, },
methods: { methods: {
toComment(id){
this.$router.push({
name: 'shop-comments',
query: {
id: id
}
})
},
getDataList (page, params) { getDataList (page, params) {
this.dataListLoading = true this.dataListLoading = true
this.$http({ this.$http({
......
<template> <template>
<div class="mod-user"> <div class="mod-user">
<avue-crud ref="crud" <avue-crud ref="crud"
:page="page" :page="page"
:data="dataList" :data="dataList"
:option="tableOption" :option="tableOption"
@search-change="searchChange" @search-change="searchChange"
@selection-change="selectionChange" @selection-change="selectionChange"
@on-load="getDataList"> @on-load="getDataList">
<template slot="menuLeft"> <template slot="menuLeft">
<el-button type="danger" <el-button type="danger"
@click="deleteHandle()" @click="deleteHandle()"
v-if="isAuth('admin:user:delete')" v-if="isAuth('admin:user:delete')"
size="small" size="small"
:disabled="dataListSelections.length <= 0">批量删除</el-button> :disabled="dataListSelections.length <= 0">批量删除
</template> </el-button>
</template>
<template slot-scope="scope" <template slot-scope="scope"
slot="status"> slot="status">
<el-tag v-if="scope.row.status === 0" <el-tag v-if="scope.row.status === 0"
size="small" size="small"
type="danger">禁用</el-tag> type="danger">禁用
<el-tag v-else </el-tag>
size="small">正常</el-tag> <el-tag v-else
</template> size="small">正常
</el-tag>
</template>
<template slot-scope="scope"
slot="view">
<el-button type="text"
@click.stop="toLowerUser(scope.row.userId)">查看下级
</el-button>
</template>
<template slot-scope="scope"
slot="menu">
<div>
<el-button type="warning"
icon="el-icon-edit"
size="small"
v-if="isAuth('admin:user:update')"
@click.stop="addOrUpdateHandle(scope.row.userId)">编辑
</el-button>
<el-button type="primary"
size="small"
@click.stop="viewBalance(scope.row.userId)">查看余额
</el-button>
</div>
<template slot-scope="scope" <div style="margin: 10px 0">
slot="menu">
<el-button type="primary"
icon="el-icon-edit"
size="small"
v-if="isAuth('admin:user:update')"
@click.stop="addOrUpdateHandle(scope.row.userId)">编辑</el-button>
<el-button type="primary"
icon="el-icon-user"
size="small"
@click.stop="viewBalance(scope.row.userId)">查看余额</el-button>
<el-button type="danger" <el-button type="danger"
icon="el-icon-delete" icon="el-icon-delete"
size="small" size="small"
v-if="isAuth('admin:user:delete')" v-if="isAuth('admin:user:delete')"
@click.stop="deleteHandle(scope.row.userId)">删除</el-button> @click.stop="deleteHandle(scope.row.userId)">删除
</template> </el-button>
</avue-crud> <el-button
type="success"
size="small"
@click.stop="exportEntry(scope.row.userId,scope.row.nickName)">导出下级
</el-button>
</div>
<!-- 弹窗, 新增 / 修改 --> </template>
<add-or-update v-if="addOrUpdateVisible" </avue-crud>
ref="addOrUpdate"
@refreshDataList="getDataList"></add-or-update> <!-- 弹窗, 新增 / 修改 -->
<view-balance v-if="viewBalanceVisible" <add-or-update v-if="addOrUpdateVisible"
ref="viewBalance"></view-balance> ref="addOrUpdate"
</div> @refreshDataList="getDataList"></add-or-update>
<view-balance v-if="viewBalanceVisible"
ref="viewBalance"></view-balance>
<view-lower-user v-if="viewUserVisible" ref="viewLowerUser"></view-lower-user>
</div>
</template> </template>
<script> <script>
import { tableOption } from '@/crud/user/user' import { tableOption } from '@/crud/user/user'
import AddOrUpdate from './user-add-or-update' import AddOrUpdate from './user-add-or-update'
import ViewBalance from './view-balance' import ViewBalance from './view-balance'
import ViewLowerUser from './view-lower-user'
export default { export default {
data () { data () {
return { return {
...@@ -65,6 +89,7 @@ export default { ...@@ -65,6 +89,7 @@ export default {
dataListSelections: [], dataListSelections: [],
addOrUpdateVisible: false, addOrUpdateVisible: false,
viewBalanceVisible: false, viewBalanceVisible: false,
viewUserVisible: false,
tableOption: tableOption, tableOption: tableOption,
page: { page: {
total: 0, // 总页数 total: 0, // 总页数
...@@ -75,7 +100,8 @@ export default { ...@@ -75,7 +100,8 @@ export default {
}, },
components: { components: {
AddOrUpdate, AddOrUpdate,
ViewBalance ViewBalance,
ViewLowerUser
}, },
methods: { methods: {
// 获取数据列表 // 获取数据列表
...@@ -106,12 +132,18 @@ export default { ...@@ -106,12 +132,18 @@ export default {
this.$refs.addOrUpdate.init(id) this.$refs.addOrUpdate.init(id)
}) })
}, },
viewBalance(id){ viewBalance (id) {
this.viewBalanceVisible = true this.viewBalanceVisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.viewBalance.init(id) this.$refs.viewBalance.init(id)
}) })
}, },
toLowerUser (id) {
this.viewUserVisible = true
this.$nextTick(() => {
this.$refs.viewLowerUser.init(id)
})
},
// 删除 // 删除
deleteHandle (id) { deleteHandle (id) {
var ids = id ? [id] : this.dataListSelections.map(item => { var ids = id ? [id] : this.dataListSelections.map(item => {
...@@ -138,7 +170,8 @@ export default { ...@@ -138,7 +170,8 @@ export default {
}) })
}) })
}) })
.catch(() => { }) .catch(() => {
})
}, },
// 条件查询 // 条件查询
searchChange (params) { searchChange (params) {
...@@ -147,6 +180,34 @@ export default { ...@@ -147,6 +180,34 @@ export default {
// 多选变化 // 多选变化
selectionChange (val) { selectionChange (val) {
this.dataListSelections = val this.dataListSelections = val
},
// 导出
exportEntry (id, nickName) {
this.$http({
url: this.$http.adornUrl(`/admin/user/getLowLevelByParentUserId`),
method: 'get',
params: this.$http.adornParams({ parentUserId: id })
}).then(({ data }) => {
let result = data.result
if (result && result.length) {
require.ensure([], () => {
let { exportJsonToExcel } = require('../../../../static/Export2Excel')
// 表头
let tHeader = ['用户昵称', '总佣金(元)', '订单累计购买金额(元)', '累计订单收益金额(元)']
//表头对应字段名,要和下面数据key对应
let filterVal = ['nickName', 'totalCommissionAmount', 'totalOrderAmount', 'totalOrderIncomeAmount']
let data = this.formatJson(filterVal, result) //数据格式化
exportJsonToExcel(tHeader, data, nickName + '下级用户表') //导出文件
})
} else {
this.$message('暂无下级用户')
}
})
},
// 数据格式化
formatJson (filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => v[j]))
} }
} }
} }
......
<template>
<el-dialog title="查看下级"
:close-on-click-modal="false"
:visible.sync="visible">
<el-table
:data="list"
style="width: 100%"
row-key="id"
border
lazy
:load="load"
:tree-props="{children: 'userRelationDTOList', hasChildren: 'hasChildren'}">
<el-table-column
prop="nickName"
label="用户昵称"
>
</el-table-column>
<el-table-column
prop="pic"
label="头像"
width="100"
align="center"
>
<template slot-scope="scope">
<img :src="scope.row.pic" style="width:60px;" alt="">
</template>
</el-table-column>
<el-table-column
prop="totalCommissionAmount"
width="100"
label="总佣金(元)"
align="center">
</el-table-column>
<el-table-column
prop="totalOrderAmount"
label="订单累计购买金额(元)"
width="180"
align="center">
</el-table-column>
<el-table-column
prop="totalOrderIncomeAmount"
label="累计订单收益金额(元)"
width="180"
align="center">
</el-table-column>
</el-table>
<span slot="footer"
class="dialog-footer">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary"
@click="visible = false">确定</el-button>
</span>
</el-dialog>
</template>
<script>
export default {
data () {
return {
list: [],
userId: '',
visible: false,
}
},
methods: {
load (tree, treeNode, resolve) {
this.$http({
url: this.$http.adornUrl(`/admin/user/getLowLevelByParentUserId`),
method: 'get',
params: this.$http.adornParams({ parentUserId: tree.userId })
}).then(({ data }) => {
console.log('下级', data.result)
let list = data.result
if (list && list.length) {
list.forEach(item => {
if (item.userRelationDTOList && item.userRelationDTOList.length) {
item.hasChildren = true
} else {
item.hasChildren = false
}
})
}
resolve(list)
})
},
init (id) {
this.userId = id || 0
this.visible = true
if (this.userId) {
this.$http({
url: this.$http.adornUrl(`/admin/user/getLowLevelByParentUserId`),
method: 'get',
params: this.$http.adornParams({ parentUserId: this.userId })
}).then(({ data }) => {
console.log('下级', data.result)
let list = data.result
if (list && list.length) {
list.forEach(item => {
if (item.userRelationDTOList && item.userRelationDTOList.length) {
item.hasChildren = true
} else {
item.hasChildren = false
}
})
}
this.list = list
})
}
},
// 表单提交
dataFormSubmit () {
this.$refs['dataForm'].validate(valid => {
if (valid) {
this.$http({
url: this.$http.adornUrl(`/admin/user`),
method: this.dataForm.userId ? 'put' : 'post',
data: this.$http.adornData({
userId: this.dataForm.userId || undefined,
nickName: this.dataForm.nickName,
status: this.dataForm.status
})
}).then(({ data }) => {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList', this.page)
}
})
})
}
})
}
}
}
</script>
/* eslint-disable */
/* Blob.js
* A Blob implementation.
* 2014-05-27
*
* By Eli Grey, http://eligrey.com
* By Devin Samarin, https://github.com/eboyjr
* License: X11/MIT
* See LICENSE.md
*/
/*global self, unescape */
/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
plusplus: true */
/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
(function (view) {
"use strict";
view.URL = view.URL || view.webkitURL;
if (view.Blob && view.URL) {
try {
new Blob;
return;
} catch (e) {}
}
// Internally we use a BlobBuilder implementation to base Blob off of
// in order to support older browsers that only have BlobBuilder
var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
var
get_class = function(object) {
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
}
, FakeBlobBuilder = function BlobBuilder() {
this.data = [];
}
, FakeBlob = function Blob(data, type, encoding) {
this.data = data;
this.size = data.length;
this.type = type;
this.encoding = encoding;
}
, FBB_proto = FakeBlobBuilder.prototype
, FB_proto = FakeBlob.prototype
, FileReaderSync = view.FileReaderSync
, FileException = function(type) {
this.code = this[this.name = type];
}
, file_ex_codes = (
"NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
+ "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
).split(" ")
, file_ex_code = file_ex_codes.length
, real_URL = view.URL || view.webkitURL || view
, real_create_object_URL = real_URL.createObjectURL
, real_revoke_object_URL = real_URL.revokeObjectURL
, URL = real_URL
, btoa = view.btoa
, atob = view.atob
, ArrayBuffer = view.ArrayBuffer
, Uint8Array = view.Uint8Array
;
FakeBlob.fake = FB_proto.fake = true;
while (file_ex_code--) {
FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
}
if (!real_URL.createObjectURL) {
URL = view.URL = {};
}
URL.createObjectURL = function(blob) {
var
type = blob.type
, data_URI_header
;
if (type === null) {
type = "application/octet-stream";
}
if (blob instanceof FakeBlob) {
data_URI_header = "data:" + type;
if (blob.encoding === "base64") {
return data_URI_header + ";base64," + blob.data;
} else if (blob.encoding === "URI") {
return data_URI_header + "," + decodeURIComponent(blob.data);
} if (btoa) {
return data_URI_header + ";base64," + btoa(blob.data);
} else {
return data_URI_header + "," + encodeURIComponent(blob.data);
}
} else if (real_create_object_URL) {
return real_create_object_URL.call(real_URL, blob);
}
};
URL.revokeObjectURL = function(object_URL) {
if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
real_revoke_object_URL.call(real_URL, object_URL);
}
};
FBB_proto.append = function(data/*, endings*/) {
var bb = this.data;
// decode data to a binary string
if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
var
str = ""
, buf = new Uint8Array(data)
, i = 0
, buf_len = buf.length
;
for (; i < buf_len; i++) {
str += String.fromCharCode(buf[i]);
}
bb.push(str);
} else if (get_class(data) === "Blob" || get_class(data) === "File") {
if (FileReaderSync) {
var fr = new FileReaderSync;
bb.push(fr.readAsBinaryString(data));
} else {
// async FileReader won't work as BlobBuilder is sync
throw new FileException("NOT_READABLE_ERR");
}
} else if (data instanceof FakeBlob) {
if (data.encoding === "base64" && atob) {
bb.push(atob(data.data));
} else if (data.encoding === "URI") {
bb.push(decodeURIComponent(data.data));
} else if (data.encoding === "raw") {
bb.push(data.data);
}
} else {
if (typeof data !== "string") {
data += ""; // convert unsupported types to strings
}
// decode UTF-16 to binary string
bb.push(unescape(encodeURIComponent(data)));
}
};
FBB_proto.getBlob = function(type) {
if (!arguments.length) {
type = null;
}
return new FakeBlob(this.data.join(""), type, "raw");
};
FBB_proto.toString = function() {
return "[object BlobBuilder]";
};
FB_proto.slice = function(start, end, type) {
var args = arguments.length;
if (args < 3) {
type = null;
}
return new FakeBlob(
this.data.slice(start, args > 1 ? end : this.data.length)
, type
, this.encoding
);
};
FB_proto.toString = function() {
return "[object Blob]";
};
FB_proto.close = function() {
this.size = this.data.length = 0;
};
return FakeBlobBuilder;
}(view));
view.Blob = function Blob(blobParts, options) {
var type = options ? (options.type || "") : "";
var builder = new BlobBuilder();
if (blobParts) {
for (var i = 0, len = blobParts.length; i < len; i++) {
builder.append(blobParts[i]);
}
}
return builder.getBlob(type);
};
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
/* eslint-disable */
require('script-loader!file-saver');
require('./Blod');
require('script-loader!xlsx/dist/xlsx.core.min');
function generateArray(table) {
var out = [];
var rows = table.querySelectorAll('tr');
var ranges = [];
for (var R = 0; R < rows.length; ++R) {
var outRow = [];
var row = rows[R];
var columns = row.querySelectorAll('td');
for (var C = 0; C < columns.length; ++C) {
var cell = columns[C];
var colspan = cell.getAttribute('colspan');
var rowspan = cell.getAttribute('rowspan');
var cellValue = cell.innerText;
if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue;
//Skip ranges
ranges.forEach(function (range) {
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);
}
});
//Handle Row Span
if (rowspan || colspan) {
rowspan = rowspan || 1;
colspan = colspan || 1;
ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}});
}
;
//Handle Value
outRow.push(cellValue !== "" ? cellValue : null);
//Handle Colspan
if (colspan) for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
}
out.push(outRow);
}
return [out, ranges];
};
function datenum(v, date1904) {
if (date1904) v += 1462;
var 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) {
var ws = {};
var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
for (var R = 0; R != data.length; ++R) {
for (var C = 0; C != data[R].length; ++C) {
if (range.s.r > R) range.s.r = R;
if (range.s.c > C) range.s.c = C;
if (range.e.r < R) range.e.r = R;
if (range.e.c < C) range.e.c = C;
var cell = {v: data[R][C]};
if (cell.v == null) continue;
var cell_ref = XLSX.utils.encode_cell({c: C, r: R});
if (typeof cell.v === 'number') cell.t = 'n';
else if (typeof cell.v === 'boolean') cell.t = 'b';
else if (cell.v instanceof Date) {
cell.t = 'n';
cell.z = XLSX.SSF._table[14];
cell.v = datenum(cell.v);
}
else cell.t = 's';
ws[cell_ref] = cell;
}
}
if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range);
return ws;
}
function Workbook() {
if (!(this instanceof Workbook)) return new Workbook();
this.SheetNames = [];
this.Sheets = {};
}
function s2ab(s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
}
export function export_table_to_excel(id) {
var theTable = document.getElementById(id);
console.log('a')
var oo = generateArray(theTable);
var ranges = oo[1];
/* original data */
var data = oo[0];
var ws_name = "SheetJS";
console.log(data);
var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
/* add ranges to worksheet */
// ws['!cols'] = ['apple', 'banan'];
ws['!merges'] = ranges;
/* add worksheet to workbook */
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx")
}
function formatJson(jsonData) {
console.log(jsonData)
}
export function exportJsonToExcel(th, jsonData, defaultTitle) {
/* original data */
var data = jsonData;
data.unshift(th);
var ws_name = "SheetJS";
var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
/* add worksheet to workbook */
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
var title = defaultTitle || '列表'
saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment