jhzh
2025-04-27 c6c703c80be3ee1f1f2d28f820c4d3b730e17040
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="format-detection" content="telephone=no" />
    <title>沟通中</title>
    <link rel="stylesheet" type="text/css"
          href="__STATIC__/newcj/css/themes.css?v=2017129">
    <link rel="stylesheet" type="text/css" href="__STATIC__/newcj/css/h5app.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/newcj/fonts/iconfont.css?v=2016070717">
    <script src="__STATIC__/newcj/js/jquery.min2.js"></script>
    <script src="__STATIC__/newcj/js/dist/flexible/flexible_css.debug.js"></script>
    <script src="__STATIC__/newcj/js/dist/flexible/flexible.debug.js"></script>
    <script src="__STATIC__/qqFace/js/jquery.qqFace.js"></script>
    <style>
        table{width: 100%;}
        .qqFace { margin-top: -338px; background: #fff; padding: 2px; border: 1px #dfe6f6 solid;
            width: 92%;}
        .qqFace table td { padding: 0px; text-align: center;}
        .qqFace table td img { cursor: pointer; border: 1px #fff solid; width: 90%}
        .qqFace table td img:hover { border: 1px #0066cc solid; }
    </style>
 
</head>
<body ontouchstart>
<div class='fui-page-group'>
<div class='fui-page chatDetail-page'>
    <div class="chat-header flex">
        <!--<span class="return"><i class="icon icon-toleft t-48"></i></span>-->
        <span class="shop-titlte t-30">商店</span>
        <span class="shop-online t-26"></span>
        <!--<span class="into-shop">进店</span>-->
    </div>
    <div class="fui-content navbar" style="padding:1.2rem 0 1.35rem 0;">
        <div class="chat-content">
            <p style="display: none;text-align: center;padding-top: 0.5rem" id="more"><a>加载更多</a></p>
            <!--<p class="chat-time"><span class="time">2019-10-10</span></p>-->
            <p class="chat-time"></p>
 
<!--            <div class="chat-text section-left flex">-->
<!--                <span class="char-img" style="background-image:-->
<!--                url(__STATIC__/newcj/img/123.jpg)"></span>-->
<!--                <span class="text"><i class="icon icon-sanjiao4 t-32"></i>你好</span>-->
<!--            </div>-->
 
<!--            <div class="chat-text section-right flex">-->
<!--                <span class="text"><i class="icon icon-sanjiao3 t-32"></i>你好</span>-->
<!--                <span class="char-img" style="background-image:-->
<!--                url(__STATIC__/newcj/img/132.jpg)"></span>-->
<!--            </div>-->
 
        </div>
    </div>
    <div class="fix-send flex footer-bar">
        <i class="icon icon-emoji1 t-50"></i>
        <input class="send-input t-28" maxlength="200" id="saytext">
        <input type="file" name="pic" id="file" style="display: none">
        <i class="icon icon-add image_up t-50" style="color: #888;"></i>
        <span class="send-btn">发送</span>
    </div>
</div>
</div>
</body>
<script>
    var fromid = {$fromid};
    var toid = {$toid};
 
    var from_head = '';
    var to_head = '';
    var online = 0;
    var to_name = '';
 
    var API_URL = "https://socket.kocoinlab.com/index.php/api/chat/";
    //连接socket服务器
    var ws = new WebSocket("wss://socket.kocoinlab.com/ws1");
 
    //接收socket服务方的消息
    ws.onmessage = function (e) {
        var message = eval("("+e.data+")");
        switch (message.type) {
            case 'init':
                var bind = '{"type":"bind","fromid":"'+fromid+'"}';
                ws.send(bind);
                get_head(fromid,toid);
                get_name(toid);
                message_load();
                var online = '{"type":"online","toid":'+toid+',"fromid":'+fromid+'}';
                ws.send(online);
                changeNoRead();
                return;
            case 'text':
                if (toid == message.fromid){
                    $(".chat-content").append('<div class="chat-text section-left flex">\n' +
                        '                <span class="char-img" style="background-image:\n' +
                        '                url('+to_head+')"></span>\n' +
                        '                <span class="text"><i class="icon icon-sanjiao4 t-32"></i>' +
                        replace_em(message.data) +
                        '</span>\n' +
                        '            </div>');
                    $('.chat-content').scrollTop(3000);
                }
                changeNoRead();
                return;
            case 'say_img':
                if (toid == message.fromid){
                    $(".chat-content").append('<div class="chat-text section-left flex">\n' +
                        '                <span class="char-img" style="background-image:\n' +
                        '                url('+to_head+')"></span>\n' +
                        '                <span class="text"><i class="icon icon-sanjiao4 t-32"></i><img width="120em" height="120em" src="__ROOT__/uploads/' +
                         message.img_name +'">'+
                        '</span>\n' +
                        '            </div>');
                    $('.chat-content').scrollTop(3000);
                    changeNoRead();
                }
                return;
            case 'save':
                save_Message(message);
                if (message.isread == 1){
                    online = 1;
                    $('.shop-online').text('在线');
                }else {
                    online = 0;
                    $('.shop-online').text('不在线');
                }
                return;
            case 'online':
                if (message.status == 1){
                    online = 1;
                    $('.shop-online').text('在线');
                }else {
                    online = 0;
                    $('.shop-online').text('不在线');
                }
                return;
            // case 'close':
            //     console.log(message);
            //     if (message.uid == toid){
            //         $('.shop-online').text('不在线');
            //     }else {
            //         $('.shop-online').text('在线');
            //     }
        }
    }
    
    
 
    $('.send-btn').click(function () {
        //客户端给gatewayworker发送消息
 
        var text = $('.send-input').val();
 
        var message = '{"data":"'+text+'","type":"say","fromid":"'+fromid+'","toid":"'+toid+'"}';
        $(".chat-content").append('<div class="chat-text section-right flex">\n' +
            '                <span class="text"><i class="icon icon-sanjiao3 t-32"></i>' +
            replace_em(text) +
            '</span>\n' +
            '                <span class="char-img" style="background-image:\n' +
            '                url('+from_head+')"></span>\n' +
            '            </div>');
        $('.chat-content').scrollTop(3000);
        ws.send(message);
        $('.send-input').val('');
    })
 
    function save_Message(message) {
        $.post(
            API_URL+"save_message",
            message,
            function () {
 
            },'json'
        )
    }
 
    function changeNoRead() {
        $.post(
            API_URL+"changeNoRead",
            {"fromid":fromid,"toid":toid},
            function () {
 
            },'json'
        )
    }
 
    function get_head(fromid,toid) {
        $.post(
            API_URL+"getHead",
            {"fromid":fromid,"toid":toid},
            function (e) {
                from_head = e.from_head;
                to_head = e.to_head;
            },'json'
        )
    }
 
    function get_name(toid) {
        $.post(
            API_URL+"get_name",
            {"uid":toid},
            function (e) {
                to_name = e.toname;
                $('.shop-titlte').text('与'+to_name+'聊天中')
            },'json'
        )
    }
 
    function message_load() {
        $.post(
            API_URL+"load",
            {"fromid":fromid,"toid":toid},
            function (e) {
                $.each(e,function (index,content) {
                    if(fromid == content.fromid){
                        if (content.type == 2){
                            $(".chat-content").append('<div class="chat-text section-right flex">\n' +
                                '                <span class="text"><i class="icon icon-sanjiao3 t-32"></i><img width="120em" height="120em" src="__ROOT__/uploads/' +
                                content.content+'">'+
                                '</span>\n' +
                                '                <span class="char-img" style="background-image:\n' +
                                '                url('+from_head+')"></span>\n' +
                                '            </div>');
                        }else {
                            $(".chat-content").append('<div class="chat-text section-right flex">\n' +
                                '                <span class="text"><i class="icon icon-sanjiao3 t-32"></i>' +
                                replace_em(content.content) +
                                '</span>\n' +
                                '                <span class="char-img" style="background-image:\n' +
                                '                url('+from_head+')"></span>\n' +
                                '            </div>');
                        }
                    }else {
                        if (content.type == 2){
                            $(".chat-content").append('<div class="chat-text section-left flex">\n' +
                                '                <span class="char-img" style="background-image:\n' +
                                '                url('+to_head+')"></span>\n' +
                                '                <span class="text"><i class="icon icon-sanjiao4 t-32"></i><img width="120em" height="120em" src="__ROOT__/uploads/' +
                                content.content +'">'+
                                '</span>\n' +
                                '            </div>');
                            $('.chat-content').scrollTop(3000);
                        }else {
                            $(".chat-content").append('<div class="chat-text section-left flex">\n' +
                                '                <span class="char-img" style="background-image:\n' +
                                '                url(' + to_head + ')"></span>\n' +
                                '                <span class="text"><i class="icon icon-sanjiao4 t-32"></i>' +
                                replace_em(content.content) +
                                '</span>\n' +
                                '            </div>');
                        }
                    }
                })
                $('.chat-content').scrollTop(3000);
            },'json'
        )
    }
 
    function replace_em(str){
        str = str.replace(/\</g,'&lt;');
        str = str.replace(/\>/g,'&gt;');
        str = str.replace(/\n/g,'<br/>');
        str =
            str.replace(/\[em_([0-9]*)\]/g,'<img src="__STATIC__/qqFace/arclist/$1.gif" border="0" />');
        return str;
    }
 
    $(function(){
        $('.icon-emoji1').qqFace({
            assign:'saytext',
            path:'__STATIC__/qqFace/arclist/'    //表情存放的路径
        });
 
        // $(".sub_btn").click(function(){
        //
        //     var str = $("#saytext").val();
        //
        //     $("#show").html(replace_em(str));
        //
        // });
 
    });
    
    $('.return').click(function() {
       var url = 'https://socket.kocoinlab.com/index.php/index/index/lists?fromid='+fromid;
       window.location.herf = url;
        
    });
 
    $('.image_up').click(function () {
        $('#file').click();
    })
 
    $('#file').change(function () {
        fromdata = new FormData();
        fromdata.append('fromid',fromid);
        fromdata.append('toid',toid);
        fromdata.append('online',online);
        fromdata.append('file',$("#file")[0].files[0]);
 
        $.ajax({
            url:API_URL+"uploadimg",
            type:"POST",
            cache:false,
            data:fromdata,
            dataType:'json',
            processData:false,//会把所有的数据转换后才能对象,所以禁用掉
            contentType:false,
            success:function (data,status,xhr) {
                console.log(data);
                if (data.status == 'ok'){
                    $(".chat-content").append('<div class="chat-text section-right flex">\n' +
                        '                <span class="text"><i class="icon icon-sanjiao3 t-32"></i><img width="120em" height="120em" src="__ROOT__/uploads/' +
                         data.img_name+'">'+
                        '</span>\n' +
                        '                <span class="char-img" style="background-image:\n' +
                        '                url('+from_head+')"></span>\n' +
                        '            </div>');
                    $('.chat-content').scrollTop(3000);
 
                    var message =
                        '{"data":"'+data.img_name+'","fromid":"'+fromid+'","toid":"'+toid+'","type":"say_img"}';
                    $("#file").val("");
                    ws.send(message);
 
                }else {
                    console.log(data.status)
                }
            }
        });
    })
 
 
 
</script>
 
</html>