Starter.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. MWF.require("MWF.widget.UUID", null, false);
  2. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.xApplication.IMV2 = MWF.xApplication.IMV2 || {};
  5. MWF.require("MWF.widget.Mask", null, false);
  6. MWF.xDesktop.requireApp("IMV2", "lp."+o2.language, null, false);
  7. MWF.xApplication.IMV2.Starter = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "businessType" : "none", // 业务类型 :none, process, cms 。启动聊天 是否带业务类型
  13. "businessId": null, // 业务ID 新创建为空
  14. "includePersonList": [], // 在规定范围内的人员进行选择, 如果为空,则不限制
  15. "conversationId": null, // 传入的会话id, 新创建为空
  16. "mode": "default" // 展现模式:default onlyChat 。 onlyChat的模式需要传入conversationId 会打开这个会话的聊天窗口并隐藏左边的会话列表
  17. },
  18. initialize: function(data, app, options){
  19. console.log("init IMV2.Starter " );
  20. this.setOptions(options);
  21. this.path = "../x_component_IMV2/$Main/";
  22. MWF.xDesktop.requireApp("IMV2", "lp."+o2.language, null, false);
  23. this.lp = MWF.xApplication.IMV2.LP;
  24. this.data = data;
  25. this.app = app;
  26. },
  27. load: function(){
  28. console.log("init IMV2.load " );
  29. debugger;
  30. // 打开聊天会话
  31. if (this.options.conversationId && this.options.conversationId !== "") {
  32. this.openConversationWindow(this.options.conversationId);
  33. } else {
  34. // 创建聊天
  35. var me = layout.session.user.distinguishedName;
  36. var exclude = [];
  37. if (me) {
  38. exclude = [me];
  39. }
  40. // 默认创建聊天
  41. if ( !(this.options.businessType) || this.options.businessType === "none" || !(this.options.businessId) || this.options.businessId === "" ) {
  42. var form = new MWF.xApplication.IMV2.Starter.CreateConversationForm(this);
  43. form.create()
  44. } else if (this.options.businessType === "process") {
  45. if (this.options.businessId) {
  46. //TODO 如果已经存在是否考虑可创建多个,那就需要提示创建新的还是打开老的
  47. console.log("根据流程的job id查询,会话是否存在,如果存在,则打开,如果不存在,则创建。jobId: " + this.options.businessId);
  48. this.findConversationByBusinessId();
  49. } else {
  50. this.app.notice(this.lp.msgNoBusinessId, "error");
  51. }
  52. //打开工作 o2.env.form.openJob
  53. } else {
  54. this.app.notice(this.lp.msgNotSupport, "error");
  55. }
  56. }
  57. },
  58. // 打开会话聊天窗口
  59. openConversationWindow: function(conversationId) {
  60. var options = {
  61. conversationId: conversationId,
  62. mode: this.options.mode || "default"
  63. }
  64. layout.openApplication(null, "IMV2", options);
  65. },
  66. // 创建会话
  67. newConversation: function(personList) {
  68. console.log("newConversation", personList);
  69. var cType = "single"; // cType 会话类型 "single" "group"
  70. if (personList.length > 1) {
  71. cType = "group"
  72. }
  73. var conv = {
  74. type: cType,
  75. personList: personList,
  76. };
  77. if (this.options.businessId) {
  78. conv.businessId = this.options.businessId;
  79. conv.businessType = this.options.businessType;
  80. }
  81. o2.Actions.load("x_message_assemble_communicate").ImAction.create(conv, function (json) {
  82. var newConv = json.data;
  83. if (this.app.refreshAll) this.app.refreshAll();
  84. this.openConversationWindow(newConv.id);
  85. }.bind(this), function (error) {
  86. console.log(error);
  87. this.app.notice(error, "error");
  88. if (this.app.refreshAll) this.app.refreshAll();
  89. }.bind(this))
  90. },
  91. // 根据流程的job id查询,会话是否存在
  92. findConversationByBusinessId: function() {
  93. o2.Actions.load("x_message_assemble_communicate").ImAction.conversationFindByBusinessId(this.options.businessId, function(json){
  94. if (json.data && json.data.length > 0) {
  95. this.showChooseConversationDialog(json.data);
  96. } else {
  97. if (this.options.businessType === "process") {
  98. this.getProcessReviewByJobId();
  99. }
  100. }
  101. }.bind(this), function (error) {
  102. console.log(error);
  103. if (this.options.businessType === "process") {
  104. this.getProcessReviewByJobId();
  105. }
  106. }.bind(this));
  107. },
  108. // 有存在的会话 展现可以点击打开会话聊天
  109. showChooseConversationDialog: function(conversationList) {
  110. if (conversationList && conversationList.length > 0) {
  111. var cssPath = this.path + "default/style.css";
  112. var chooseConversationHtmlPath = this.path + "default/chooseConversation.html";
  113. this.app.content.loadAll({
  114. "css": [cssPath],
  115. "html": chooseConversationHtmlPath,
  116. }, { "bind": { "lp": this.lp, "data": {} }, "module": this }, function(){
  117. // 会话列表
  118. for (let index = 0; index < conversationList.length; index++) {
  119. const conv = conversationList[index];
  120. // <div class="conversation-item">群聊1111 | <span style="color: #4A90E2;">打开</span></div>
  121. var conversationItem = new Element("div", {"class": "conversation-item"}).inject(this.conversationChooseListNode);
  122. new Element("span", {"text": "【"+conv.title+"】"}).inject(conversationItem);
  123. new Element("span", {"text": "打开", "style": "color: #4A90E2;"}).inject(conversationItem);
  124. // conversationItem.set("text", conv.title + " | <span style=\"color: #4A90E2;\">打开</span>");
  125. conversationItem.store("conversation", conv);
  126. conversationItem.addEvents({
  127. "click": function(e){
  128. debugger;
  129. var myConv = null;
  130. if (e.target.get("tag") === "span") {
  131. myConv = e.target.parentNode.retrieve("conversation");
  132. } else {
  133. myConv = e.target.retrieve("conversation");
  134. }
  135. if (myConv) {
  136. this.openConversationWindow(myConv.id);
  137. this.closeChooseConversationDialog();
  138. }
  139. }.bind(this)
  140. });
  141. }
  142. // 关闭按钮
  143. this.conversationChooseCloseNode.addEvents({
  144. "click": function(e){
  145. this.closeChooseConversationDialog();
  146. }.bind(this)
  147. });
  148. // 新建聊天按钮
  149. this.conversationCreateNewNode.addEvents({
  150. "click": function(e){
  151. this.closeChooseConversationDialog();
  152. if (this.options.businessType === "process") {
  153. this.getProcessReviewByJobId();
  154. }
  155. }.bind(this)
  156. })
  157. }.bind(this));
  158. }
  159. },
  160. // 关闭会话选择窗口
  161. closeChooseConversationDialog: function() {
  162. if (this.conversationChooseDialogNode) {
  163. this.conversationChooseDialogNode.destroy();
  164. this.conversationChooseDialogNode = null;
  165. }
  166. if (this.app.refreshAll) this.app.refreshAll();
  167. },
  168. // 显示创建会话的表单,上面列示出人员列表,可以选择人员
  169. showCreateConversationWithPersonsDialog: function(personList) {
  170. if (personList && personList.length > 0) {
  171. var cssPath = this.path + "default/style.css";
  172. var choosePersonHtmlPath = this.path + "default/choosePerson.html";
  173. this.app.content.loadAll({
  174. "css": [cssPath],
  175. "html": choosePersonHtmlPath,
  176. }, { "bind": { "lp": this.lp, "data": {} }, "module": this }, function(){
  177. //载入完成后的回调
  178. // 人员列表
  179. for (let index = 0; index < personList.length; index++) {
  180. const person = personList[index];
  181. // <div class="person-tag person-tag-active">了国栋</div>
  182. var personTag = new Element("div", {"class": "person-tag person-tag-active"}).inject(this.personListNode);
  183. var name = person;
  184. if (person.indexOf("@") != -1) {
  185. name = name.substring(0, person.indexOf("@"));
  186. }
  187. personTag.set("text", name);
  188. personTag.store("person", person);
  189. personTag.addEvents({
  190. "click": function(e){
  191. if (e.target.get("class") == "person-tag person-tag-active") {
  192. e.target.set("class", "person-tag");
  193. } else {
  194. e.target.set("class", "person-tag person-tag-active");
  195. }
  196. }
  197. });
  198. }
  199. // 创建会话按钮
  200. this.personChooseCreateNode.addEvents({
  201. "click": function(e){
  202. var personList = []
  203. this.personListNode.getChildren().each(function(tag){
  204. if (tag.get("class") == "person-tag person-tag-active") {
  205. personList.push(tag.retrieve("person"));
  206. }
  207. });
  208. if (personList.length > 0) {
  209. this.newConversation(personList);
  210. this.closeChoosePersonDialog();
  211. } else {
  212. this.app.notice(this.lp.msgNeedChoosePerson, "error");
  213. }
  214. }.bind(this)
  215. });
  216. // 关闭按钮
  217. this.personChooseCloseBtnNode.addEvents({
  218. "click": function(e){
  219. this.closeChoosePersonDialog();
  220. }.bind(this)
  221. })
  222. }.bind(this));
  223. } else {
  224. this.app.notice(this.lp.msgNoBusinessPerson, "error");
  225. }
  226. },
  227. // 关闭人员选择
  228. closeChoosePersonDialog: function(){
  229. if (this.personChooseDialogNode) {
  230. this.personChooseDialogNode.destroy();
  231. this.personChooseDialogNode = null;
  232. }
  233. if (this.app.refreshAll) this.app.refreshAll();
  234. },
  235. // 根据jobid查询review,获取所有相关的人员
  236. getProcessReviewByJobId: function() {
  237. o2.Actions.load("x_processplatform_assemble_surface").ReviewAction.listWithJob(this.options.businessId, function(json){
  238. if (json.data && json.data.length > 0) {
  239. var personList = [];
  240. json.data.each(function(review){
  241. if (review.person && review.person !== layout.session.user.distinguishedName) {
  242. personList.push(review.person);
  243. }
  244. });
  245. this.showCreateConversationWithPersonsDialog(personList);
  246. } else {
  247. this.showCreateConversationWithPersonsDialog([]);
  248. }
  249. }.bind(this), function(error){
  250. console.log(error);
  251. this.showCreateConversationWithPersonsDialog([]);
  252. }.bind(this));
  253. }
  254. });
  255. //创建聊天 弹出窗表单
  256. MWF.xApplication.IMV2.Starter.CreateConversationForm = new Class({
  257. Extends: MPopupForm,
  258. Implements: [Options, Events],
  259. options: {
  260. "style": "minder",
  261. "width": 700,
  262. "height": "200",
  263. "hasTop": true,
  264. "hasIcon": false,
  265. "draggable": true,
  266. "title": MWF.xApplication.IMV2.LP.createConversation,
  267. "includePersonList": [], // 在规定范围内的人员进行选择, 如果为空,则不限制
  268. "personSelected": []
  269. },
  270. _createTableContent: function () {
  271. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  272. "<tr><td styles='formTableTitle' lable='person' width='25%'></td>" +
  273. " <td styles='formTableValue14' item='person' colspan='3'></td></tr>" +
  274. "</table>";
  275. this.formTableArea.set("html", html);
  276. var me = layout.session.user.distinguishedName;
  277. var exclude = [];
  278. if (me) {
  279. exclude = [me];
  280. }
  281. this.form = new MForm(this.formTableArea, this.data || {}, {
  282. isEdited: true,
  283. style: "minder",
  284. hasColon: true,
  285. itemTemplate: {
  286. person: {
  287. text: MWF.xApplication.IMV2.LP.selectPerson,
  288. type: "org",
  289. orgType: "person",
  290. notEmpty: true,
  291. exclude: exclude,
  292. count: 0, // 可选人数 0是不限制人数
  293. value: this.options["personSelected"] },
  294. }
  295. }, this.app);
  296. this.form.load();
  297. },
  298. _createBottomContent: function () {
  299. if (this.isNew || this.isEdited) {
  300. this.okActionNode = new Element("button.inputOkButton", {
  301. "styles": this.css.inputOkButton,
  302. "text": MWF.xApplication.IMV2.LP.ok
  303. }).inject(this.formBottomNode);
  304. this.okActionNode.addEvent("click", function (e) {
  305. this.save(e);
  306. }.bind(this));
  307. }
  308. this.cancelActionNode = new Element("button.inputCancelButton", {
  309. "styles": (this.isEdited || this.isNew || this.getEditPermission()) ? this.css.inputCancelButton : this.css.inputCancelButton_long,
  310. "text": MWF.xApplication.IMV2.LP.close
  311. }).inject(this.formBottomNode);
  312. this.cancelActionNode.addEvent("click", function (e) {
  313. this.close(e);
  314. }.bind(this));
  315. },
  316. save: function () {
  317. var data = this.form.getResult(true, null, true, false, true);
  318. if (data) {
  319. this.explorer.newConversation(data.person);
  320. this.close();
  321. }
  322. }
  323. });
  324. /**
  325. * 分享消息、转发消息
  326. */
  327. MWF.xApplication.IMV2.ShareToConversation = new Class({
  328. Extends: MWF.widget.Common,
  329. Implements: [Options, Events],
  330. options: {
  331. "style": "default",
  332. "businessType" : "none", // 业务类型 :none, process, cms 。启动聊天 是否带业务类型
  333. "businessId": null, // 业务ID 新创建为空
  334. "includePersonList": [], // 在规定范围内的人员进行选择, 如果为空,则不限制
  335. "conversationId": null, // 传入的会话id, 新创建为空
  336. "mode": "default" // 展现模式:default onlyChat 。 onlyChat的模式需要传入conversationId 会打开这个会话的聊天窗口并隐藏左边的会话列表
  337. },
  338. initialize: function(data, app, options){
  339. console.log("init IMV2.Starter " );
  340. this.setOptions(options);
  341. this.path = "../x_component_IMV2/$Main/";
  342. MWF.xDesktop.requireApp("IMV2", "lp."+o2.language, null, false);
  343. this.lp = MWF.xApplication.IMV2.LP;
  344. this.data = data; // msgBody 消息体
  345. this.app = app;
  346. },
  347. load: function(){
  348. console.log("init IMV2.ShareToConversation " );
  349. debugger;
  350. if (this.data && this.data.msgBody) {
  351. console.log(this.data.msgBody );
  352. this.openConversationListDialog();
  353. } else {
  354. this.app.notice(this.lp.msgShareNoBody, "error");
  355. }
  356. },
  357. // 打开窗口
  358. openConversationListDialog: function() {
  359. var cssPath = this.path + "default/style.css";
  360. var choosePersonHtmlPath = this.path + "default/shareToConversation.html";
  361. this.app.content.loadAll({
  362. "css": [cssPath],
  363. "html": choosePersonHtmlPath,
  364. }, { "bind": { "lp": this.lp, "data": {} }, "module": this }, function() {
  365. this.conversationChooseCloseBtnNode.addEvents({
  366. "click": function(){this.closeConversationListDialog()}.bind(this)
  367. });
  368. this.shareSearchInputNode.addEvent("keyup", function (e){
  369. if (e.code === 13) {
  370. e.stopPropagation();
  371. var searchInputVal = this.shareSearchInputNode.get("value");
  372. console.log('搜索内容: '+searchInputVal)
  373. this.searchConversationAndPerson(searchInputVal);
  374. }
  375. }.bind(this));
  376. this.loadConversationList();
  377. }.bind(this));
  378. },
  379. // 关闭窗口
  380. closeConversationListDialog: function() {
  381. if (this.conversationChooseDialogNode) {
  382. this.conversationChooseDialogNode.destroy();
  383. this.conversationChooseDialogNode = null;
  384. }
  385. if (this.app.refreshAll) this.app.refreshAll();
  386. },
  387. // 加载会话列表
  388. loadConversationList: function() {
  389. o2.Actions.load("x_message_assemble_communicate").ImAction.myConversationList(function (json) {
  390. if (json.data && json.data instanceof Array) {
  391. this.conversationList = json.data; // 会话数据
  392. this.conversationNodeItemList = [];
  393. for (var i = 0; i < this.conversationList.length; i++) {
  394. var conversation = this.conversationList[i];
  395. var itemNode = this._createConvItemNode(conversation);
  396. this.conversationNodeItemList.push(itemNode);
  397. }
  398. }
  399. }.bind(this));
  400. },
  401. // 搜索会话
  402. searchConversationAndPerson: function(value) {
  403. this.conversationListNode.empty();
  404. this.searchPersonListNode.empty();
  405. this.searchPersonTitleNode.classList.remove("block");
  406. this.searchPersonTitleNode.classList.add("none");
  407. this.conversationNodeItemList = [];
  408. this.personNodeItemList = [];
  409. var searchConvList = [];
  410. if (value) {
  411. // 搜索会话
  412. searchConvList = this.conversationList.filter((c) => c.title.indexOf(value) > -1 );
  413. //搜索人员
  414. this.searchLoadPerson(value);
  415. } else {
  416. // 还原会话列表
  417. searchConvList = this.conversationList;
  418. }
  419. // 会话列表创建
  420. for (var i = 0; i < searchConvList.length; i++) {
  421. var conversation = searchConvList[i];
  422. var itemNode = this._createConvItemNode(conversation);
  423. this.conversationNodeItemList.push(itemNode);
  424. }
  425. },
  426. searchLoadPerson: function (value) {
  427. var body = {"key": value};
  428. this.searchPersonList = [];
  429. o2.Actions.load("x_organization_assemble_control").PersonAction.listFilterPaging(1, 20, body, function (json) {
  430. if (json.data && json.data instanceof Array) {
  431. this.searchPersonList = json.data || [];
  432. this.personNodeItemList = [];
  433. this.searchPersonTitleNode.classList.remove("none");
  434. this.searchPersonTitleNode.classList.add("block");
  435. for (var i = 0; i < this.searchPersonList.length; i++) {
  436. var person = this.searchPersonList[i];
  437. var personItemNode = this._createPersonItemNode(person);
  438. this.personNodeItemList.push(personItemNode);
  439. }
  440. }
  441. }.bind(this));
  442. },
  443. _createPersonItemNode: function (person) {
  444. var avatarDefault = this._getIcon(person.distinguishedName);
  445. var itemNode = new Element("div", { "class": "item" }).inject(this.searchPersonListNode);
  446. var nodeBaseItem = new Element("div", { "class": "base" }).inject(itemNode);
  447. var avatarNode = new Element("div", { "class": "avatar" }).inject(nodeBaseItem);
  448. new Element("img", { "src": avatarDefault, "class": "img" }).inject(avatarNode);
  449. new Element("div", { "class": "body" , "text": person.name }).inject(nodeBaseItem);
  450. itemNode.store("person", person);
  451. itemNode.addEvents({
  452. "click": function() {
  453. this.clickPersonItem(person)
  454. }.bind(this)
  455. })
  456. return itemNode;
  457. },
  458. clickPersonItem: function (person) {
  459. console.log('点击人员', person);
  460. MWF.require("MWF.widget.Mask", function () {
  461. this.mask = new MWF.widget.Mask({ "style": "desktop", "zIndex": 50000 });
  462. this.mask.loadNode(this.app.content);
  463. var conv = {
  464. type: "single",
  465. personList: [person.distinguishedName],
  466. };
  467. o2.Actions.load("x_message_assemble_communicate").ImAction.create(conv, function (json) {
  468. var newConv = json.data;
  469. this.clickConversationItem(newConv);
  470. if (this.mask) { this.mask.hide(); this.mask = null; }
  471. }.bind(this), function (error) {
  472. console.error(error);
  473. if (this.mask) { this.mask.hide(); this.mask = null; }
  474. }.bind(this));
  475. }.bind(this));
  476. },
  477. //用户头像
  478. _getIcon: function (id) {
  479. var orgAction = MWF.Actions.get("x_organization_assemble_control")
  480. var url = (id) ? orgAction.getPersonIcon(id) : "../x_component_IMV2/$Main/default/icons/group.png";
  481. return url + "?" + (new Date().getTime());
  482. },
  483. // 创建会话Node
  484. _createConvItemNode: function(conversation) {
  485. var avatarDefault = this._getIcon();
  486. var convData = {
  487. "id": conversation.id,
  488. "avatarUrl": avatarDefault,
  489. "title": conversation.title,
  490. };
  491. var distinguishedName = layout.session.user.distinguishedName;
  492. if (conversation.type && conversation.type === "single") {
  493. var chatPerson = "";
  494. if (conversation.personList && conversation.personList instanceof Array) {
  495. for (var j = 0; j < conversation.personList.length; j++) {
  496. var person = conversation.personList[j];
  497. if (person !== distinguishedName) {
  498. chatPerson = person;
  499. }
  500. }
  501. }
  502. convData.avatarUrl = this._getIcon(chatPerson);
  503. var name = chatPerson;
  504. if (chatPerson.indexOf("@") != -1) {
  505. name = name.substring(0, chatPerson.indexOf("@"));
  506. }
  507. convData.title = name;
  508. }
  509. var itemNode = new Element("div", { "class": "item" }).inject(this.conversationListNode);
  510. var nodeBaseItem = new Element("div", { "class": "base" }).inject(itemNode);
  511. var avatarNode = new Element("div", { "class": "avatar" }).inject(nodeBaseItem);
  512. new Element("img", { "src": convData.avatarUrl, "class": "img" }).inject(avatarNode);
  513. new Element("div", { "class": "body" , "text": convData.title }).inject(nodeBaseItem);
  514. itemNode.store("conversation", conversation);
  515. itemNode.addEvents({
  516. "click": function() {
  517. this.clickConversationItem(conversation)
  518. }.bind(this)
  519. })
  520. return itemNode;
  521. },
  522. // 点击会话
  523. clickConversationItem: function(conversation) {
  524. console.log(conversation);
  525. if (this.data.callback ) { // 选择器
  526. this.data.callback(conversation)
  527. } else {
  528. var distinguishedName = layout.session.user.distinguishedName;
  529. var time = this._currentTime();
  530. var bodyJson = JSON.stringify(this.data.msgBody);
  531. var uuid = new MWF.widget.UUID().createTrueUUID();
  532. var textMessage = {
  533. "id": uuid,
  534. "conversationId": conversation.id,
  535. "body": bodyJson,
  536. "createPerson": distinguishedName,
  537. "createTime": time,
  538. "sendStatus": 1
  539. };
  540. o2.Actions.load("x_message_assemble_communicate").ImAction.msgCreate(textMessage,
  541. function (json) {
  542. var options = {
  543. conversationId: conversation.id,
  544. mode: this.options.mode || "default"
  545. }
  546. layout.openApplication(null, "IMV2", options);
  547. }.bind(this),
  548. function (error) {
  549. console.log(error);
  550. this.app.notice(this.lp.msgShareError, "error");
  551. }.bind(this));
  552. }
  553. this.closeConversationListDialog();
  554. },
  555. _currentTime: function () {
  556. var today = new Date();
  557. var year = today.getFullYear(); //得到年份
  558. var month = today.getMonth();//得到月份
  559. var date = today.getDate();//得到日期
  560. var hour = today.getHours();//得到小时
  561. var minu = today.getMinutes();//得到分钟
  562. var sec = today.getSeconds();//得到秒
  563. month = month + 1;
  564. if (month < 10) month = "0" + month;
  565. if (date < 10) date = "0" + date;
  566. if (hour < 10) hour = "0" + hour;
  567. if (minu < 10) minu = "0" + minu;
  568. if (sec < 10) sec = "0" + sec;
  569. return year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
  570. }
  571. });