前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >h5移动端智慧办公项目案例

h5移动端智慧办公项目案例

原创
作者头像
andy2018
修改2018-10-22 10:58:00
1.9K1
修改2018-10-22 10:58:00
举报
文章被收录于专栏:h5h5

h5开发的微信端智慧办公——weDingTalk项目,运用到了html5+css3+jquery+swiper+wcPop等技术进行开发,其中wcPop.js弹窗插件又进行了一次全面升级(新增全屏弹窗),另外项目中多处应用到了Material Design波纹效果,很多地方的1px进行了细化处理。

代码语言:javascript
复制
var $chatMsgList = $("#J__chatMsgList");
// ...处理编辑器信息
var $editor = $(".J__wdtEditor"), _editor = $editor[0];
function surrounds() {
	setTimeout(function () { //chrome
		var sel = window.getSelection();
		var anchorNode = sel.anchorNode;
		if (!anchorNode) return;
		if (sel.anchorNode === _editor ||
			(sel.anchorNode.nodeType === 3 && sel.anchorNode.parentNode === _editor)) {

			var range = sel.getRangeAt(0);
			var p = document.createElement("p");
			range.surroundContents(p);
			range.selectNodeContents(p);
			range.insertNode(document.createElement("br")); //chrome
			sel.collapse(p, 0);

			(function clearBr() {
				var elems = [].slice.call(_editor.children);
				for (var i = 0, len = elems.length; i < len; i++) {
					var el = elems[i];
					if (el.tagName.toLowerCase() == "br") {
						_editor.removeChild(el);
					}
				}
				elems.length = 0;
			})();
		}
	}, 10);
}

// 定义光标位置
var _lastRange = null, _sel = window.getSelection && window.getSelection();
var _rng = {
	getRange: function () {
		if (_sel && _sel.rangeCount > 0) {
			return _sel.getRangeAt(0);
		}
	},
	addRange: function () {
		if (_lastRange) {
			_sel.removeAllRanges();
			_sel.addRange(_lastRange);
		}
	}
}

// 格式编辑器包含标签
_editor.addEventListener("click", function () {
	$(".wdt__choose-panel").hide();
}, true);
_editor.addEventListener("focus", function () {
	surrounds();
}, true);
_editor.addEventListener("input", function () {
	surrounds();
}, false);

// ...选择文件
$("#J__chooseFile").on("change", function () {
	$(".wdt__choose-panel").hide();

	var file = this.files[0], fileSuffix = /\.[^\*]+/.exec(file.name).toString(), fileExt = fileSuffix.substr(fileSuffix.lastIndexOf('.') + 1, fileSuffix.length).toLowerCase();
	console.log(fileSuffix);
	console.log(fileExt);
	var fileTypeArr = ['jpg', 'jpeg', 'png', 'gif', 'txt', 'rar', 'zip', 'pdf', 'docx', 'xls'];
	if ($.inArray(fileExt, fileTypeArr) < 0) {
		wcPop({content: '附件只支持jpg、jpeg、png、gif、txt、rar、zip、pdf、docx、xls格式的文件', time: 2});
		return;
	}
	var reader = new FileReader();
	reader.readAsDataURL(file);
	reader.onload = function (e) {
		var _file = this.result;
		console.log(_file);
		var _tpl = [
			'<li class= "me">\
				<div class="content">\
					<p class="author">风铃子</p>\
					<div class="msg attachment">\
						<div class="card flexbox flex-alignc">\
							<span class="ico-bg wdt__bg01"><i class="iconfont icon-fujian"></i></span>\
							<div class="file-info flex1" title="'+ file.name +'">\
								<p class="name">'+ file.name +'</p><p class="size">'+ formateSize(file.size) +'</p>\
							</div>\
							<a class="btn-down" href="'+ _file +'" target="_blank" download="'+ file.name +'"><i class="iconfont icon-down"></i></a>\
						</div>\
					</div>\
				</div>\
				<a class="avatar" href="微钉-好友主页(详细资料).html"><img src="img/uimg/u__chat-img07.jpg" /></a>\
			</li>'
		].join("");
		$chatMsgList.append(_tpl);

		setTimeout(function () {wchat_ToBottom();}, 17);
	}

	/** 格式化文件大小显示  value : file文件的大小值 */
	formateSize = function (value) {
		if (null == value || value == '') {
			return "0 Bytes";
		}
		var unitArr = new Array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
		var index = 0;
		var srcsize = parseFloat(value);
		index = Math.floor(Math.log(srcsize) / Math.log(1024));
		var size = srcsize / Math.pow(1024, index);
		size = size.toFixed(2);		//保留的小数位数
		return size + unitArr[index];
	}
});

// ...拆开红包功能
$(".J__getRedPackets").on("click", function(){
	var getHbIdx = wcPop({
		id: 'wdtPopGetHb',
		skin: 'ios',
		content: $("#J__popupTmpl-getRedPacket").html(),
		xclose: true,
		style: 'background-color: #f3f3f3; width: 280px;',

		show: function () {
			$("body").on("click", ".J__btnGetRedPacket", function () {
				var that = $(this);
				that.addClass("active");
				setTimeout(function(){
					that.removeClass("active");
				}, 1000);
			});
		}
	});
});
代码语言:javascript
复制
/* __ 触摸模拟(active) */
.wdt__material-cell:active{background-color: rgba(25,31,37,.1)!important; transition: all .3s;}
/* __ 模拟水波效果 */
.wdt__ripple, .wdt__ripple-fff{overflow: hidden; position: relative;}
.wdt__ripple:before, .wdt__ripple-fff:before{
	background-image: radial-gradient(circle, #191f25 10%, transparent 11%); background-repeat: no-repeat; background-position: center;
	content: ''; display: block; pointer-events: none; opacity: 0; height: 100%; width: 100%; position: absolute; left: 0; top: 0;
	transform: scale(8,8); transition: transform .5s, opacity 1s;
}
.wdt__ripple-fff:before{background-image: radial-gradient(circle, #fff 10%, transparent 11%);}
.wdt__ripple:active:before, .wdt__ripple-fff:active:before{opacity: .1; transform: scale(0,0); transition: 0s;}
.wdt__ripple.disabled, .wdt__ripple-fff.disabled{pointer-events: none;}
/* __ 消息提示(圆点) - px */
/* .wdt__badge{background-color: #f25643; border-radius: 18px; color: #fff; display: inline-block; font-size: 12px; font-family: arial; text-align: center; padding: 0 4px; line-height: 14px; min-width: 8px; vertical-align: middle;}
.wdt__badge-dot{padding: 5px; min-width: 0;} */
/* __ 消息提示(圆点) - rem */
.wdt__badge{background-color: #f25643; border-radius: .4rem; color: #fff; display: inline-block; font-size: .22rem; font-family: arial; text-align: center; padding: 0 .08rem; line-height: .32rem; min-width: .32rem; vertical-align: middle;}
.wdt__badge-dot{border-radius: 50%; padding: 0; height: .1458rem; line-height: 0; min-width: 0; width: .1458rem;}
  • ——>>>欢迎一起交流学习  QQ:282310962    微信:xy190310

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档