瀏覽代碼

项目管理,项目跳转url设置,日期格式化

MaiXinRong 8 年之前
父節點
當前提交
e0f3257ee7
共有 7 個文件被更改,包括 2727 次插入66 次删除
  1. 5 27
      modules/pm/models/project.js
  2. 21 0
      public/dateUtil.js
  3. 13 0
      server.js
  4. 2627 0
      web/main/html/main.html
  5. 1 1
      web/pm/html/project-management.html
  6. 45 0
      web/pm/js/pm_main.js
  7. 15 38
      web/scripts/tree_table.js

+ 5 - 27
modules/pm/models/project.js

@@ -2,41 +2,19 @@
  * Created by Mai on 2017/1/18.
  */
 
-// 对Date的扩展,将 Date 转化为指定格式的String
-// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
-// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
-// 例子:
-// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
-// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
-Date.prototype.Format = function (fmt) {
-    var o = {
-        "M+": this.getMonth() + 1, //月份
-        "d+": this.getDate(), //日
-        "h+": this.getHours(), //小时
-        "m+": this.getMinutes(), //分
-        "s+": this.getSeconds(), //秒
-        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
-        "S": this.getMilliseconds() //毫秒
-    };
-    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
-    for (var k in o)
-        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
-    return fmt;
-};
-
 var db = require('../db/pm_db');
 var Schema = db.mongoose.Schema;
 var ProjectSchema = new Schema({
     "name": String,
     "projType": String,
-    "lastDateTime": String,
-    "createDateTime": String,
+    "lastDateTime": Date,
+    "createDateTime": Date,
     "id": Number,
     "parentId": Number,
     "nextId": Number,
     "userId": Number,
     "deleted": Boolean,
-    'deleteDateTime': String,
+    'deleteDateTime': Date,
     'deleteFullFolder': Array
 });
 
@@ -85,12 +63,12 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
             } else if (data.updateType === 'new') {
                 data.updateData['userId'] = userId;
                 if (data.updateData.projType === 'Tender') {
-                    data.updateData['createDateTime'] = new Date().Format("yyyy-MM-dd");
+                    data.updateData['createDateTime'] = new Date();
                 }
                 newProject = new Projects(data.updateData);
                 newProject.save(updateAll);
             } else if (data.updateType === 'delete') {
-                data.updateData['deleteDateTime'] = new Date().Format("yyyy-MM-dd");
+                data.updateData['deleteDateTime'] = new Date();
                 Projects.update({userId: userId, id: data.updateData.id}, data.updateData, updateAll);
             }
         }

+ 21 - 0
public/dateUtil.js

@@ -0,0 +1,21 @@
+// 对Date的扩展,将 Date 转化为指定格式的String
+// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
+// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
+// 例子:
+// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
+// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
+Date.prototype.Format = function (fmt) {
+    var o = {
+        "M+": this.getMonth() + 1, //月份
+        "d+": this.getDate(), //日
+        "h+": this.getHours(), //小时
+        "m+": this.getMinutes(), //分
+        "s+": this.getSeconds(), //秒
+        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
+        "S": this.getMilliseconds() //毫秒
+    };
+    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
+    for (var k in o)
+        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
+    return fmt;
+};

+ 13 - 0
server.js

@@ -39,6 +39,19 @@ app.use('/', users);
 var pmRouter = require('./modules/pm/routes/pm_route');
 app.use('/', pmRouter);
 
+app.get('/main',  function(req, res) {
+    if (!req.session.userAccount) {
+        res.redirect('/login');
+    }
+    else {
+        res.render('main/html/main.html',
+            {
+                userAccount: req.session.userAccount,
+                userID: req.session.userID
+            });
+    }
+});
+
 var apiRouter = express.Router();
 
 app.use('/api', apiRouter);

File diff suppressed because it is too large
+ 2627 - 0
web/main/html/main.html


+ 1 - 1
web/pm/html/project-management.html

@@ -455,6 +455,7 @@
     <script src="lib/tether/tether.min.js"></script>
     <script src="lib/bootstrap/bootstrap.min.js"></script>
     <script src="lib/global.js"></script>
+    <script src="public/dateUtil.js"></script>
     <script src="web/scripts/tree_table.js"></script>
     <script src="web/pm/js/pm_ajax.js"></script>
     <script src="web/pm/js/pm_main.js" charset="UTF-8"></script>
