123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- Namespace.register("U.MD.O.W.SP");
- U.MD.O.W.SP.FILEINFO = null;
- window.onload = function () {
- //加载1473数据
- U.UF.CD.loadPageCrossDomain(function () {
- });
- //获取站点信息
- U.MD.O.W.SP.sitePreviewInit();
- U.MD.O.W.SP.LoadDiskDate();
- if (window.location.hash) {//如果是长链接则显示域名设置提示
- $(".U_MD_O_W_SP_Fixed_dnReset")[0].style.display = "block";
- } else {
- $(".U_MD_O_W_SP_Fixed_dnReset")[0].style.display = "none";
- $('.U_MD_O_W_SP_ToolsBar')[0].style.display = "block";
- }
- }
- /**
- * 网站预览初始化
- */
- U.MD.O.W.SP.sitePreviewInit = function () {
- var _pathname = window.location.pathname, //获取网站地址
- _domename = U.UF.C.queryString("fid") || _pathname.split("/")[1]; //进行域名分离
- //获取网页内容
- if (_domename) {
- U.A.Request("http://cd.1473.cn/php", ["db.1473.cn", "UseStudio_DNS", "GetFileIdToDomain", _domename], function (r) { //获取文件信息
- var _value = r.value
- U.MD.O.W.SP.uwOpen(_value[0].FileId); //进入获取文档信息
- U.MD.O.W.SP.initReply(); //加载评论系统
- //console.log(window.location.hash);
- //console.log(U.MD.O.W.SP.FILEINFO.UserID);
- //console.log(US.userInfo.userid);
- /*if (window.location.hash) {
- $(".U_MD_O_W_SP_Fixed_dnReset")[0].style.display = "block";
- } else {
- $(".U_MD_O_W_SP_Fixed_dnReset")[0].style.display = "none";
- }*/
- });
- }
- }
- /**
- * 获取uw文件数据
- *
- * @fileid {string} 文档id
- */
- U.MD.O.W.SP.uwOpen = function (fileid) {
- //通过文档id获取文档信息
- U.A.Request(US.CD, [US.DB, "UseStudio_Disk", "GetFileById", fileid], function (r) {
- r = r.value;
- // if (r[0].UsOffice.indexOf("?") > -1) {
- // alert('str中包含bc字符串');
- // }
- // r[0].UsOffice = r[0].UsOffice.replace("<span>?</span>", "");
- // r[0].UsOffice = r[0].UsOffice.replace("<span>?</span>", "");
- console.log(r[0].UsOffice);
- if (r[0]) {
- //设置全局变量
- U.MD.O.W.SP.FILEINFO = r[0];
- //有内容直接加载内容
- if (r[0].UsOffice !== undefined && r[0].UsOffice != null) {
- U.MD.O.W.SP.uwOpen.asyn(r[0]);
- }
- //如果没有内容则去office下载内容
- else if (['doc', 'docx'].indexOf(r[0].UserFilesExtendName.toLocaleLowerCase()) > -1) {
- //初始化内容处理
- U.A.Request("http://office.1473.cn/Officetohtml.ashx", ["Open", r[0].UserFilesExtendName, r[0].UserFilesServerName], function (r) {
- var _fileinfo = r.context[1]; //获取文档信息
- if (r.value != undefined) {
- //设置文档内容
- r = r.value;
- _fileinfo.UsOffice = r.value.getBodyHtml().replace(/src=[\'\"]?([^\'\"]*)[\'\"]?/ig, function (str1, str2) {
- return "src=\"http://office.1473.cn/usoffice/" + str2 + "\"";
- });
- //加载文档信息
- U.MD.O.W.SP.uwOpen.asyn(_fileinfo);
- }
- else {
- U.Alert("文档已丢失。。。");
- }
- }, [null, r[0]]);
- }
- else {
- U.Alert("该文件无法打开");
- }
- }
- else {
- U.Alert("文档已丢失。。。");
- }
- });
- }
- /**
- * 获取uw文件数据
- *
- * @fileid {string} 文档id
- */
- U.MD.O.W.SP.uwOpen.asyn = function (fileinfo) {
- //判断_value.UsOffice是否为null
- if (!fileinfo.UsOffice && typeof (fileinfo.UsOffice) != "undefined" && fileinfo.UsOffice != 0) {
- fileinfo.UsOffice = " "; //显示为空
- }
- //导航模式的处理
- if (fileinfo.UserFilesExtendName.toLowerCase() == 'un') {
- $('body').addClass('U_MD_O_W_SP_Nav');
- $('.U_MD_O_W_SP_Head_Main_Logo span')[0].innerText = fileinfo.UserFilesName;
- U.MD.O.W.SP.modelDataCreate(fileinfo);
- }
- //普通模式的处理
- else {
- $('.U_MD_O_W_SP_Head')[0].style.display = 'block'; //显示元素
- $('.U_MD_O_W_SP_Tool')[0].style.display = 'block'; //显示元素
- $("#U_MD_O_W_SP_Editor")[0].innerHTML = fileinfo.UsOffice.unEscapeQuotes(); //文档内容格式化
- var _len = $("#U_MD_O_W_SP_Editor")[0].childNodes[0].children.length;
- for (var i = 0; i < _len; i++) {
- if ($("#U_MD_O_W_SP_Editor")[0].childNodes[0].children[i].innerText === "?") {
- $("#U_MD_O_W_SP_Editor")[0].childNodes[0].children[i].innerText = '';
- }
- else if ($("#U_MD_O_W_SP_Editor")[0].childNodes[0].children[i].innerText === " ") {
- $("#U_MD_O_W_SP_Editor")[0].childNodes[0].children[i].innerText = '';
- }
- }
- $(".U_MD_O_W_SP_Title")[0].innerText = fileinfo.UserFilesName; //文档名
- U.MD.O.W.SP.bindInit(fileinfo); //进入事件绑定
- }
- $$("meta", { name: "title", content: fileinfo.UserFilesName }, $('head')[0]);
- U.MD.O.W.SP.backTop();
- $('.U_MD_O_W_SP_ToolsBar')[0].onclick = function () {
- U.MD.O.W.SP.isLogin(fileinfo);
- }
- $('#U_MD_O_W_SP_Editor').bind('click', function (event) { U.MD.O.W.SP.pictureClick(event) }); //设置图片点击
- $('.U_MD_O_W_SP_Content').bind('mousedown', U.UF.EV.stopBubble); //阻止层级冒泡
- }
- U.MD.O.W.SP.eidtor = function (fileinfo) {
- if (US.userInfo.userid == fileinfo.UserID || (Guid.IsGuid(fileinfo.UserDirectoryEncrypt) && U.Json.select(US.friend.group, { GroupManageID: fileinfo.UserDirectoryEncrypt })[0])) {
- var _fileinfo = {
- UserId: fileinfo.UserID,
- GroupID: fileinfo.UserDirectoryEncrypt,
- UserDirectoryID: fileinfo.UserFilesID,
- UserallDirectoryName: fileinfo.UserFilesName,
- UserDirectoryExtendType: fileinfo.UserFilesExtendName
- }
- U.MD.O.word(US.userInfo, _fileinfo);
- } else {
- U.Alert("无编辑权限");
- }
- }
- U.MD.O.W.SP.isLogin = function (fileinfo) {
- if (!US.userInfo.userid) {
- U.MD.U.L.login(function () { U.MD.O.W.SP.eidtor(fileinfo) });
- } else {
- U.MD.O.W.SP.eidtor(fileinfo)
- }
- }
- /**
- * 文档模板生成
- * 把你的代码放在这个函数里面
- */
- U.MD.O.W.SP.modelDataCreate = function (fileinfo) {
- var _li, data = JSON.parse(fileinfo.UsOffice); //字符串转换为JSON对象
- for (var i = 0; i < data.nav.length; i++) { //循环数据
- _li = i == 0 ? $$("li", { innerHTML: data.nav[i].name, className: 'DataLi_active' }, $(".U_MD_O_W_SP_Header_DataUl")[0]) : $$("li", { innerHTML: data.nav[i].name }, $(".U_MD_O_W_SP_Header_DataUl")[0]); //创建li元素
- //初始化导航的处理
- _li.onclick = U.UF.C.closure(function (i) { //绑定点击事件
- //根据导航获取信息
- U.A.Request(US.CD, [US.DB, "UseStudio_Office", "GetNavPageContent", data.nav[i].pageId], function (r) { //请求数据库获取值
- var _el = $('#U_MD_O_W_SP_Editor')[0], //获取输出元素
- _listLi = $('.U_MD_O_W_SP_Header_DataUl').find('.DataLi_active'); //获取选中元素
- //有选中的元素 然后 清空class
- if (_listLi.length) {
- (_listLi[0].className = '');
- }
- $('.U_MD_O_W_SP_Header_DataUl').find('li')[i].className = 'DataLi_active'; //给点击的元素的class加
- _el.innerHTML = r.value[0].content.unEscapeQuotes(); //对数据过滤然后输出
- });
- }, [i]);
- //点击第一个元素
- if (i == 0) {
- _li.click();
- }
- }
- }
- /**
- * 事件绑定
- *
- * @fileinfo {object} 文档信息
- */
- U.MD.O.W.SP.bindInit = function (fileinfo) {
- var _shareEl = $('#U_MD_O_W_SP_Tool_ShareBtn')[0], //分享按钮
- _saveEl = $('#U_MD_O_W_SP_Tool_SaveBtn')[0], //保存到我的云盘按钮
- _showShareEl = U.MD.O.W.SP.shareFile(fileinfo, _shareEl), //打印分享的布局并返回户元素
- _winWidth;
- _saveEl.onclick = function () {
- U.MD.O.W.SP.saveSpecifiedFolder(fileinfo);
- }
- }
- /**
- * 事件绑定
- *
- * @fileinfo {object} 文档信息
- */
- U.MD.O.W.SP.backTop = function () {
- var _container = $('.U_MD_O_W_SP_ToolsBar_Container'),
- _topEl = $('.U_MD_O_W_SP_Top_Icon')[0], //滚动置顶按钮
- _winScrollTop, _clientheight;
- window.onscroll = function () {
- _winScrollTop = document.documentElement.scrollTop; //浏览器窗口到顶部的距离
- _clientheight = document.documentElement.clientHeight;
- if (_winScrollTop >= 100) { //距离大于等于100px显示按钮
- if (_topEl.style.display == 'none') //隐藏
- _topEl.style.display = 'block'; //显示
- // _topEl.style.top = document.body.clientHeight + _winScrollTop - 200 + 'px'; //显示位置
- } else if (_winScrollTop < 100 && _topEl.style.display == 'block') { //显示
- _topEl.style.display = 'none'; //隐藏
- }
- if (_clientheight + _winScrollTop >= _container[0].offsetTop + _container[1].offsetHeight) {
- //_container.css('position', 'relative', 1);
- _container.css('position', 'fixed', 1);
- } else {
- _container.css('position', 'fixed', 1);
- }
- }
- window.onscroll();
- // $(window).bind({ scroll: function () {
- // })
- _topEl.onclick = function () {
- U.MD.O.W.SP.topAnimate(document.documentElement, 0)
- }
- }
- /**
- * 置顶动画
- *
- * @ele {element} 移动元素
- * @target {number} 目标点
- */
- U.MD.O.W.SP.topAnimate = function (ele, target) {
- clearInterval(ele.timer); //清楚历史定时器
- ele.timer = setInterval(function () {
- //获取步长 确定移动方向(正负值) 步长应该是越来越小的,缓动的算法。
- var step = (target - ele.scrollTop) / 10;
- //对步长进行二次加工(大于0向上取整,小于0项下取整)
- step = step > 0 ? Math.ceil(step) : Math.floor(step);
- //动画原理: 目标位置 = 当前位置 + 步长
- ele.scrollTop = ele.scrollTop + step;
- //检测缓动动画有没有停止
- if (Math.abs(target - ele.scrollTop) <= Math.abs(step)) {
- ele.scrollTop = target; //直接移动指定位置
- clearInterval(ele.timer);
- }
- }, 16);
- }
- /**
- * 分享功能
- *
- * @fileInfo {object} 文档信息
- * @parentel {element} 添加的元素
- */
- U.MD.O.W.SP.shareFile = function (fileinfo, parentel) {
- var _content = $$('div', { className: "U_MD_O_W_SP_ShareBox" }), //创建最外层元素
- _shareTitle = $$('div', { className: "U_MD_O_W_SP_ShareTitle" }, _content), //分享小标题
- _shareBorder = $$('div', { className: "U_MD_O_W_SP_ShareBorder" }, _content), //分割线
- _wechat = $$('div', { className: "shareBlock" }, _content), //微信好友分享按钮
- _qq = _wechat.cloneNode(), //克隆元素
- _xin = _wechat.cloneNode(); //克隆元素
- $$('span', { innerText: "分享" }, _shareTitle); //创建文字
- $$('img', { src: "/img/xinlangRed.png", style: { width: '24px'} }, _xin); //创建图片
- $$('img', { src: "/img/qq.png", style: { width: '24px'} }, _qq); //创建图片
- $$('img', { src: "/img/wechat.png", style: { width: '24px'} }, _wechat); //创建图片
- $$('div', { innerText: "新浪微博" }, _xin); //创建文字
- $$('div', { innerText: "微信好友" }, _wechat); //创建文字
- $$('div', { innerText: "QQ好友" }, _qq); //创建文字
- $$('div', { className: "U_MD_O_W_SP_ShareBorder" }, _content); //分割线
- _wechat.className += " U_MD_O_W_SP_WeChat"; //加class
- _content.appendChild(_qq); //添加至最元素
- $$('div', { className: "U_MD_O_W_SP_ShareBorder" }, _content); //分割线
- _content.appendChild(_xin); //添加至最元素
- _qq.onclick = function () { //绑定点击事件
- var _title = "这个文档超赞的,赶快分享给大家吧!【" + fileinfo.Username + "--分享自-互联办公】"; //设置文本
- U.UF.OT.qqFriendShare('', _title); //调用qq好友分享的接口
- }
- _xin.onclick = function () {//绑定点击事件
- var _title = "这个文档超赞的,赶快分享给大家吧!【" + fileinfo.Username + "--分享自-互联办公】"; //设置文本
- U.UF.OT.weiboShare('', _title); //调用微博分享的接口
- }
- U.UF.OT.weChatShareCode(_wechat); //调用微信分享的接口
- parentel.appendChild(_content);
- return _content; //返回元素
- }
- /**
- * 保存我的云盘
- *
- * @fileinfo {object} 文档信息
- */
- U.MD.O.W.SP.saveSpecifiedFolder = function () {
- var _loginChecked = U.MD.U.L.isLogin(); //拿到登录状态值
- if (!_loginChecked) { //判断是否登录
- var _form = !Object.getOwnPropertyNames(US.disk.Disks).length && U.MD.DK.initDisk(US.userInfo.userid, 'f6d7a4b6-e34c-4964-beed-24187b2cb1ba'); //拿到网盘的窗体
- _form && (_form.style.display = 'none'); //隐藏窗体
- if (Object.getOwnPropertyNames(US.disk.Disks).length) { //判断US.disk.Disks常量是否有值
- var _guid = Guid.newGuid(); //生成GUID
- U.MD.DK.VW.chosenSaveFile(U.MD.O.W.SP.FILEINFO.UserFilesExtendName.toLowerCase(), _guid, U.MD.O.W.SP.FILEINFO.UserFilesName, function (fileinfo) { //调用选择保存文件弹窗位置的接口
- var _fileInfo = fileinfo; //文档信息
- U.A.Request(US.CD, [US.DB, "UseStudio_Disk", "SaveFileContent", fileinfo.UserDirectoryID, U.MD.O.W.SP.FILEINFO.UsOffice, fileinfo.UserallDirectoryname || U.MD.O.W.SP.FILEINFO.UserFilesName], function (r) { //将文档数据存储至数据库
- var _foldername = ''; //定义
- for (var i = 0; i < US.disk.initTree.length; i++) { //循环判断用户保存到那个文件夹下
- if (US.disk.initTree[i][0] == _fileInfo.UserDirectoryParentID) {
- _foldername = US.disk.initTree[i][4];
- break;
- }
- }
- if (r.value) { //判断数据库返回值判断是否插入成功
- U.Alert("以保存到云盘【" + _foldername + "】目录下!"); //提示用户
- } else {
- U.Alert("文档保存失败!") //提示用户
- }
- });
- });
- } else {
- U.alert('数据加载中...'); //提示用户
- }
- } else {
- U.alert('登录失败!'); //提示用户
- };
- }
- /**
- * 初始化加载评论
- *
- */
- U.MD.O.W.SP.initReply = function () {
- var _el = $(".U_MD_O_W_SP_Reply")[0];
- U.MD.R.reply({ 'type': true, 'el': _el, 'pid': "36341f7e-77a9-11e8-b499-005056b350a4" });
- }
- /**
- * 图片点击
- * @param event {object} 事件源
- */
- U.MD.O.W.SP.pictureClick = function (event) {
- var _nowel = event.target; //获取点击元素
- //判断是否为图片点击
- if (_nowel.tagName.toLocaleLowerCase() == "img") {
- var _mark; //设置记录
- var _arr = []; //定义图片路径数组
- var _imgels = $('#U_MD_O_W_SP_Editor img'); //获取所有图片元素
- for (i = 0; i < _imgels.length; i++) { //循环记录
- _arr.push(_imgels[i].src); //添加路径
- if (_imgels[i] == _nowel) { //判断当前点击元素为第几个
- _mark = i; //记录位置
- }
- }
- U.MD.UI.picture(_arr, _mark); //调用图片控件
- }
- }
- U.MD.O.W.SP.dnReset = function (el) {
- var _wordinfo = U.MD.O.W.SP.FILEINFO;
- var _type = U.MD.O.W.SP.FILEINFO.UserFilesExtendName == 'uw' ? 'word' : 'word';
- if (el == "cancel") {
- $(".U_MD_O_W_SP_Fixed_dnReset")[0].style.display = "none";
- //$('.U_MD_O_W_SP_ToolsBar')[0].style.display = "block";
- } else {
- if ($('#U_MD_DM_B_Manage_Pop')[0]) {
- $('#U_MD_DM_B_Manage_Pop')[0].style.display = "block";
- } else {
- if (US.userInfo.userid) {
- top.U.MD.DS.dnsInit(_wordinfo, _type);
- } else {
- U.MD.O.W.SP.LoadDiskDate();
- }
- }
- }
- //提示消失时显示加入修改按钮
- if ($(".U_MD_O_W_SP_Fixed_dnReset")[0].style.display == "none") {
- $('.U_MD_O_W_SP_ToolsBar')[0].style.display = "block";
- }else {
- $('.U_MD_O_W_SP_ToolsBar')[0].style.display = "none";
- }
- }
- U.MD.O.W.SP.LoadDiskDate = function () {
- if (JSON.stringify(US.disk.Disks) === '{}') {
- U.MD.U.L.login(function () {
- var _form = U.MD.DK.initDisk(US.userInfo.userid, "f6d7a4b6-e34c-4964-beed-24187b2cb1ba");
- setTimeout(function () {
- _form.style.display = 'none';
- }, 0);
- });
- }
- $('#U_D_' + US.userInfo.userid).length && ($('#U_D_' + US.userInfo.userid)[0].style.display = 'none');
- }
|