badgeConfig.jsp 11.7 KB
<%@page import="com.weaver.formmodel.gateway.bean.Api" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="com.weaver.formmodel.gateway.bean.ApiGroup" %>
<%@ page import="com.weaver.formmodel.gateway.service.ApiGroupManager" %>
<%@ page import="com.weaver.formmodel.gateway.service.ApiManager" %>
<%@ page import="com.weaver.formmodel.mobile.manager.MobileAppBaseManager" %>
<%@ page import="com.weaver.formmodel.mobile.model.MobileAppBaseInfo" %>
<%@ page import="com.weaver.formmodel.util.StringHelper" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="weaver.servicefiles.DataSourceXML" %>
<%@ include file="/mobilemode/admin/init.jsp" %>
<%
    response.setHeader("cache-control", "no-cache");
    response.setHeader("pragma", "no-cache");
    response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");

    int appid = Util.getIntValue(Util.null2String(request.getParameter("appid")));
    MobileAppBaseInfo mobileAppBaseInfo = MobileAppBaseManager.getInstance().getMobileAppBaseInfoById(appid);
    String type = "";
    String sql = "";
    String datasource = "";

    String apiConfigStr = "";
    JSONObject outFormat = null;
    JSONObject apiConfig = null;

    if (mobileAppBaseInfo != null) {
        String badgeConfig = StringHelper.null2String(mobileAppBaseInfo.getBadgeconfig(), "{}");

        JSONObject badge = JSONObject.fromObject(badgeConfig.replaceAll(""", "\""));
        type = badge.containsKey("remindtype") ? badge.getString("remindtype") : "1";
        sql = badge.containsKey("remindsql") ? badge.getString("remindsql") : "";
        datasource = badge.containsKey("reminddatasource") ? badge.getString("reminddatasource") : "";
        apiConfigStr = badge.containsKey("remindapiconfig") ? badge.getString("remindapiconfig") : "";

        if (!"".equals(apiConfigStr)) {
            try {
                JSONObject apiConfigObj = JSONObject.fromObject(apiConfigStr);
                apiConfig = (JSONObject) apiConfigObj.get("apiConfig");
                outFormat = (JSONObject) apiConfigObj.get("outFormat");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        apiConfig = (apiConfig == null ? JSONObject.fromObject("{api: {},params: {query: [],body: {}}}") : apiConfig);
        outFormat = (outFormat == null ? JSONObject.fromObject("{}") : outFormat);
    }
    DataSourceXML dataSourceXML = new DataSourceXML();
    List pointArrayList = dataSourceXML.getPointArrayList();

    JSONObject selApi = apiConfig.getJSONObject("api");

    String apiId =selApi.containsKey("id") ? selApi.getString("id") : "";
    List<Api> apiList = ApiManager.getInstance().listApi("", "", "");
    List<ApiGroup> apiGroups = ApiGroupManager.getInstance().listApiGroup("");
    JSONObject group = new JSONObject();
    for(ApiGroup g : apiGroups){
        group.put(g.getId(), g.getName());
    }
    JSONObject apis = new JSONObject();
    for(Api a : apiList){
        apis.put(a.getId(), a);
    }

%>
<html>
<head>
    <title></title>
    <link type="text/css" rel="stylesheet" href="/mobilemode/admin/src/common/css/common.css">
    <link type="text/css" rel="stylesheet" href="/mobilemode/admin/src/appdesigner/appDesigner.css">
    <script type="text/javascript" src="/formmode/js/jquery/jquery-1.8.3.min_wev8.js"></script>
    <style>
        body {
            background: none;
        }
        select.form-control {
            appearance: menulist-button;
            -webkit-appearance: menulist-button;
            -moz-appearance: menulist-button;
        }
        .valueContent {
            display: none;
        }

        .area-control {
            height: 100px;
        }

        .col-m-8 {
            position: relative;
        }

        .helper {
            display: none;
            position: absolute;
            right: 5px;
            top: 5px;
            width: 14px;
            height: 14px;
            background: #666;
            border-radius: 3px;
            color: #fff;
            text-align: center;
            font-size: 14px;
            font-family: Arial;
            line-height: 14px;
            cursor: pointer;
        }

        .helper:hover {
            background: #999;
        }

        #tabs li {
            float: left;
            margin-right: 10px;
            padding: 0px 16px;
            line-height: 34px;
            font-size: 14px;
            color: #999;
            height: 34px;
            box-sizing: border-box;
            cursor: pointer;
        }

        #tabs li.selected {
            border-bottom: 2px solid #017afd;
            color: #017afd;
        }
    </style>
    <script type="text/javascript">
        var apiConfig = <%=apiConfig%>;
        var apiResultKey = '<%=Util.null2String(outFormat.get("DATAS"))%>';

        var apis = <%=apis%>;
        $(function () {

            var type = <%=type%>;
            var $cbObj;
            if (type != 3) {
                $cbObj = $("input[type='checkbox'][name='type'][value='<%=type%>']");
            } else {
                $cbObj = $("input[type='checkbox'][name='type'][value='1']");
            }
            if ($cbObj.length > 0) {
                $cbObj.attr("checked", "checked");
                $cbObj.triggerHandler("click");
            }

            $("#api-name").change(function(){

              var apiId = $("#api-name").val();
              var api = apis[apiId] || {};
              apiConfig = {api: {
                  id: api.id || "",
                  path: api.frontPath && "/mobilemode/api" + api.frontPath || ""
                },params: {query: api.frontParameters,body: {}}}
            });

            require(["switcher"], function () {
                $(".p-property").switcher();
            });

            require(["modal"], function (modal) {
                $(".helper").on("click", function (e) {
                    modal.tips("SQL <%=SystemEnv.getHtmlLabelName(127577,user.getLanguage())%></br><%=SystemEnv.getHtmlLabelName(24533,user.getLanguage())%>:{curruser},<%=SystemEnv.getHtmlLabelName(126029,user.getLanguage())%>:{currdept},<%=SystemEnv.getHtmlLabelName(31131,user.getLanguage())%>:{currdate},<%=SystemEnv.getHtmlLabelName(25130,user.getLanguage())%>:{currtime},<%=SystemEnv.getHtmlLabelName(141,user.getLanguage())%>:{currdeptsub},<%=SystemEnv.getHtmlLabelName(82281,user.getLanguage())%>:{currdatetime}", $(this), {
                        area: ['250px', ''],
                        placement: "left"
                    });
                    e.stopPropagation();
                });

                $("body").on("click", function (e) {
                    var $target = $(e.target);
                    var layero = $target.parents(".layui-layer-tips");

                    if (layero.length) return;

                    modal.closeAll('tips');
                });
            });

            $(".codeDelFlag").click(function (e) {
                if (confirm("<%=SystemEnv.getHtmlLabelName(127574,user.getLanguage())%>")) {   //确定删除吗?
                    $("#javafilename_span").html("");
                    $("#javafilename").val("");
                    $(".codeDelFlag").hide();
                }
                e.stopPropagation();
            });
        });

        function fiexdUndefinedVal(v, defV) {
            if (typeof (v) == "undefined" || v == null) {
                if (defV) {
                    return defV;
                } else {
                    return "";
                }
            }
            return v;
        }

        function changeSCT(cbObj) {
            setTimeout(function () {	//checkbox用了插件,不延时checkbox的checked状态获取不准确
                var objV = cbObj.value;
                $(".valueContent").hide();
                $("#valueDiv_" + objV).show();
            }, 100);
        }

        //回调函数
        function receiveMessageFromIndex(event) {
            var remindtype = $("input[type='checkbox'][name='type']:checked").val();

            var api = {
                apiConfig: apiConfig,
                outFormat: {DATAS: $("#api-resultkey").val() || ""}
            }

            var result = {
                remindtype: remindtype,
                remindsql: $("#sql").val(),
                reminddatasource: $("#dataSource").val(),
                remindapiconfig: api
            };

            parent.postMessage(JSON.stringify(result), '*'); //window.postMessage
            window.removeEventListener("message", receiveMessageFromIndex, false);
        }

        //监听message事件
        window.addEventListener("message", receiveMessageFromIndex, false);
    </script>
</head>
<body>
<div style="padding: 0px 18px;" class="p-property">
    <div id="form-group-num" class="form-group">
        <div class="row">
            <span class="col-2 span-control"><%=SystemEnv.getHtmlNoteName(4185, user.getLanguage())%></span>
            <div class="col-m-8">
                <div class="multi-switch">
					<span>
						<input type="checkbox" name="type" value="1" onclick="changeSCT(this);"/><span class="cbboxLabel">SQL</span>
					</span>
                    <span>
						<input type="checkbox" name="type" value="4" onclick="changeSCT(this);"/><span
                            class="cbboxLabel"><%=SystemEnv.getHtmlNoteName(5268, user.getLanguage())%></span><!-- 接口 -->
					</span>
                </div>
            </div>
        </div>
        <div id="valueDiv_1" class="valueContent">
            <div class="row">
                <span class="col-2 span-control"></span> <!-- 数据源: -->
                <div class="col-m-8">
                    <select id="dataSource" class="form-control">
                        <option value="">(local)</option>
                        <%
                            for (int i = 0; pointArrayList != null && i < pointArrayList.size(); i++) {
                                String pointid = Util.null2String(pointArrayList.get(i));
                        %>
                        <option value="<%=pointid%>" <%if(datasource.equals(pointid)){%>selected<%}%>><%=pointid%>
                        </option>
                        <% } %>
                    </select>
                </div>
            </div>

            <div class="row">
                <span class="col-2 span-control">SQL:</span>
                <div class="col-m-8">
                    <textarea id="sql" name="sql" class="area-control" placeholder="<%=SystemEnv.getHtmlLabelName(383347,user.getLanguage())%>"><%=sql %></textarea>
                    <!-- 请在此处输入SQL语句查询一个具体的数值 -->
                    <div class="helper" for="sql">?</div>
                </div>
            </div>
        </div>
        <div id="valueDiv_4" class="valueContent">
            <div class="row">
                <div class="col-2 span-control"><%=SystemEnv.getHtmlNoteName(5239, user.getLanguage())%>
                </div><!-- 接口配置: -->
                <div class="col-m-8">
                        <select id="api-name" class="form-control">
                            <option value="">
                            </option>
                            <%
                                for (int i = 0; apiList != null && i < apiList.size(); i++) {
                                    Api a = apiList.get(i);
                                    String groupName = group.getString(a.getGroupid());

                                    groupName = StringHelper.isEmpty(groupName) ? "" : "-" + groupName;
                            %>
                            <option value="<%=a.getId()%>" <%if(apiId.equals(a.getId())){%>selected<%}%>><%=a.getName()%><%=groupName%>
                            </option>
                            <% } %>
                        </select>
                </div>
        </div>
    </div>
    </div>
</div>
</body>
</html>