@@ -577,5 +578,4 @@
 <script type="text/javascript">
     autoFlashHeight();
 </script>
-
 </html>

+ 45 - 0
web/pm/js/pm_main.js

@@ -1,8 +1,53 @@
 /**
  * Created by Mai on 2017/2/24.
  */
+
 var Tree = null, movetoZTree = null, copytoZTree = null;
 var ProjTreeSetting = {
+    columns: [
+        {
+            head: '',
+            data: '',
+            static: true,
+            width: '40',
+            event: {}
+        },
+        {
+            head: '工程列表',
+            data: 'name',
+            static: false,
+            width: '78%',
+            event: {
+                getUrl: function (node) {
+                    if (node && node.data && node.data.projType === 'Tender') {
+                        return '/main?project='+node.id();
+                    }
+                }
+            }
+        },
+        {
+            head: '最近使用',
+            data: 'lastDateTime',
+            static: false,
+            width: '10%',
+            event: {
+                textFormat: function (date) {
+                    return date ? new Date(date).Format('yyyy-MM-dd') : '';
+                }
+            }
+        },
+        {
+            head: '创建日期',
+            data: 'createDateTime',
+            static: false,
+            width: '10%',
+            event: {
+                textFormat: function (date) {
+                    return date ? new Date(date).Format('yyyy-MM-dd') : '';
+                }
+            }
+        }
+    ],
     viewEvent: {
         beforeSelect: function (node) {
             if (node && node.row) {

+ 15 - 38
web/scripts/tree_table.js

@@ -14,33 +14,11 @@
  		},
  		columns: [
  		{
- 			head: '',
- 			data: '<i class="fa fa-sort" data-toggle="tooltip" data-placement="top" title="长安拖动"></i>',
- 			static: true,
- 			width: '40'
- 		},
- 		{
  			head: '工程列表',
  			data: 'name',
  			static: false,
- 			width: '78%',
-			url: '/tender',
-			urlParam: [{
-				name: 'id',
-				value: 'id'
-			}]
- 		},
- 		{
- 			head: '最近使用',
- 			data: 'lastDateTime',
- 			static: false,
- 			width: '10%'
- 		},
- 		{
- 			head: '创建日期',
- 			data: 'createDateTime',
- 			static: false,
- 			width: '10%'
+ 			width: '100%',
+            event: {}
  		}
  		],
  		dataTemp: {
@@ -461,7 +439,7 @@
  			return span;
  		},*/
  		_makeTableRowCell: function (obj, node, columns, index) {
- 			var html = [], td, i;
+ 			var html = [], td, i, url;
 
  			html.push('<td ');
  			if (index === node.setting.tree.btnColumn){
@@ -493,18 +471,18 @@
     				html.push('&nbsp;');
                 }
 				html.push('<a ');
-				if (columns.url) {
-					html.push('href="', columns.url);
-					if (columns.urlParam){
-						html.push('?');
-						columns.urlParam.forEach(function(item){
-							html.push(item.name, '=', node.data[item.value]);
-						})
-					}
-					html.push('"');
-				}
+                if (columns.event.getUrl) {
+                    url = columns.event.getUrl(node);
+                    if (url) {
+                        html.push('href="', url, '"')
+                    }
+                }
 				html.push('>');
-				html.push(node.data[columns.data]);
+                if (columns.event.textFormat) {
+                    html.push(columns.event.textFormat(node.data[columns.data]));
+                } else {
+                    html.push(node.data[columns.data]);
+                }
 				html.push('</a>');
  			}
  			html.push('</td>');
@@ -535,7 +513,6 @@
  			tr.attr('id', node.domId());
  			node.row = tr;
  			_view._makeTableRowCells(tr, node);
-            //tr.click(_event._selectProj(node));
  			tr.click(function(){
                 _event._selectProj(node);
  			});
@@ -558,7 +535,7 @@
  			});	*/
  			return tr;
  		},
-        _moveRowDomBefore(node, destination) {
+        _moveRowDomBefore: function (node, destination) {
             var moveNodesRowDomBefore = function (nodes) {
                 nodes.forEach(function (node) {
                     node.row.insertBefore(destination);