Showing
10 changed files
with
300 additions
and
3 deletions
@@ -19,7 +19,13 @@ const index = (req, res, next) => { | @@ -19,7 +19,13 @@ const index = (req, res, next) => { | ||
19 | let userAgent = req.headers['user-agent']; | 19 | let userAgent = req.headers['user-agent']; |
20 | let unSupport = reg.test(userAgent); | 20 | let unSupport = reg.test(userAgent); |
21 | let encryptedUid = aes.encryptionUid(req.user.uid); | 21 | let encryptedUid = aes.encryptionUid(req.user.uid); |
22 | + let domains = common.domains; | ||
23 | + let imCs = domains.imCs; | ||
24 | + let imSocket = domains.imSocket; | ||
25 | + | ||
22 | let data = { | 26 | let data = { |
27 | + imCs, | ||
28 | + imSocket, | ||
23 | encryptedUid, | 29 | encryptedUid, |
24 | layout: false | 30 | layout: false |
25 | }; | 31 | }; |
@@ -54,6 +54,12 @@ | @@ -54,6 +54,12 @@ | ||
54 | {{> connect-fail}} | 54 | {{> connect-fail}} |
55 | 55 | ||
56 | <input name="encryptedUid" type="text" type="hidden" value={{encryptedUid}}> | 56 | <input name="encryptedUid" type="text" type="hidden" value={{encryptedUid}}> |
57 | + <script> | ||
58 | + var gDomains = { | ||
59 | + imCs: '{{{imCs}}}', | ||
60 | + imSocket: '{{{imSocket}}}' | ||
61 | + } | ||
62 | + </script> | ||
57 | {{#if devEnv}} | 63 | {{#if devEnv}} |
58 | <input name="assetsPrefix" type="text" type="hidden" value=""> | 64 | <input name="assetsPrefix" type="text" type="hidden" value=""> |
59 | <script src="//{{devHost}}:5002/libs.js"></script> | 65 | <script src="//{{devHost}}:5002/libs.js"></script> |
@@ -12,8 +12,10 @@ var $ = require('yoho-jquery'), | @@ -12,8 +12,10 @@ var $ = require('yoho-jquery'), | ||
12 | emojiMap = require('./emoji-map'), | 12 | emojiMap = require('./emoji-map'), |
13 | editArea = require('./edit-area'), | 13 | editArea = require('./edit-area'), |
14 | broswer = require('./broswer'), | 14 | broswer = require('./broswer'), |
15 | - socketChat = require('./socket-chat'), | ||
16 | - socketConf = require('./socket-config'); | 15 | + send = require('./socket/send'), |
16 | + socketChat = require('./socket/chat'), | ||
17 | + socketConf = require('./socket/config'), | ||
18 | + clipPaste = require('./clip-paste'); | ||
17 | 19 | ||
18 | var allRTs, | 20 | var allRTs, |
19 | endTime, | 21 | endTime, |
@@ -824,6 +826,11 @@ function pageInit() { | @@ -824,6 +826,11 @@ function pageInit() { | ||
824 | }); | 826 | }); |
825 | }()); | 827 | }()); |
826 | 828 | ||
829 | + // 剪切板粘贴发送图片 | ||
830 | + new clipPaste('.msg-area', function(path){ | ||
831 | + send.image(path); | ||
832 | + }); | ||
833 | + | ||
827 | // tab页title重置 | 834 | // tab页title重置 |
828 | broswer.tabVisible(function() { | 835 | broswer.tabVisible(function() { |
829 | document.title = docTitle; | 836 | document.title = docTitle; |
public/js/service/clip-paste.js
0 → 100644
1 | +/** | ||
2 | + * 粘贴剪切板 | ||
3 | + * @author qi.li@yoho.cn | ||
4 | + * @date: 2017/03/09 | ||
5 | + */ | ||
6 | + | ||
7 | +/* global gDomains injected from client.hbs*/ | ||
8 | +var $ = require('yoho-jquery'); | ||
9 | +var Handlebars = require('yoho-handlebars'); | ||
10 | +var config = require('../../../config/common'); | ||
11 | + | ||
12 | +// dialog html | ||
13 | +var $view = '<div class="mask-dialog preview-dialog">' + | ||
14 | + '<div class="dialog-mask"></div>' + | ||
15 | + '<div class="dialog-main">' + | ||
16 | + '<div class="head-part">' + | ||
17 | + '<span class="head-title">是否发送图片</span> ' + | ||
18 | + '<span class="head-close">x</span>' + | ||
19 | + '</div>' + | ||
20 | + '<div class="body-part">' + | ||
21 | + '<img class="clip-img" src="{{src}}">' + | ||
22 | + '</div>' + | ||
23 | + '<div class="foot-part">' + | ||
24 | + '<a class="foot-btn confirm-btn" href="javascript:;">发送</a>' + | ||
25 | + '<a class="foot-btn cancel-btn" href="javascript:;">取消</a>' + | ||
26 | + '</div>' + | ||
27 | + '</div>' + | ||
28 | + '</div>'; | ||
29 | + | ||
30 | +var $viewHbs = Handlebars.compile($view); | ||
31 | + | ||
32 | +/** | ||
33 | + * 粘贴事件 | ||
34 | + * @param sl 事件元素选择器 | ||
35 | + * @param cb 上传成功的回调 | ||
36 | + */ | ||
37 | +function Paste(sl, cb) { | ||
38 | + if(typeof sl !== 'string') { return }; | ||
39 | + this.$el = document.querySelector(sl); | ||
40 | + this.formData = null; | ||
41 | + this.uploadCb = cb; | ||
42 | + this.isSending = false; | ||
43 | + this.bindEvents(); | ||
44 | +} | ||
45 | + | ||
46 | +Paste.prototype = { | ||
47 | + bindEvents: function() { | ||
48 | + var self = this; | ||
49 | + | ||
50 | + this.$el.addEventListener("paste", function (e) { | ||
51 | + var cbd = e.clipboardData; | ||
52 | + var ua = window.navigator.userAgent; | ||
53 | + | ||
54 | + // 如果是 Safari 直接 return | ||
55 | + if ( !(e.clipboardData && e.clipboardData.items) ) { | ||
56 | + return; | ||
57 | + } | ||
58 | + | ||
59 | + // Mac平台下Chrome49版本以下 复制Finder中的文件的Bug Hack掉 | ||
60 | + if(cbd.items && cbd.items.length === 2 && cbd.items[0].kind === "string" && cbd.items[1].kind === "file" && | ||
61 | + cbd.types && cbd.types.length === 2 && cbd.types[0] === "text/plain" && cbd.types[1] === "Files" && | ||
62 | + ua.match(/Macintosh/i) && Number(ua.match(/Chrome\/(\d{2})/i)[1]) < 49){ | ||
63 | + return; | ||
64 | + } | ||
65 | + | ||
66 | + for(var i = 0; i < cbd.items.length; i++) { | ||
67 | + var item = cbd.items[i]; | ||
68 | + if(item.kind == "file"){ | ||
69 | + var file = item.getAsFile(); | ||
70 | + if (file.size === 0) { return; } | ||
71 | + | ||
72 | + self.formData = new FormData(); | ||
73 | + self.formData.append('files[]', file, 'clip.jpg'); | ||
74 | + | ||
75 | + var _upload = function() { | ||
76 | + if(self.isSending) return; | ||
77 | + self.isSending = true; | ||
78 | + | ||
79 | + $.ajax({ | ||
80 | + type: 'POST', | ||
81 | + url: gDomains.imCs + '/fileManage/uploadFile', | ||
82 | + data: self.formData, | ||
83 | + processData: false, // 告诉jQuery不要去处理发送的数据 | ||
84 | + contentType: false | ||
85 | + }) | ||
86 | + .done(function(res) { | ||
87 | + if (res.code === 200) { | ||
88 | + var path = res.data.filePath; | ||
89 | + self.uploadCb(path); | ||
90 | + self.close(); | ||
91 | + } | ||
92 | + }) | ||
93 | + .fail(function() { | ||
94 | + alert('图片发送失败、点击发送重试!'); | ||
95 | + }) | ||
96 | + .always(function() { | ||
97 | + self.isSending = false; | ||
98 | + }); | ||
99 | + }; | ||
100 | + | ||
101 | + var _bindPrevEvents = function() { | ||
102 | + var $prev = self.$preview; | ||
103 | + | ||
104 | + $prev.on('click', '.head-close, .cancel-btn', self.close.bind(self)) | ||
105 | + .on('click', '.confirm-btn', _upload); | ||
106 | + } | ||
107 | + | ||
108 | + var _drawPreview = function(url) { | ||
109 | + var $prev = $('.preview-dialog'); | ||
110 | + var $img = $prev.find('.clip-img'); | ||
111 | + var len = $img.length; | ||
112 | + | ||
113 | + if(len) { | ||
114 | + $img.attr('src', url); | ||
115 | + self.$preview = $prev; | ||
116 | + return; | ||
117 | + } | ||
118 | + | ||
119 | + var html = $viewHbs({src: url}); | ||
120 | + $('body').append(html); | ||
121 | + $('.preview-dialog').css('z-index', 1090); | ||
122 | + self.$preview = $('.preview-dialog'); | ||
123 | + | ||
124 | + // 绑定预览内事件 | ||
125 | + _bindPrevEvents(); | ||
126 | + }; | ||
127 | + | ||
128 | + var reader = new FileReader(); | ||
129 | + reader.onload = function(e) { | ||
130 | + var base64 = e.target.result; | ||
131 | + var image = new Image(); | ||
132 | + image.src = base64; | ||
133 | + image.onload = function() { | ||
134 | + _drawPreview(base64); | ||
135 | + self.open(); | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + reader.readAsDataURL(file); | ||
140 | + } | ||
141 | + } | ||
142 | + }, false); | ||
143 | + }, | ||
144 | + | ||
145 | + open: function() { | ||
146 | + this.$preview.show(); | ||
147 | + }, | ||
148 | + | ||
149 | + close: function() { | ||
150 | + console.log(this); | ||
151 | + this.$preview.hide(); | ||
152 | + } | ||
153 | +} | ||
154 | + | ||
155 | +Paste.prototype.constructor = Paste; | ||
156 | + | ||
157 | +module.exports = Paste; | ||
158 | + |
public/js/service/socket/send.js
0 → 100644
1 | +/** | ||
2 | + * 消息发送 | ||
3 | + * @author <qi.li@yoho.cn> | ||
4 | + * @date 2017/03/13 | ||
5 | + */ | ||
6 | +var uuid = require('uuid'); | ||
7 | +var chat = require('./chat'); | ||
8 | +var sockConf = require('./config'); | ||
9 | +var recTypes = sockConf.recType; | ||
10 | +var conMSG = sockConf.conversationMessage; | ||
11 | + | ||
12 | +/** | ||
13 | + * 发送 | ||
14 | + * @param {msg} 消息体 | ||
15 | + */ | ||
16 | +function _send(msg) { | ||
17 | + chat.send(msg); | ||
18 | +} | ||
19 | + | ||
20 | +/** | ||
21 | + * 图片发送 | ||
22 | + */ | ||
23 | +exports.image = function(path) { | ||
24 | + var IMG_TYPE = 2; // 图片消息 | ||
25 | + conMSG.type = recTypes.CU_SEND; | ||
26 | + conMSG.chatMessage.content = path; | ||
27 | + conMSG.chatMessage.type = IMG_TYPE; | ||
28 | + conMSG.uuid = uuid.v4(); | ||
29 | + _send(conMSG); | ||
30 | +} |
@@ -22,9 +22,9 @@ | @@ -22,9 +22,9 @@ | ||
22 | position: relative; | 22 | position: relative; |
23 | display: block; | 23 | display: block; |
24 | height: auto; | 24 | height: auto; |
25 | + max-width: 90%; | ||
25 | margin: 0 auto; | 26 | margin: 0 auto; |
26 | margin-top: 50px; | 27 | margin-top: 50px; |
27 | cursor: pointer; | 28 | cursor: pointer; |
28 | - | ||
29 | } | 29 | } |
30 | } | 30 | } |
@@ -1150,6 +1150,7 @@ $color-3a3a3a: #3a3a3a; | @@ -1150,6 +1150,7 @@ $color-3a3a3a: #3a3a3a; | ||
1150 | @import "_img-zoom-in.css"; | 1150 | @import "_img-zoom-in.css"; |
1151 | @import "_un-support.css"; | 1151 | @import "_un-support.css"; |
1152 | @import "_connect-fail.css"; | 1152 | @import "_connect-fail.css"; |
1153 | + @import "_mask-dialog.css"; | ||
1153 | } | 1154 | } |
1154 | 1155 | ||
1155 | 1156 |
public/scss/service/_mask-dialog.css
0 → 100644
1 | +.mask-dialog { | ||
2 | + display: none; | ||
3 | + position: fixed; | ||
4 | + left: 0; | ||
5 | + top: 0; | ||
6 | + width: 100%; | ||
7 | + height: 100%; | ||
8 | + | ||
9 | + .dialog-mask { | ||
10 | + position: fixed; | ||
11 | + top: 0; | ||
12 | + left: 0; | ||
13 | + right: 0; | ||
14 | + bottom: 0; | ||
15 | + z-index: 1070; | ||
16 | + background-color: #000; | ||
17 | + filter: alpha(opacity=50); | ||
18 | + opacity: .4; | ||
19 | + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; | ||
20 | + } | ||
21 | + | ||
22 | + .dialog-main { | ||
23 | + position: relative; | ||
24 | + top: 50px; | ||
25 | + width: 600px; | ||
26 | + padding: 20px; | ||
27 | + z-index: 1100; | ||
28 | + margin: 0 auto; | ||
29 | + background: #fff; | ||
30 | + border: 1px solid #c2bbbb; | ||
31 | + box-shadow: 1px 1px 10px #000; | ||
32 | + | ||
33 | + .head-part { | ||
34 | + margin-bottom: 20px; | ||
35 | + | ||
36 | + .head-title { | ||
37 | + font-size: 14px; | ||
38 | + } | ||
39 | + | ||
40 | + .head-close { | ||
41 | + position: absolute; | ||
42 | + right: 25px; | ||
43 | + top: 15px; | ||
44 | + font-size: 22px; | ||
45 | + cursor: pointer; | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | + .body-part { | ||
50 | + margin-bottom: 20px; | ||
51 | + text-align: center; | ||
52 | + | ||
53 | + .clip-img { | ||
54 | + max-width: 560px; | ||
55 | + max-height: 400px; | ||
56 | + border: 1px solid #eee; | ||
57 | + } | ||
58 | + | ||
59 | + } | ||
60 | + | ||
61 | + .foot-part { | ||
62 | + text-align: center; | ||
63 | + | ||
64 | + .foot-btn { | ||
65 | + display: inline-block; | ||
66 | + height: 30px; | ||
67 | + width: 120px; | ||
68 | + margin: 0 40px; | ||
69 | + color: #fff; | ||
70 | + line-height: 30px; | ||
71 | + text-align: center; | ||
72 | + text-decoration: none; | ||
73 | + background: #fff; | ||
74 | + border: 1px solid #000; | ||
75 | + cursor: pointer; | ||
76 | + } | ||
77 | + | ||
78 | + .confirm-btn { | ||
79 | + background: #000; | ||
80 | + } | ||
81 | + | ||
82 | + .cancel-btn { | ||
83 | + color: #000; | ||
84 | + } | ||
85 | + | ||
86 | + } | ||
87 | + } | ||
88 | +} | ||
89 | + |
-
Please register or login to post a comment