1 Star 0 Fork 47

davylau/tms-frontend

forked from 团购商城/tms-frontend 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sheet.html 30.90 KB
一键复制 编辑 原始数据 按行查看 历史
团购商城 提交于 2021-09-28 19:41 . Update sheet.html
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
<!DOCTYPE html>
<html lang = "zh">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta content='tms,chat,wiki,translation,blog,markdown,group,team,teamwork,聊天,沟通,知识库,博文,国际化翻译,团队协作' name='Keywords'>
<meta content='TMS是免费开源的团队协作(团队沟通,博文知识库,国际化翻译i18n)web系统(响应式界面设计,移动端适配).' name='Description'>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<title>TMS博文</title>
<!-- Include CSS for icons. -->
<!-- <link href="cdn/font-awesome.min.css" rel="stylesheet" type="text/css" /> -->
<link href="cdn/toastr.min.css" rel="stylesheet" type="text/css" />
<!-- jQuery Modal -->
<link href="cdn/jquery.modal.min.css" rel="stylesheet" type="text/css" />
<link rel='stylesheet' href='cdn/luckysheet/plugins/css/pluginsCss.css' />
<link rel='stylesheet' href='cdn/luckysheet/plugins/plugins.css' />
<link rel='stylesheet' href='cdn/luckysheet/css/luckysheet.css' />
<link rel='stylesheet' href='cdn/luckysheet/assets/iconfont/iconfont.css' />
<!-- <link rel='stylesheet' href='cdn/luckysheet/expendPlugins/chart/chartmix.css' /> -->
<style>
body {
margin: 0;
overflow: hidden;
}
.blocker {
z-index: 999;
}
div#editor {
width: 100%;
position: relative;
height: 100vh;
}
.sheet-container {
height: calc(100% - 70px);
overflow: auto;
}
.readonly .sheet-container {
height: 100%;
}
#sheet {
height: 100%;
position: relative;
}
#sheet>.x-spreadsheet {
height: 100% !important;
}
#toast-container {
z-index: 9999999999 !important;
}
.topbar {
padding: 16px;
height: 38px;
}
.readonly .topbar {
display: none;
}
.topbar>input {
width: 400px;
font-size: 26px;
box-sizing: border-box;
outline: 0;
border: 0;
box-shadow: 0px 1px 0px 0px #dddddd;
padding-right: 80px;
}
.topbar>button {
font-size: 12px;
}
button.btn {
color: #fff;
background: #2185d0;
padding: .5rem 1rem;
display: inline-block;
border-radius: 4px;
transition-duration: .25s;
border: none;
font-size: 14px;
}
#import {
color: #fff;
background: #00aaff;
padding: .25rem .5rem;
display: inline-block;
border-radius: 4px;
transition-duration: .25s;
border: none;
font-size: 14px;
}
@media only screen and (max-width: 767px) {
.topbar>input {
width: 250px;
}
#import {
display: none;
}
}
button.btn:hover {
background: #1678c2;
}
#saveFrm .row {
padding-bottom: 8px;
}
#saveFrm label {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#saveFrm select {
background: #fafdfe;
height: 28px;
width: 440px;
margin-top: 3px;
line-height: 28px;
border: 1px solid #9bc0dd;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
}
</style>
</head>
<body>
<div id="editor" class="readonly">
<div class="topbar">
<input id="title" type="text" placeholder="标题">
<button class="button -blue btn" id="save">保存</button>
<span id="msg" style="color: red; padding-left: 16px;"></span>
<div style="display: inline-block;">
<input type="file" accept=".sheet,.xlsx" id="files" style="display:none" onchange="importHandler();" />
<input type="button" id="import" value="导入" />
</div>
</div>
<div class="sheet-container">
<div id='sheet'></div>
</div>
</div>
<!-- Modal HTML embedded directly into document -->
<div id="saveModal" class="modal">
<div id="saveFrm" style="padding-top: 16px;">
<div class="row">
<label>选择空间</label>
<select name="space"></select>
</div>
<div class="row">
<label>选择分类</label>
<select name="dir"></select>
</div>
<div class="row">
<input id="privated" type="checkbox">
<label for="privated">私有博文(不公开)</label>
</div>
<div class="row" style="padding-top: 16px;">
<button class="btnOk btn">确定</button>
</div>
</div>
</div>
<!-- <p><a href="#saveModal" rel="modal:open">Open Modal</a></p> -->
<!-- Include jQuery lib. -->
<script type="text/javascript" src="cdn/jquery.min.js"></script>
<script type="text/javascript" src="cdn/toastr.min.js"></script>
<script type="text/javascript" src="cdn/url.min.js"></script>
<script type="text/javascript" src="cdn/lodash.core.min.js"></script>
<script type="text/javascript" src="cdn/sockjs.min.js"></script>
<script type="text/javascript" src="cdn/stomp.min.js"></script>
<script type="text/javascript" src="cdn/luckysheet/plugins/js/plugin.js"></script>
<script type="text/javascript" src="cdn/luckysheet/luckysheet.umd.js"></script>
<script type="text/javascript" src="cdn/luckysheet/luckyexcel.umd.js"></script>
<!-- <script type="text/javascript" src="cdn/luckysheet/expendPlugins/chart/chartmix.umd.min.js"></script> -->
<script type="text/javascript" src="cdn/jquery.modal.min.js"></script>
<script>
function initSheet(data) {
// console.log(data);
var readonly = typeof url('?readonly') !== 'undefined';
if ($('#sheet').length == 0) return;
try {
//配置项
var options = {
container: 'sheet', //luckysheet为容器id
showinfobar: false,
showtoolbar: !readonly,
showtoolbarConfig: {
image: false,
print: false
},
showsheetbar: true,
showsheetbarConfig: {
add: !readonly, //新增sheet
menu: true, //sheet管理菜单
sheet: true //sheet页显示
},
showstatisticBar: !readonly,
sheetFormulaBar: !readonly,
enableAddRow: !readonly,
enableAddBackTop: !readonly,
lang: 'zh',
plugins: ['chart'],
data: !!data ? data : null
};
if (window.luckysheet) {
luckysheet.destroy();
luckysheet.create(options);
}
} catch (err) {
console.warn(err);
}
}
$("#import").click(function () { //点击导入按钮,使files触发点击事件,然后完成读取文件的操作。
$("#files").click();
});
function importHandler() {
var selectedFile = document.getElementById("files").files[0]; //获取读取的File对象
var name = selectedFile.name; //读取选中文件的文件名
// var type = selectedFile.type;
// var size = selectedFile.size; //读取选中文件的大小
// console.log("文件名:" + name + "大小:" + size);
var index = _.lastIndexOf(name, ".");
var title = name.substring(0, index);
$('#title').val(title);
try {
if (_.endsWith(name, ".sheet")) {
var reader = new FileReader(); //这里是核心!!!读取操作就是由它完成的。
reader.readAsText(selectedFile); //读取文件的内容
reader.onload = function () {
try {
initSheet(JSON.parse(this.result));
} catch (err) {
alert(err);
}
};
} else {
LuckyExcel.transformExcelToLucky(selectedFile, function (exportJson, luckysheetfile) {
if (exportJson.sheets == null || exportJson.sheets.length == 0) {
alert(
"Failed to read the content of the excel file, currently does not support xls files!"
);
return;
}
// console.log(exportJson, luckysheetfile);
initSheet(exportJson.sheets);
});
}
} catch (err) {
alert(err);
}
}
function getAllSheets() {
// return JSON.stringify(luckysheet.getAllSheets());
// let ls = luckysheet.getLuckysheetfile()
let ls = luckysheet.getAllSheets();
ls.forEach((item, index) => {
if (item.chart) {
item.chart.forEach((chart, i) => {
var chart2 = _.clone(ls[index].chart[i]);
var co = {
chart_id: chart.chart_id
};
try {
co = chartmix.default.getChartJson(chart.chart_id);
} catch (error) {
console.log(error);
}
chart2.chartOptions = _.clone(co);
ls[index].chart[i] = chart2;
let div = document.getElementById(chart.chart_id + '_c');
if (div && div.style) {
ls[index].chart[i].left = parseInt(div.style.left)
ls[index].chart[i].top = parseInt(div.style.top)
ls[index].chart[i].width = parseInt(div.style.width)
ls[index].chart[i].height = parseInt(div.style.height)
}
})
}
});
return JSON.stringify(ls)
}
$(function () {
var isComment = typeof url('?comment') !== 'undefined';
var id = url('?id');
var cid = url('?cid');
var spaceId = url('?spaceId');
var dirId = url('?dirId');
var pid = url('?pid');
var readonly = typeof url('?readonly') !== 'undefined';
!readonly && $('#editor').removeClass('readonly');
var blog = null;
var comment = null;
// toastr弹出消息提示插件全局配置设置
toastr.options.positionClass = 'toast-bottom-center';
toastr.options.preventDuplicates = true;
if (isComment) { // comment
$('#title').hide();
if (cid) {
var isFree = typeof url('?free') !== 'undefined';
if (isFree) {
$.get('/free/blog/comment/' + cid, {}, function (data) {
if (data.success) {
comment = data.data;
initSheet(JSON.parse(data.data.content));
} else {
toastr.error(data.data);
}
});
} else {
$.get('/admin/blog/comment/get', {
cid: cid
}, function (data) {
if (data.success) {
comment = data.data;
initSheet(JSON.parse(data.data.content))
} else {
toastr.error(data.data);
}
});
}
} else {
initSheet();
}
$('#save').click(function (event) {
var content = getAllSheets();
// console.log(content);
if (!content || !$.trim(content)) {
toastr && toastr.error('博文评论内容不能为空!');
return;
}
if (comment == null) {
$.post('/admin/blog/comment/create', {
basePath: window.location.protocol + '//' + window.location.host +
'/page/index.html',
id: id,
editor: 'Sheet',
content: content
}, function (data, textStatus, xhr) {
if (data.success) {
comment = data.data;
toastr && toastr.success('博文评论保存成功!');
(window.parent && window.parent.postMessage) && (window.parent
.postMessage({
action: 'created',
source: 'comment',
comment: data.data,
editor: 'sheet'
}, window.location.origin));
} else {
toastr && toastr.error(data.data);
}
}).fail(function () {
toastr && toastr.error('网络传输错误!');
});
} else {
$.post('/admin/blog/comment/update', {
basePath: window.location.protocol + '//' + window.location.host +
'/page/index.html',
id: id,
cid: cid,
version: comment.version,
content: content
}, function (data, textStatus, xhr) {
if (data.success) {
comment = data.data;
toastr && toastr.success('博文评论保存成功!');
(window.parent && window.parent.postMessage) && (window.parent
.postMessage({
action: 'updated',
source: 'comment',
comment: data.data,
editor: 'sheet'
}, window.location.origin));
} else {
toastr && toastr.error(data.data);
}
}).fail(function () {
toastr && toastr.error('网络传输错误!');
});
}
});
window.addEventListener && window.addEventListener('message', (evt) => {
if (evt.origin != window.location.origin) return;
if (evt.data.source != 'blogClose') return;
if (evt.data.action == 'isUpdated') {
var updated = false;
var title = $('#title').val();
var content = getAllSheets();
// console.log(content);
if (comment) {
updated = (comment.content != content);
} else {
updated = (!!$.trim(content) && content !=
``
);
}
(window.parent && window.parent.postMessage) && (window.parent
.postMessage({
action: 'isUpdated',
source: 'blogCloseAck',
item: evt.data.item,
updated: updated
}, window.location.origin));
}
}, false);
} else { // blog
if (id) {
if (typeof url('?free') === 'undefined') {
$.get('/admin/blog/get', {
id: id,
inc: false
}, function (data) {
if (data.success) {
if (typeof url('?copy') === 'undefined') { // edit
blog = data.data;
$('#title').val(data.data.title);
if (!readonly) {
window.stompClient = Stomp.over(new SockJS('/ws-lock?blogId=' +
blog
.id));
window.stompClient.debug = function () {};
// this.stompClient.debug = function (msg) { console.log(msg) };
window.stompClient.connect({}, function (frame) {}, function (
err) {
console.error(err);
});
}
} else {
$('#title').val(data.data.title + ' (副本)');
}
initSheet(JSON.parse(data.data.content))
} else {
toastr.error(data.data);
}
});
} else {
var shareId = url('?shareId');
// console.log('shareId: ' + shareId);
if (shareId && shareId != '') {
$.get('/free/blog/share/' + shareId, {
_: new Date().getTime(),
inc: false
}, function (data) {
if (data.success) {
if (typeof url('?copy') === 'undefined') { // edit
blog = data.data;
$('#title').val(data.data.title);
} else {
$('#title').val(data.data.title + ' (副本)');
}
initSheet(JSON.parse(data.data.content))
} else {
toastr.error(data.data);
}
});
} else {
$.get('/free/home/blog/' + id, {
_: new Date().getTime(),
inc: false
}, function (data) {
if (data.success) {
if (typeof url('?copy') === 'undefined') { // edit
blog = data.data.blog;
$('#title').val(data.data.blog.title);
} else {
$('#title').val(data.data.blog.title + ' (副本)');
}
initSheet(JSON.parse(data.data.blog.content))
} else {
toastr.error(data.data);
}
});
}
}
} else {
initSheet();
}
// 博文保存选择,空间 + 分类
var spaces = [];
$('#saveFrm select[name="space"]').change(function (event) {
var sid = $(this).val();
$('#saveFrm select[name="dir"]').empty().append($('<option/>').text('(不指定分类)').attr(
'value', ''));
if (sid !== '') {
$.each(spaces, function (index, space) {
if (space.id == sid) {
window._ && (space.dirs = _.sortBy(space.dirs, 'name'));
$.each(space.dirs, function (index, dir) {
if (dir.status != 'Deleted') {
$('#saveFrm select[name="dir"]').append($(
'<option/>').text(dir.name).attr(
'value', dir.id));
}
});
var did = localStorage && localStorage.getItem(
'tms-blog-html-dir');
if (_.some(space.dirs, {
id: +did
})) {
$('#saveFrm select[name="dir"]').val(did);
}
return false;
}
});
}
});
window.addEventListener && window.addEventListener('message', (evt) => {
if (evt.origin != window.location.origin) return;
if (evt.data.source != 'blogClose') return;
if (evt.data.action == 'isUpdated') {
var updated = false;
var title = $('#title').val();
var content = getAllSheets();
if (blog) {
updated = (blog.title != title) || (blog.content != content);
} else {
updated = !!$.trim(title) || (!!$.trim(content) && content !=
``
);
}
(window.parent && window.parent.postMessage) && (window.parent
.postMessage({
action: 'isUpdated',
source: 'blogCloseAck',
item: evt.data.item,
updated: updated
}, window.location.origin));
}
}, false);
$('#save').click(function (event) {
var title = $('#title').val();
var content = getAllSheets();
// console.log(content);
if (!title || !$.trim(title)) {
toastr && toastr.error('博文标题不能为空!');
return;
}
if (!content || !$.trim(content)) {
toastr && toastr.error('博文内容不能为空!');
return;
}
if (blog == null) {
if (spaceId || pid) {
createBlog(spaceId, dirId, pid);
} else {
$.get('/admin/space/listMy', function (data) {
if (data.success) {
spaces = data.data;
$('#saveFrm select[name="space"]').empty().append($(
'<option/>')
.text('(不指定空间)').attr('value', ''));
$('#saveFrm select[name="dir"]').empty().append($(
'<option/>')
.text(
'(不指定分类)').attr('value', ''));
window._ && (spaces = _.sortBy(spaces, 'name'));
$.each(spaces, function (index, space) {
$('#saveFrm select[name="space"]').append($(
'<option/>')
.text(space.name).attr('value', space
.id));
});
var sid = localStorage && localStorage.getItem(
'tms-blog-html-space');
if (_.some(spaces, {
id: +sid
})) {
$('#saveFrm select[name="space"]').val(sid);
$('#saveFrm select[name="space"]').change();
}
var privated = localStorage && localStorage.getItem(
'tms-blog-html-privated');
$('#privated').prop("checked", privated == 'true');
$('#saveModal').modal({
fadeDuration: 200,
clickClose: false
});
}
});
}
} else {
$.post('/admin/blog/update', {
url: window.location.protocol + '//' + window.location.host +
'/page/index.html',
id: blog.id,
version: blog.version,
title: title,
content: content
}, function (data, textStatus, xhr) {
if (data.success) {
blog = data.data;
toastr && toastr.success('博文更新成功!');
(window.parent && window.parent.postMessage) && (window.parent
.postMessage({
action: 'updated',
autoFollow: true,
source: 'blog',
blog: data.data
}, window.location.origin));
} else {
toastr && toastr.error(data.data);
}
}).fail(function () {
toastr && toastr.error('网络传输错误!');
});
}
});
$('#saveFrm .btnOk').click(function (event) {
createBlog();
});
}
function createBlog(spaceId, dirId, pid) {
var title = $('#title').val();
var content = getAllSheets();
if (!title || !$.trim(title)) {
toastr && toastr.error('博文标题不能为空!');
return;
}
if (!content || !$.trim(content)) {
toastr && toastr.error('博文内容不能为空!');
return;
}
if (blog == null) {
if (!spaceId && !pid) {
$.modal.close();
localStorage && localStorage.setItem('tms-blog-html-space', $(
'#saveFrm select[name="space"]').val());
localStorage && localStorage.setItem('tms-blog-html-dir', $(
'#saveFrm select[name="dir"]').val());
localStorage && localStorage.setItem('tms-blog-html-privated', $('#privated')
.prop(
"checked"));
}
$.post('/admin/blog/create', {
url: window.location.protocol + '//' + window.location.host +
'/page/index.html',
spaceId: spaceId ? spaceId : $('#saveFrm select[name="space"]').val(),
dirId: dirId ? dirId : (spaceId ? '' : $('#saveFrm select[name="dir"]').val()),
pid: pid ? pid : '',
title: title,
content: content,
editor: 'Sheet',
privated: spaceId ? false : $('#privated').prop("checked"),
contentHtml: content
}, function (data, textStatus, xhr) {
if (data.success) {
blog = data.data;
toastr && toastr.success('博文保存成功!');
$('#preview').show();
(window.parent && window.parent.postMessage) && (window.parent
.postMessage({
action: 'created',
source: 'blog',
blog: data.data,
editor: 'sheet'
}, window.location.origin));
} else {
toastr && toastr.error(data.data);
}
}).fail(function () {
toastr && toastr.error('网络传输错误!');
});
}
}
});
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/laudavy/tms-frontend.git
git@gitee.com:laudavy/tms-frontend.git
laudavy
tms-frontend
tms-frontend
master

搜索帮助