管理表单示例

管理表单示例

image

目录结构:

image

index.html:

<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>index</title>
    <link rel="stylesheet" href="../vendor/bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" href="index.css">

    <script src="../vendor/bootstrap3/js/jquery.js"></script>
    <script src="../vendor/bootstrap3/js/bootstrap.js"></script>
    <script src="../vendor/bootstrap3/js/angular.js"></script>
    <script src="index.js"></script>
</head>
<body ng-controller="ctrl">

<div>
    <table id="clusterTable" class="table table-bordered table-hover">
        <thead>
        <tr>
            <th>序号</th>
            <th>集群名称</th>
            <th>创建者</th>
            <th>创建时间</th>
            <th>状态信息</th>
            <th>查看详情</th>
        </tr>
        </thead>

        <tbody>
        <tr ng-repeat="item in clusterGroups">
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>{{item.owner}}</td>
            <td>{{item.date}}</td>
            <td>{{item.state}}</td>
            <td style="width: 300px; text-align: center">
                <button class="btn btn-success">启动全部</button>
                <button class="btn btn-danger">停止全部</button>
                <slide-down></slide-down>
            </td>
        </tr>
        </tbody>
    </table>
</div>

</body>
</html>

index.js:

(function () {
    angular
        .module("app", [])
        .controller("ctrl", ["$scope", "$http", function ($scope, $http) {
            $scope.clusterGroups = [];
            $http.get("./clusterGroups.json").then(
                function (res) {
                    $scope.clusterGroups = res.data;
                },
                function (res) {
                    console.log(res);
                }
            )
        }])
        .directive("slideDown", function ($compile) {
            return {
                restrict: 'AE',
                replace: true,
                template: `<button class="btn btn-primary" ng-click="showDetails()">展开集群</button>`,
                link: function (scope, element, attributes, controller) {
                    let html = `<cluster-details item-id="item.id"></cluster-details>`;

                    element.tog = false;
                    scope.showDetails = function () {
                        if (element.tog === false) {
                            $(element).children("button").text("折叠集群");
                            $(element).parent().parent().after($compile(html)(scope));
                            element.tog = true;
                        } else {
                            $(element).children("button").text("展开集群");
                            $(element).parent().parent().next().remove();
                            element.tog = false;
                        }
                    }
                }
            }
        })
        .directive("clusterDetails", ["$http", function ($http) {
            return {
                restrict: 'AE',
                replace: true,
                scope: {
                    itemId: "=itemId"
                },
                templateUrl: "./clusterDetails.html",
                link: function (scope, element, attributes, controller) {
                    scope.cluster = [];
                    $http.get("./cluster/cluster_" + scope.itemId + ".json").then(
                        function (res) {
                            scope.cluster = res.data;
                        },
                        function (res) {
                            console.log(res);
                        }
                    );
                }
            }
        }])
})();

clusterDetails.html:

<tr>
    <td colspan="100" style="padding: 5px; background-color: #efefef;">
        <table class="table table-bordered table-hover" style="width: 100%; margin: 0;">
            <thead>
            <tr>
                <th>序号</th>
                <th>地址</th>
                <th>端口</th>
                <th>目录</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="item in cluster">
                <td>{{item.id}}</td>
                <td>{{item.ip}}</td>
                <td>{{item.port}}</td>
                <td>{{item.dir}}</td>
                <td>{{item.state}}</td>
                <td style="width: 200px; text-align: center">
                    <button class="btn btn-success">启动</button>
                    <button class="btn btn-danger">停止</button>
                    <button class="btn btn-primary">命令</button>
                </td>
            </tr>
            </tbody>
        </table>
    </td>
</tr>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1 Webpack 1.1 概念简介 1.1.1 WebPack是什么 1、一个打包工具 2、一个模块加载工具 3...
    Kevin_Junbaozi阅读 6,787评论 0 16
  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,022评论 3 119
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,824评论 1 45
  • 2017年3月22日中午1点,对于我来说是个值得纪念的日子,在这个地球上生长了24年,第一次被狗咬,还是一个只有四...
    蹲在墙角等月亮阅读 419评论 0 0
  • 不要为不值得的人做太多,不是因为不够爱,而是爱过了自己能够承受的范围却又无法得到回报,反而是作践自己。 这种犯贱的...
    昏钝年华阅读 357评论 0 2