iPortalBatchAddResource.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_iPortalAddMapOrScene"></title>
  9. <style>
  10. .title-checkbox-container p{
  11. max-width: 150px;
  12. float: left;
  13. }
  14. .title-checkbox-container input{
  15. float: right;
  16. }
  17. #plottingPanel {
  18. float: left;
  19. background: #ffffff;
  20. width: 250px;
  21. height: 100%;
  22. border: 1px solid #3473b7;
  23. }
  24. .datagrid-cell {
  25. word-break: break-all;
  26. white-space: normal!important;
  27. }
  28. .tabs-container ,.tabs-panels,.panel-body{
  29. height: auto!important;
  30. }
  31. .panel-title {
  32. margin-top: 0!important;
  33. margin-bottom: 0!important;
  34. font-size: 16px!important;
  35. color: inherit!important;
  36. }
  37. </style>
  38. </head>
  39. <body style=" margin: 0;overflow: auto;background: #F2F2F2;width: 100%;height:100%;position: absolute;top: 0;">
  40. <!-- 资源过滤 and 资源展示 -->
  41. <div class="container" style="margin-bottom: 100px;">
  42. <div class="page-header">
  43. <h4 id="resourceTypeText" data-i18n="resources.title_iPortalAddMap"></h4>
  44. </div>
  45. <br />
  46. <div class="col-md-12">
  47. <div class="row">
  48. <div class="col-md-12" style="background: #FFF;">
  49. <!--添加资源-->
  50. <div class="row" id="batch-add-resource" style="padding: 10px;">
  51. <h5 data-i18n="resources.title_iPortalQueryResourcesType"></h5>
  52. <select id='typeSelect' class='form-control' onchange="onSelectResourcesType()">
  53. <option value="MAP" data-i18n="resources.title_iPortalQueryResourcesMap"></option>
  54. <option value="SCENE" data-i18n="resources.title_iPortalQueryResourcesScene"></option>
  55. </select>
  56. <h5 data-i18n="resources.text_serviceAddress"></h5>
  57. <span style="position: relative;">
  58. <input id="address" class='form-control' type="text" style="width: 100%;"><i class="fa fa-question-circle question" aria-hidden="true"></i>
  59. </span>
  60. <h5 data-i18n="resources.detail_iPortal_tags"></h5>
  61. <input id="tags" class='form-control' type="text" style="width: 100%;" data-i18n="[placeholder]resources.text_userMap">
  62. <h5 data-i18n="resources.title_share_setting"></h5>
  63. <div>
  64. <form class="form-horizontal">
  65. <fieldset>
  66. <ul class="nav nav-tabs" role="tablist">
  67. <li role="presentation" class="active">
  68. <a href="#public" aria-controls="public" role="tab" data-toggle="tab" data-i18n="resources.title_iPortalQueryResourcesPublic"></a>
  69. </li>
  70. </ul>
  71. <div class="tab-content">
  72. <div role="tabpanel" class="tab-pane active" id="public">
  73. <div class="col-md-4 gallery-item" id="shareCheckboxs">
  74. <div class="publicPane sub-font">
  75. <input id="search" type="checkbox" value="search" onclick="clickSearchCheckBox()" />
  76. &nbsp;<label for="search" data-i18n="resources.text_user_search"></label>
  77. </div>
  78. <div class="publicPane sub-font">
  79. <input id="view" type="checkbox" value="view" onclick="clickViewCheckBox()" />
  80. &nbsp;<label for="view" data-i18n="resources.text_user_view"></label>
  81. </div>
  82. <div class="publicPane sub-font">
  83. <input id="edit" type="checkbox" value="edit" onclick="clickEditCheckBox()" />
  84. &nbsp;<label for="edit" data-i18n="resources.text_user_editor"></label>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. </fieldset>
  90. </form>
  91. </div>
  92. <div><button class="btn btn-primary col-md-offset-6" style="margin-top: 20px;" onclick="addMapOrScene()" data-i18n="resources.btn_OK"></button></div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. <script type="text/javascript" include="jquery,bootstrap,plottingPanel,widgets" src="../js/include-web.js"></script>
  99. <script type="text/javascript" include="iclient-plot-leaflet" src="../../dist/leaflet/include-leaflet.js"></script>
  100. <script type="text/javascript" include="iPortalStylePanel" src="../js/plottingPanel/PlottingPanel.Include.js"></script>
  101. <script>
  102. //iportal的URL地址 或根据情况添加自己的本地iportal地址:http://localhost:8091/iportal
  103. var iPortalUrl = "https://iportal.supermap.io/iportal";
  104. // iptl的admin1用户的token,模拟admin1用户登录状态
  105. var token = "MFEKl8kVmkvEDrDFcgnjodlPCudIO83mBSwvdjiUlWNnySGD-FCEyYEk4CsY2WnSCujfAs8HI0ZkSL6Vxa-njg..";
  106. //默认请求资源类型
  107. var resourceType = "MAP";
  108. //共享设置
  109. var publicSettingEntity = {
  110. "permissionType": "",
  111. "entityType": "USER",
  112. "entityName": "GUEST",
  113. "entityId": null,
  114. "authorizeList": []
  115. }
  116. function getDefaultUrl(){
  117. iPortalUser = new SuperMap.iPortalUser(iPortalUrl);
  118. }
  119. // 注册token
  120. function generatePortalToken() {
  121. let serverInfo = new SuperMap.ServerInfo(SuperMap.ServerType.IPORTAL, {
  122. server: iPortalUrl
  123. });
  124. SuperMap.SecurityManager.registerServers([serverInfo]);
  125. SuperMap.SecurityManager.destroyToken(iPortalUrl);
  126. SuperMap.SecurityManager.registerToken(iPortalUrl, token);
  127. }
  128. // 添加地图/场景
  129. function addMapOrScene() {
  130. generatePortalToken();
  131. iPortalUser = new SuperMap.iPortalUser(iPortalUrl);
  132. let params = new SuperMap.iPortalAddResourceParam({
  133. rootUrl: $("#address").val(),
  134. tags: $("#tags").val(),
  135. entities: getShareEntities()
  136. });
  137. if(resourceType === "MAP") {
  138. iPortalUser.addMap(params).then(res => {
  139. if(res.succeed) {
  140. widgets.alert.showAlert(resources.msg_addSuccess, true);
  141. } else {
  142. widgets.alert.showAlert(resources.msg_addFailed, false);
  143. }
  144. })
  145. }
  146. if(resourceType === "SCENE") {
  147. iPortalUser.addScene(params).then(res => {
  148. if(res.succeed) {
  149. widgets.alert.showAlert(resources.msg_addSuccess, true);
  150. } else {
  151. widgets.alert.showAlert(resources.msg_addFailed, false);
  152. }
  153. })
  154. }
  155. }
  156. function getShareEntities(){
  157. shareSettingList = [];
  158. //公开
  159. addSettingEntity(publicSettingEntity);
  160. return shareSettingList;
  161. }
  162. //生成分享的entities参数
  163. function addSettingEntity(obj){
  164. var settingEntity = dealShareSettingParam(obj);
  165. if(settingEntity){
  166. shareSettingList.push(settingEntity);
  167. }
  168. }
  169. function dealShareSettingParam(obj) {
  170. var authorize = "";
  171. if(!obj.authorizeList){
  172. return null;
  173. }
  174. if(obj.authorizeList.includes("edit")){
  175. authorize = "READWRITE";
  176. }else if(obj.authorizeList.includes("view")){
  177. authorize = "READ";
  178. }else if(obj.authorizeList.includes("download")){
  179. authorize = "DOWNLOAD";
  180. }else if(obj.authorizeList.includes("search")){
  181. authorize = "SEARCH";
  182. }
  183. if(authorize){
  184. if(resourceType === "data") {
  185. obj.dataPermissionType = authorize;
  186. }
  187. obj.permissionType = authorize;
  188. let targetPermissionEntity = Object.assign({},obj);
  189. delete targetPermissionEntity.authorizeList;
  190. delete targetPermissionEntity.aliasName;
  191. delete targetPermissionEntity.entityRoles;
  192. return targetPermissionEntity;
  193. }else {
  194. return null;
  195. }
  196. }
  197. // 选择资源类型
  198. function onSelectResourcesType(){
  199. let type = $("#typeSelect").val();
  200. resourceType = type;
  201. if(resourceType === "MAP") {
  202. $("#resourceTypeText")[0].innerText = resources.title_iPortalAddMap;
  203. } else if(resourceType === "SCENE") {
  204. $("#resourceTypeText")[0].innerText = resources.title_iPortalAddScene;
  205. }
  206. $("#address").val("");
  207. $("#tags").val("");
  208. }
  209. // 点击所有用户可检索
  210. function clickSearchCheckBox(){
  211. if(!publicSettingEntity.authorizeList || (publicSettingEntity.authorizeList).indexOf("search") === -1){
  212. publicSettingEntity.authorizeList = ["search"];
  213. }else {
  214. publicSettingEntity.authorizeList = [];
  215. }
  216. if($("input[value='search']").is(':checked')){
  217. publicSettingEntity.authorizeList.forEach(authorizeListItem=>{
  218. $("input[value='"+authorizeListItem+"']").prop("checked", true);
  219. $("input[value='view']").prop("checked", false);
  220. $("input[value='edit']").prop("checked", false);
  221. })
  222. }else {
  223. $("input[value='search']").prop("checked", false);
  224. $("input[value='view']").prop("checked", false);
  225. $("input[value='edit']").prop("checked", false);
  226. }
  227. }
  228. // 点击所有用户可查看
  229. function clickViewCheckBox(){
  230. if(!publicSettingEntity.authorizeList || (publicSettingEntity.authorizeList).indexOf("view") === -1){
  231. publicSettingEntity.authorizeList = ["search","view"];
  232. }else if((publicSettingEntity.authorizeList).indexOf("search") !== -1){
  233. publicSettingEntity.authorizeList = ["search"];
  234. }
  235. if($("input[value='view']").is(':checked')){
  236. publicSettingEntity.authorizeList.forEach(authorizeListItem=>{
  237. $("input[value='"+authorizeListItem+"']").prop("checked", true);
  238. })
  239. }else {
  240. $("input[value='edit']").prop("checked", false);
  241. }
  242. }
  243. // 点击所有用户可编辑
  244. function clickEditCheckBox(){
  245. if(!publicSettingEntity.authorizeList || (publicSettingEntity.authorizeList).indexOf("edit") === -1){
  246. publicSettingEntity.authorizeList = ["search","view","edit"];
  247. }else if((publicSettingEntity.authorizeList).indexOf("view") !== -1){
  248. publicSettingEntity.authorizeList = ["search","view"];
  249. }
  250. if($("input[value='edit']").is(':checked')){
  251. publicSettingEntity.authorizeList.forEach(authorizeListItem=>{
  252. $("input[value='"+authorizeListItem+"']").prop("checked", true);
  253. })
  254. }
  255. }
  256. </script>
  257. </body>
  258. </html>