main.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /**
  2. * 页面专用
  3. */
  4. import '../../sass/main.scss';
  5. (function (window) {
  6. let apiUrl = window.location.origin + '/api/';
  7. let $ = window.$A;
  8. $.extend({
  9. fillUrl(str) {
  10. if (str.substring(0, 2) === "//" ||
  11. str.substring(0, 7) === "http://" ||
  12. str.substring(0, 8) === "https://" ||
  13. str.substring(0, 6) === "ftp://" ||
  14. str.substring(0, 1) === "/") {
  15. return str;
  16. }
  17. return window.location.origin + '/' + str;
  18. },
  19. aUrl(str) {
  20. if (str.substring(0, 2) === "//" ||
  21. str.substring(0, 7) === "http://" ||
  22. str.substring(0, 8) === "https://" ||
  23. str.substring(0, 6) === "ftp://" ||
  24. str.substring(0, 1) === "/") {
  25. return str;
  26. }
  27. return apiUrl + str;
  28. },
  29. aAjax(params) {
  30. if (typeof params !== 'object') return false;
  31. if (typeof params.success === 'undefined') params.success = () => { };
  32. params.url = this.aUrl(params.url);
  33. //
  34. let beforeCall = params.beforeSend;
  35. params.beforeSend = () => {
  36. $A.aAjaxLoad++;
  37. $A(".w-spinner").show();
  38. //
  39. if (typeof beforeCall == "function") {
  40. beforeCall();
  41. }
  42. };
  43. //
  44. let completeCall = params.complete;
  45. params.complete = () => {
  46. $A.aAjaxLoad--;
  47. if ($A.aAjaxLoad <= 0) {
  48. $A(".w-spinner").hide();
  49. }
  50. //
  51. if (typeof completeCall == "function") {
  52. completeCall();
  53. }
  54. };
  55. //
  56. let callback = params.success;
  57. params.success = (data, status, xhr) => {
  58. if (typeof data === 'object') {
  59. if (data.ret === -1 && params.checkRole !== false) {
  60. //身份丢失
  61. $A.app.$Modal.error({
  62. title: '温馨提示',
  63. content: data.msg,
  64. onOk: () => {
  65. $A.token("");
  66. $A.userLogout();
  67. }
  68. });
  69. return;
  70. }
  71. if (data.ret === -2 && params.role !== false) {
  72. //没有权限
  73. $A.app.$Modal.error({
  74. title: '权限不足',
  75. content: data.msg ? data.msg : "你没有相关的权限查看或编辑!"
  76. });
  77. }
  78. }
  79. if (typeof callback === "function") {
  80. callback(data, status, xhr);
  81. }
  82. };
  83. //
  84. $A.ajax(params);
  85. },
  86. aAjaxLoad: 0,
  87. /**
  88. * 编辑器参数配置
  89. * @returns {{modules: {toolbar: *[]}}}
  90. */
  91. editorOption() {
  92. return {
  93. modules: {
  94. toolbar: [
  95. ['bold', 'italic'],
  96. [{ 'list': 'ordered'}, { 'list': 'bullet' }],
  97. [{ 'size': ['small', false, 'large', 'huge'] }],
  98. [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
  99. [{ 'color': [] }, { 'background': [] }],
  100. [{ 'align': [] }]
  101. ]
  102. }
  103. };
  104. },
  105. /**
  106. * 获取token
  107. * @returns {boolean}
  108. */
  109. getToken() {
  110. let token = $A.token();
  111. return $A.count(token) < 10 ? false : token;
  112. },
  113. /**
  114. * 设置token
  115. * @param token
  116. */
  117. setToken(token) {
  118. $A.token(token);
  119. },
  120. /**
  121. * 获取会员昵称
  122. * @returns string
  123. */
  124. getUserName() {
  125. if ($A.getToken() === false) {
  126. return "";
  127. }
  128. let userInfo = $A.getUserInfo();
  129. return $A.ishave(userInfo.username) ? userInfo.username : '';
  130. },
  131. /**
  132. * 获取用户信息(并保存)
  133. * @param callback 网络请求获取到用户信息回调(监听用户信息发生变化)
  134. * @param continueListenerName 持续监听标识(字符串或boolean,true:自动生成监听标识,false:自动生成监听标识但首次不请求网络)
  135. * @returns Object
  136. */
  137. getUserInfo(callback, continueListenerName) {
  138. if (typeof callback === 'function' || (typeof callback === "boolean" && callback === true)) {
  139. if (typeof continueListenerName === "boolean") {
  140. if (continueListenerName === true) {
  141. continueListenerName = "auto-" + $A.randomString(6);
  142. } else {
  143. $A.setOnUserInfoListener("auto-" + $A.randomString(6), callback);
  144. return $A.jsonParse($A.storage("userInfo"));
  145. }
  146. }
  147. //
  148. $A.aAjax({
  149. url: 'users/info',
  150. error: () => {
  151. this.userLogout();
  152. },
  153. success: (res) => {
  154. if (res.ret === 1) {
  155. $A.storage("userInfo", res.data);
  156. $A.setToken(res.data.token);
  157. $A.triggerUserInfoListener(res.data);
  158. typeof callback === "function" && callback(res.data, $A.getToken() !== false);
  159. }
  160. },
  161. afterComplete: () => {
  162. if (typeof continueListenerName == "string" && continueListenerName) {
  163. $A.setOnUserInfoListener(continueListenerName, callback);
  164. }
  165. },
  166. });
  167. }
  168. return $A.jsonParse($A.storage("userInfo"));
  169. },
  170. /**
  171. * 打开登录页面
  172. */
  173. userLogout() {
  174. $A.token("");
  175. $A.storage("userInfo", {});
  176. $A.triggerUserInfoListener({});
  177. if (typeof $A.app === "object") {
  178. $A.app.goForward({path: '/'}, true);
  179. } else {
  180. window.location.href = window.location.origin;
  181. }
  182. },
  183. /**
  184. * 权限是否通过
  185. * @param role
  186. * @returns {boolean}
  187. */
  188. identity(role) {
  189. let userInfo = $A.getUserInfo();
  190. return $A.identityRaw(role, userInfo.identity);
  191. },
  192. /**
  193. * 权限是否通过
  194. * @param role
  195. * @returns {boolean}
  196. */
  197. identityRaw(role, identity) {
  198. let isRole = false;
  199. $A.each(identity, (index, res) => {
  200. if (res === role) {
  201. isRole = true;
  202. }
  203. });
  204. return isRole;
  205. },
  206. /**
  207. * 监听用户信息发生变化
  208. * @param listenerName 监听标识
  209. * @param callback 监听回调
  210. */
  211. setOnUserInfoListener(listenerName, callback) {
  212. if (typeof listenerName != "string") {
  213. return;
  214. }
  215. if (typeof callback === "function") {
  216. $A.__userInfoListenerObject[listenerName] = {
  217. callback: callback,
  218. }
  219. }
  220. },
  221. triggerUserInfoListener(userInfo) {
  222. let key, item;
  223. for (key in $A.__userInfoListenerObject) {
  224. if (!$A.__userInfoListenerObject.hasOwnProperty(key)) continue;
  225. item = $A.__userInfoListenerObject[key];
  226. if (typeof item.callback === "function") {
  227. item.callback(userInfo, $A.getToken() !== false);
  228. }
  229. }
  230. },
  231. __userInfoListenerObject: {},
  232. /**
  233. * 监听任务发生变化
  234. * @param listenerName 监听标识
  235. * @param callback 监听回调
  236. * @param callSpecial 是否监听几种特殊情况
  237. */
  238. setOnTaskInfoListener(listenerName, callback, callSpecial) {
  239. if (typeof listenerName != "string") {
  240. return;
  241. }
  242. if (typeof callback === "function") {
  243. $A.__taskInfoListenerObject[listenerName] = {
  244. special: callSpecial === true,
  245. callback: callback,
  246. }
  247. }
  248. },
  249. triggerTaskInfoListener(act, taskDetail, sendToWS = true) {
  250. let key, item;
  251. for (key in $A.__taskInfoListenerObject) {
  252. if (!$A.__taskInfoListenerObject.hasOwnProperty(key)) continue;
  253. item = $A.__taskInfoListenerObject[key];
  254. if (typeof item.callback === "function") {
  255. if (['deleteproject', 'deletelabel', 'leveltask'].indexOf(act) === -1 || item.special === true) {
  256. if (typeof taskDetail.__modifyUsername === "undefined") {
  257. taskDetail.__modifyUsername = $A.getUserName();
  258. }
  259. item.callback(act, taskDetail);
  260. }
  261. }
  262. }
  263. if (sendToWS === true) {
  264. $A.WSOB.sendTo('team', {
  265. type: "taskA",
  266. act: act,
  267. taskDetail: taskDetail
  268. });
  269. }
  270. },
  271. __taskInfoListenerObject: {},
  272. /**
  273. * 获取待推送的日志并推送
  274. * @param taskid
  275. */
  276. triggerTaskInfoChange(taskid) {
  277. $A.aAjax({
  278. url: 'project/task/pushlog',
  279. data: {
  280. taskid: taskid,
  281. pagesize: 20
  282. },
  283. success: (res) => {
  284. if (res.ret === 1) {
  285. res.data.lists.forEach((item) => {
  286. let msgData = {
  287. type: 'taskB',
  288. username: item.username,
  289. userimg: item.userimg,
  290. indate: item.indate,
  291. text: item.detail,
  292. other: item.other
  293. };
  294. res.data.follower.forEach((username) => {
  295. if (username != msgData.username) {
  296. $A.WSOB.sendTo('user', username, msgData, 'special');
  297. }
  298. });
  299. });
  300. }
  301. }
  302. });
  303. }
  304. });
  305. /**
  306. * =============================================================================
  307. * ***************************** websocket assist ****************************
  308. * =============================================================================
  309. */
  310. $.extend({
  311. /**
  312. * @param config {username, url, token, channel, logCallback}
  313. */
  314. WTWS: function (config) {
  315. this.__instance = null;
  316. this.__connected = false;
  317. this.__callbackid = {};
  318. this.__openNum = 0;
  319. this.__autoNum = 0;
  320. this.__autoLine = function (timeout) {
  321. var tempNum = this.__autoNum;
  322. var thas = this;
  323. setTimeout(function () {
  324. if (tempNum === thas.__autoNum) {
  325. thas.__autoNum++
  326. if (!thas.__config.token) {
  327. thas.__log("[WS] No token");
  328. thas.__autoLine(timeout + 5);
  329. } else {
  330. thas.sendTo('refresh', function (res) {
  331. thas.__log("[WS] Connection " + (res.status ? 'success' : 'error'));
  332. thas.__autoLine(timeout + 5);
  333. });
  334. }
  335. }
  336. }, Math.min(timeout, 30) * 1000);
  337. }
  338. this.__log = function (text, event) {
  339. typeof this.__config.logCallback === "function" && this.__config.logCallback(text, event);
  340. }
  341. this.__lExists = function (string, find, lower) {
  342. string += "";
  343. find += "";
  344. if (lower !== true) {
  345. string = string.toLowerCase();
  346. find = find.toLowerCase();
  347. }
  348. return (string.substring(0, find.length) === find);
  349. }
  350. this.__rNum = function (str, fixed) {
  351. var _s = Number(str);
  352. if (_s + "" === "NaN") {
  353. _s = 0;
  354. }
  355. if (/^[0-9]*[1-9][0-9]*$/.test(fixed)) {
  356. _s = _s.toFixed(fixed);
  357. var rs = _s.indexOf('.');
  358. if (rs < 0) {
  359. _s += ".";
  360. for (var i = 0; i < fixed; i++) {
  361. _s += "0";
  362. }
  363. }
  364. }
  365. return _s;
  366. }
  367. this.__jParse = function (str, defaultVal) {
  368. if (str === null) {
  369. return defaultVal ? defaultVal : {};
  370. }
  371. if (typeof str === "object") {
  372. return str;
  373. }
  374. try {
  375. return JSON.parse(str);
  376. } catch (e) {
  377. return defaultVal ? defaultVal : {};
  378. }
  379. }
  380. this.__randString = function (len) {
  381. len = len || 32;
  382. var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678oOLl9gqVvUuI1';
  383. var maxPos = $chars.length;
  384. var pwd = '';
  385. for (var i = 0; i < len; i++) {
  386. pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  387. }
  388. return pwd;
  389. }
  390. this.__urlParams = function(url, params) {
  391. if (typeof params === "object" && params !== null) {
  392. url+= "";
  393. url+= url.indexOf("?") === -1 ? '?' : '';
  394. for (var key in params) {
  395. if (!params.hasOwnProperty(key)) {
  396. continue;
  397. }
  398. url+= '&' + key + '=' + params[key];
  399. }
  400. }
  401. return url.replace("?&", "?");
  402. }
  403. this.__isArr = function (obj){
  404. return Object.prototype.toString.call(obj)=='[object Array]';
  405. }
  406. /**
  407. * 设置参数
  408. * @param config
  409. */
  410. this.config = function (config) {
  411. if (typeof config !== "object" || config === null) {
  412. config = {};
  413. }
  414. config.username = config.username || '';
  415. config.url = config.url || '';
  416. config.token = config.token || '';
  417. config.channel = config.channel || '';
  418. config.logCallback = config.logCallback || null;
  419. this.__config = config;
  420. return this;
  421. }
  422. /**
  423. * 连接
  424. * @param force
  425. */
  426. this.connection = function (force) {
  427. if (!this.__lExists(this.__config.url, "ws://") && !this.__lExists(this.__config.url, "wss://")) {
  428. this.__log("[WS] No connection address");
  429. return this;
  430. }
  431. if (!this.__config.token) {
  432. this.__log("[WS] No connected token");
  433. return this;
  434. }
  435. if (this.__instance !== null && force !== true) {
  436. this.__log("[WS] Connection exists");
  437. return this;
  438. }
  439. var thas = this;
  440. // 初始化客户端套接字并建立连接
  441. this.__instance = new WebSocket(this.__urlParams(this.__config.url, {
  442. token: this.__config.token,
  443. channel: this.__config.channel
  444. }));
  445. // 连接建立时触发
  446. this.__instance.onopen = function (event) {
  447. thas.__log("[WS] Connection opened", event);
  448. }
  449. // 接收到服务端推送时执行
  450. this.__instance.onmessage = function (event) {
  451. var msgDetail = thas.__jParse(event.data);
  452. if (msgDetail.messageType === 'open') {
  453. thas.__log("[WS] Connection connected");
  454. msgDetail.openNum = thas.__openNum;
  455. msgDetail.config = thas.__config;
  456. thas.__openNum++;
  457. thas.__connected = true;
  458. thas.__autoLine(30);
  459. } else if (msgDetail.messageType === 'back') {
  460. typeof thas.__callbackid[msgDetail.messageId] === "function" && thas.__callbackid[msgDetail.messageId](msgDetail.body);
  461. delete thas.__callbackid[msgDetail.messageId];
  462. return;
  463. }
  464. if (thas.__rNum(msgDetail.contentId) > 0) {
  465. thas.sendTo('roger', msgDetail.contentId);
  466. }
  467. thas.triggerMsgListener(msgDetail);
  468. };
  469. // 连接关闭时触发
  470. this.__instance.onclose = function (event) {
  471. thas.__log("[WS] Connection closed", event);
  472. thas.__connected = false;
  473. thas.__instance = null;
  474. thas.__autoLine(5);
  475. }
  476. // 连接出错
  477. this.__instance.onerror = function (event) {
  478. thas.__log("[WS] Connection error", event);
  479. thas.__connected = false;
  480. thas.__instance = null;
  481. thas.__autoLine(5);
  482. }
  483. return this;
  484. }
  485. /**
  486. * 添加消息监听
  487. * @param listenerName
  488. * @param listenerType
  489. * @param callback
  490. */
  491. this.setOnMsgListener = function (listenerName, listenerType, callback) {
  492. if (typeof listenerName != "string") {
  493. return this;
  494. }
  495. if (typeof listenerType === "function") {
  496. callback = listenerType;
  497. listenerType = [];
  498. }
  499. if (!this.__isArr(listenerType)) {
  500. listenerType = [listenerType];
  501. }
  502. if (typeof callback === "function") {
  503. this.__msgListenerObject[listenerName] = {
  504. callback: callback,
  505. listenerType: listenerType,
  506. }
  507. }
  508. return this;
  509. }
  510. this.triggerMsgListener = function (msgDetail) {
  511. var key, item;
  512. for (key in this.__msgListenerObject) {
  513. if (!this.__msgListenerObject.hasOwnProperty(key)) {
  514. continue;
  515. }
  516. item = this.__msgListenerObject[key];
  517. if (item.listenerType.length > 0 && item.listenerType.indexOf(msgDetail.messageType) === -1) {
  518. continue;
  519. }
  520. if (typeof item.callback === "function") {
  521. item.callback(msgDetail);
  522. }
  523. }
  524. }
  525. this.__msgListenerObject = {}
  526. /**
  527. * 添加特殊监听
  528. * @param listenerName
  529. * @param callback
  530. */
  531. this.setOnSpecialListener = function (listenerName, callback) {
  532. if (typeof listenerName != "string") {
  533. return this;
  534. }
  535. if (typeof callback === "function") {
  536. this.__specialListenerObject[listenerName] = {
  537. callback: callback,
  538. }
  539. }
  540. return this;
  541. }
  542. this.triggerSpecialListener = function (simpleMsg) {
  543. var key, item;
  544. for (key in this.__specialListenerObject) {
  545. if (!this.__specialListenerObject.hasOwnProperty(key)) {
  546. continue;
  547. }
  548. item = this.__specialListenerObject[key];
  549. if (typeof item.callback === "function") {
  550. item.callback(simpleMsg);
  551. }
  552. }
  553. }
  554. this.__specialListenerObject = {}
  555. /**
  556. * 发送消息
  557. * @param messageType 会话类型
  558. * - refresh: 刷新
  559. * - unread: 未读信息总数量
  560. * - read: 已读会员信息
  561. * - roger: 收到信息回执
  562. * - user: 指定target
  563. * - update: 指定target
  564. * - team: 团队会员
  565. * @param target 发送目标
  566. * @param body 发送内容(对象或数组)
  567. * @param callback 发送回调
  568. * @param againNum
  569. */
  570. this.sendTo = function (messageType, target, body, callback, againNum = 0) {
  571. if (typeof target === "object" && typeof body === "undefined") {
  572. body = target;
  573. target = null;
  574. }
  575. if (typeof target === "function") {
  576. body = target;
  577. target = null;
  578. }
  579. if (typeof body === "function") {
  580. callback = body;
  581. body = null;
  582. }
  583. if (body === null || typeof body !== "object") {
  584. body = {};
  585. }
  586. //
  587. var thas = this;
  588. if (this.__instance === null || this.__connected === false) {
  589. if (againNum < 10 && messageType != 'team') {
  590. setTimeout(function () {
  591. thas.sendTo(messageType, target, body, callback, thas.__rNum(againNum) + 1)
  592. }, 600);
  593. if (againNum === 0) {
  594. this.connection();
  595. }
  596. } else {
  597. if (this.__instance === null) {
  598. this.__log("[WS] Service not connected");
  599. typeof callback === "function" && callback({status: 0, message: '服务未连接'});
  600. } else {
  601. this.__log("[WS] Failed connection");
  602. typeof callback === "function" && callback({status: 0, message: '未连接成功'});
  603. }
  604. }
  605. return this;
  606. }
  607. if (['refresh', 'unread', 'read', 'roger', 'user', 'info', 'team'].indexOf(messageType) === -1) {
  608. this.__log("[WS] Wrong message messageType: " + messageType);
  609. typeof callback === "function" && callback({status: 0, message: '错误的消息类型: ' + messageType});
  610. return this;
  611. }
  612. //
  613. var contentId = 0;
  614. if (messageType === 'roger') {
  615. contentId = target;
  616. target = null;
  617. }
  618. var messageId = '';
  619. if (typeof callback === "string" && callback === 'special') {
  620. callback = function (res) {
  621. res.status === 1 && thas.triggerSpecialListener({
  622. target: target,
  623. body: body,
  624. });
  625. }
  626. }
  627. if (typeof callback === "function") {
  628. messageId = this.__randString(16);
  629. this.__callbackid[messageId] = callback;
  630. }
  631. this.__instance.send(JSON.stringify({
  632. messageType: messageType,
  633. messageId: messageId,
  634. contentId: contentId,
  635. channel: this.__config.channel,
  636. username: this.__config.username,
  637. target: target,
  638. body: body,
  639. time: Math.round(new Date().getTime() / 1000),
  640. }));
  641. return this;
  642. }
  643. /**
  644. * 关闭连接
  645. */
  646. this.close = function () {
  647. if (this.__instance === null) {
  648. this.__log("[WS] Service not connected");
  649. return this;
  650. }
  651. if (this.__connected === false) {
  652. this.__log("[WS] Failed connection");
  653. return this;
  654. }
  655. this.__instance.close();
  656. return this;
  657. }
  658. return this.config(config);
  659. },
  660. WSOB: {
  661. instance: null,
  662. isClose: false,
  663. /**
  664. * 初始化
  665. */
  666. initialize() {
  667. let url = $A.getObject(window.webSocketConfig, 'URL');
  668. if (!url) {
  669. url = window.location.origin;
  670. url = url.replace("https://", "wss://");
  671. url = url.replace("http://", "ws://");
  672. url+= "/ws";
  673. }
  674. let config = {
  675. username: $A.getUserName(),
  676. url: url,
  677. token: $A.getToken(),
  678. channel: 'web'
  679. };
  680. if (this.instance === null) {
  681. this.instance = new $A.WTWS(config);
  682. this.instance.connection()
  683. } else if (this.isClose) {
  684. this.isClose = false
  685. this.instance.config(config);
  686. this.instance.connection();
  687. }
  688. },
  689. /**
  690. * 主动连接
  691. */
  692. connection() {
  693. this.initialize();
  694. this.instance.connection();
  695. },
  696. /**
  697. * 监听消息
  698. * @param listenerName
  699. * @param listenerType
  700. * @param callback
  701. */
  702. setOnMsgListener(listenerName, listenerType, callback) {
  703. this.initialize();
  704. this.instance.setOnMsgListener(listenerName, listenerType, callback);
  705. },
  706. /**
  707. * 添加特殊监听
  708. * @param listenerName
  709. * @param callback
  710. */
  711. setOnSpecialListener(listenerName, callback) {
  712. this.initialize();
  713. this.instance.setOnSpecialListener(listenerName, callback);
  714. },
  715. /**
  716. * 发送消息
  717. * @param messageType
  718. * @param target
  719. * @param body
  720. * @param callback
  721. */
  722. sendTo(messageType, target, body, callback) {
  723. this.initialize();
  724. this.instance.sendTo(messageType, target, body, callback);
  725. },
  726. /**
  727. * 关闭连接
  728. */
  729. close() {
  730. if (this.instance === null) {
  731. return;
  732. }
  733. this.isClose = true
  734. this.instance.config(null).close();
  735. },
  736. /**
  737. * 获取消息描述
  738. * @param content
  739. * @returns {string}
  740. */
  741. getMsgDesc(content) {
  742. let desc;
  743. switch (content.type) {
  744. case 'text':
  745. desc = content.text;
  746. break;
  747. case 'image':
  748. desc = $A.app.$L('[图片]');
  749. break;
  750. case 'taskB':
  751. desc = content.text + " " + $A.app.$L("[来自关注任务]");
  752. break;
  753. case 'report':
  754. desc = content.text + " " + $A.app.$L("[来自工作报告]");
  755. break;
  756. default:
  757. desc = $A.app.$L('[未知类型]');
  758. break;
  759. }
  760. return desc;
  761. }
  762. }
  763. });
  764. window.$A = $;
  765. })(window);