PageSourceSearch

https://assets.uooconline.com/index/js/directives/privateMsg-011396961e.js

js uooconline.com collected 2026-10-08 09:15:39 UTC 7,825 bytes, 262 lines download raw bytes

1/**
2 * description: 私信弹出层
3 * author: Pollux
4 * create: 2015-11-01
5 */
6angular.module('privateMsg.module', [])
7  .directive('privateMsg', ['courseService', '$filter', function (courseService, $filter) {
8    return {
9      restrict: 'AE',
10      templateUrl: '/tpl/common/privatemsg-0d88593966.html',
11      scope: {
12        uid: "=", // 当前登录用户的id
13        privateClose: "&" // 关闭弹出层
14      },
15      controller: ['$scope', '$attrs', function ($scope, $attrs) {
16
17      }],
18      link: function (scope, element, attrs) {
19
20        // 富文本编辑器节点
21        var outer = angular.element(element), // 私信节点
22          editorEle = angular.element(element).find('.chatEditor-area'),
23          hisContener = outer.find(".chatContainer"), // 聊天记录节点
24          ueditor; // Ueditor
25
26        // 弹出层是否为可见
27        scope.layerVisible = false;
28
29        // 分页
30        scope.pager = {
31          page: 1,
32          pagesize: 15,
33          pages: 1
34        };
35
36        // 历史聊天数据
37        scope.historyList = [];
38
39        // 私信详细信息
40        scope.myInfo = {};
41
42        // 总共聊天总数
43        scope.historyTotal = 0;
44
45        // 创建发送editor
46        scope.ceateUeditor = function (content) {
47
48          // 存在existEditor则表示已经创建了editor
49          var existEditor = editorEle.attr('existEditor');
50          if (existEditor) { // 存在eidtor
51
52            // 设置editor为content
53            ueditor.ready(function () {
54              ueditor.setContent(content + '' || '');
55            });
56
57          } else { // 不存在eidtor, 则创建editor
58
59            var editorId = 'editor_' + (new Date().getTime());
60            editorEle.append('<div id=' + editorId + ' style="width: 100%"></div>');
61
62            // 新建ueditor
63            ueditor = UE.getEditor(editorId, {
64              initialFrameHeight: '100',
65              saveInterval: 5000000000,
66              zIndex: 1800,
67              wordCount: false,
68              // pasteplain: true,
69              retainOnlyLabelPasted: true,
70              toolbars: [
71                ['insertimage', 'link']
72              ]
73            });
74
75            // 标记已存在editor
76            ueditor.ready(function () {
77              editorEle.attr('existEditor', 1);
78            });
79          };
80        };
81
82        // 初始化ueditor
83        scope.ceateUeditor();
84
85        // 获取聊天记录
86        scope.getMsgList = function (mobj, page, callback) {
87
88          var cdata = angular.extend({
89            page: scope.pager.page,
90            pagesize: scope.pager.pagesize,
91            cate: 50,
92            order: 'DESC'
93          }, mobj);
94
95          courseService.getPriDetails(cdata, function (returnData) {
96
97            var list = [];
98
99            if (returnData.data) { // 存在data
100              var ndata = returnData.data;
101              scope.myInfo = ndata.My;
102              scope.historyTotal = ndata.data.page ? ndata.data.page.total : 0;
103              scope.pager.pages = ndata.data.page ? ndata.data.page.pages : 0;
104              list = ndata.data.data || [];
105            } else {
106              scope.myInfo = mobj;
107              scope.historyTotal = 0;
108            }
109
110            callback(list)
111          });
112        }
113
114        // 监听父级事件 layrPrivateMsg
115        // 参数 mobj {to: tid} 或 {msgid: msgid}
116        scope.$on('layrPrivateMsg', function (e, mobj) {
117          if (!mobj.to_uid && !mobj.dialog_id) { // 不存在to_uid && 不存在dialog_id 为匿名用户
118            return;
119          };
120
121          // 如果定义了uid && 当前的uid等于要发送的id
122          // 则提示不能发给自己
123          if (angular.isDefined(attrs.uid) && scope.uid == mobj.to_uid) {
124            layer.msg("同学不能给自己发私信");
125            return;
126          };
127
128          var avalidHeight = angular.element(window).height(), // 屏幕高度
129            layerHeight = avalidHeight >= 600 ? 600 : avalidHeight; // 弹出层高度 最高为600
130          scope.mobj = mobj; // 消息id
131
132          // 弹出page改为1
133          scope.pager.page = 1;
134
135          // 设置弹出层历史记录高度
136          hisContener.height(layerHeight - 210 - 43);
137
138          // 设置弹出层内容为可见
139          scope.layerVisible = false; // 隐藏弹出层内容
140          scope.loadding = true; // 显示加载层
141
142          // 获取第1页面消息
143          scope.getMsgList(mobj, 1, function (list) {
144            scope.historyList = list;
145            scope.layerVisible = true;
146            scope.loadding = false;
147          });
148
149          // 显示弹出层
150          const isExist = document.getElementById('privateMsgLayer_layui_' + mobj.to_uid);
151          !isExist && layer.open({
152            id: 'privateMsgLayer_layui_' + mobj.to_uid,
153            title: '对话记录',
154            move: false,
155            zIndex: 998,
156            type: 1,
157            scrollbar: false,
158            shadeClose: true,
159            content: angular.element(element),
160            area: ['765px', layerHeight + 'px', 'no'],
161            zIndex: 1000, //重点1
162            // success: function (layero) {
163            //   layer.setTop(layero); //重点2
164            // },
165            end: function () {
166              if (scope.privateClose) scope.privateClose();
167              scope.$emit('privateClose', true);
168            }
169          });
170        });
171
172        // 加载更多历史记录
173        scope.addMoreHistory = function () {
174
175          // 加载下一页
176          scope.pager.page++;
177
178          // 大于总页则 return;
179          if (scope.pager.page > scope.pager.pages) {
180            return;
181          };
182
183          scope.getMsgList(scope.mobj, scope.pager.page, function (list) {
184
185            scope.historyList = scope.historyList || [];
186
187            // 添加到当前页结尾
188            for (var i = 0; i < list.length; i++) {
189              scope.historyList.push(list[i])
190            };
191
192          });
193        };
194
195        // 向历史记录添加msg
196        scope.addMsgToHistory = function (msg, ueditor) {
197
198          scope.loadding = false; // 隐藏加载层
199          hisContener.scrollTop(0); // 滚动到顶部
200
201          // 为空不能提交
202          if (!msg) return;
203
204          // 组装当前的msg
205          var newMsg = angular.extend({
206            avatar: scope.myInfo.from_avatar,
207            from: scope.myInfo.from_uid,
208            to: scope.myInfo.to_uid,
209            content: msg,
210            isNew: true, // 新添加消息
211            created_time: (new Date()).getTime()
212          }, scope.myInfo);
213
214          // 向历史记录添加消息
215          scope.historyList.unshift(newMsg);
216
217          // 总数+1
218          scope.historyTotal++;
219
220          // 清空editor
221          ueditor.ready(function () { // 获取富文本内容
222            ueditor.setContent('');
223          });
224        };
225
226        // 发送私信
227        scope.addPriMsg = function () {
228
229          var content_;
230
231          // 获取富文本内容
232          ueditor.ready(function () {
233            content_ = ueditor.getContent();
234          });
235
236          // 如果为空则不提交
237          if (!content_) return;
238
239          // 显示加载层
240          scope.loadding = true;
241
242          // 发送私信
243          courseService.sendPriMsg({
244            content: content_,
245            to_uid: scope.myInfo.to_uid
246          }, function () {
247
248            // 添加到当前历史记录
249            scope.addMsgToHistory(content_, ueditor);
250          }).catch(function () {
251            scope.loadding = false;
252          });
253        };
254      }
255    };
256  }])
257  // 当前人是否等于发送人
258  .filter('isFromMe', function () {
259    return function (fid, mid) { // fid: 当前的item的id, 我的id
260      return fid == mid;
261    }
262  })

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.