wdRecord.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. function wdRecord(bjid) {
  2. try{
  3. //if(true)return;
  4. //回显个人选值数据
  5. if("0"==window.loginStatus)
  6. return;
  7. if(window.wdRecordValue&&!document.querySelector("ssDlg[setPval=false]")){ // ("wdDialog[setValue=。Lin
  8. if(typeof wdRecordValue=="string")
  9. wdRecordValue=eval("("+wdRecordValue+")")
  10. for(var key in wdRecordValue){
  11. // var ele= document.querySelector("[name="+key+"]");
  12. // if(!ele||ele.value)continue;
  13. //
  14. // ele.value=wdRecordValue[key]["value"];
  15. // $(ele).trigger("change")
  16. var box=wd.display.getInputBox(key);
  17. if(!box||box.getValue())continue;
  18. box.setValue(wdRecordValue[key]["value"]);
  19. }
  20. }
  21. if(window.wdRecordValue){
  22. window.wdRecordValue=(typeof wdRecordValue=="object")?window.wdRecordValue: eval("("+wdRecordValue+")")
  23. var thisEle=document.querySelector("[name=wdComponentID]");
  24. var wdComponentID=window.wdRecordValue["wdComponentID"];
  25. if(wdComponentID&&thisEle){
  26. thisEle.value=wdComponentID.value;
  27. }
  28. }
  29. /**
  30. * 根据是否找到wdDialogId判断当前页面在弹窗中或应用页面
  31. *
  32. */
  33. var wdDialogId = wd.display.getwdDialogId();
  34. //当前窗口在弹出窗口中
  35. if(wdDialogId){
  36. var win=wd.topWindow.dhxWins.window(wdDialogId);
  37. var allWindows= wd.display.getwdDialogWindowObjects(wdDialogId);
  38. var targetWindows=[];
  39. for(var i=0;i<allWindows.length;i++){
  40. if(!allWindows[i].document.querySelector("ssDlg[setPval=false]")){ // ("wdDialog[setValue=。Lin
  41. targetWindows.push(allWindows[i]);
  42. }
  43. }
  44. if(targetWindows.length>0){
  45. win.button("wdRecord").show();
  46. win.button("wdRecord_save").hide();
  47. //编辑个人选值和保存个人选值切换
  48. win.button("wdRecord").onclick = function() {
  49. for(var i=0;i<targetWindows.length;i++){
  50. try{
  51. targetWindows[i].wd.record.show();
  52. }catch(e){
  53. console.log(e);
  54. }
  55. }
  56. win.button("wdRecord").hide();
  57. win.button("wdRecord_save").show();
  58. }
  59. win.button("wdRecord_save").onclick = function() {
  60. for(var i=0;i<targetWindows.length;i++){
  61. try{
  62. targetWindows[i].wd.record.hide();
  63. }catch(e){
  64. console.log(e);
  65. }
  66. }
  67. win.button("wdRecord_save").hide();
  68. win.button("wdRecord").show();
  69. }
  70. }else if(win.button("wdRecord")){
  71. win.button("wdRecord").onclick=null;
  72. win.button("wdRecord").hide();
  73. win.button("wdRecord_save").hide();
  74. }
  75. }else if(wd.topWindow.wdRecordIcon){
  76. if(!document.querySelector("ssDlg[setPval=false]")){ // ("wdDialog[setValue=。Lin
  77. wd.topWindow.wdRecordIcon.style.display=""
  78. // var className= wd.topWindow.wdRecordIcon.getAttribute("class");
  79. var settingClass="largeIcon-set";
  80. var okClass="largeInvertIcon-save";
  81. wd.topWindow.wdRecordIcon.parentNode.setAttribute("class",settingClass);
  82. // largeIcon-set invertIcon-save
  83. // if(/.*\_save/.test(className)){
  84. // wd.topWindow.wdRecordIcon.setAttribute("class",className.replace(/\_save/,""))
  85. // }else{
  86. //
  87. // }
  88. //表示当前是编辑或是保存按钮
  89. wd.topWindow.wdRecordIcon.isSaveButton=false;
  90. wd.topWindow.wdRecordIcon.onclick=function(){
  91. var thiswindow=wd.topWindow.wd.base.applyIframeElement.contentWindow;
  92. while(thiswindow){
  93. try{
  94. if(this.isSaveButton){
  95. thiswindow.wd.record.hide();
  96. this.isSaveButton=false;
  97. wd.topWindow.wdRecordIcon.parentNode.setAttribute("class",settingClass);
  98. }else{
  99. thiswindow.wd.record.show();
  100. this.isSaveButton=true;
  101. wd.topWindow.wdRecordIcon.parentNode.setAttribute("class",okClass);
  102. }
  103. }catch(e){
  104. console.error(e);
  105. }
  106. var iframe= thiswindow.document.querySelector("iframe");
  107. thiswindow=iframe?iframe.contentWindow:null;
  108. }
  109. }
  110. }
  111. // else if(win&&win.button("wdRecord")){
  112. // wd.topWindow.wdRecordIcon.onclick=null;
  113. // wd.topWindow.wdRecordIcon.style.display="none";
  114. //
  115. // win.button("wdRecord").hide();
  116. // }
  117. }
  118. }catch(e){
  119. console.log(e)
  120. }
  121. }
  122. wd.record={
  123. dialogClassName:"wdRecord"
  124. ,
  125. secondClick:false
  126. ,
  127. wdRecordValue:{}
  128. ,
  129. /*
  130. * 第一次点击:设置个人选值,第二次:点击保存
  131. */
  132. show: function(div){
  133. if(document.querySelectorAll(("ssDlg[setPval=false]")).length==1){ // (("wdDialog[setValue=。Lin
  134. alert("无法设置个人选值!");
  135. return ;
  136. }
  137. var wdRecordList=this.findWdRecord();
  138. if(wdRecordList.length==0){
  139. console.log("找不到元素设置个人选值")
  140. return;
  141. }
  142. // if(this.findDialog().length>0){//第二次点击
  143. // this.hide();
  144. // return;
  145. // }
  146. if(window.wdRecordValue){
  147. this.wdRecordValue=(typeof wdRecordValue=="object")?wdRecordValue: eval("("+wdRecordValue+")")
  148. }
  149. for(var key in wdRecordList){
  150. this.showDialog(wdRecordList[key])
  151. }
  152. }
  153. ,
  154. hide:function(){
  155. var recordZhi=this.getRecordData();
  156. // if(!document.querySelector("#wdComponentID"))return;
  157. // console.log(recordZhi)
  158. // var bjid= document.getElementsByName("wdComponentID")[0].value
  159. this.insertRecordsService(recordZhi);
  160. this.removeDialog()
  161. }
  162. ,
  163. showDialog:function(inputbox){
  164. var ele=inputbox.container;
  165. if(!ele)return;
  166. var eleName=inputbox.name
  167. var topDoc = window.document;
  168. var chartDiv =$("<div class=\""+this.dialogClassName+"\" style='display: inline-block; position: absolute;z-index:1;'></div>")
  169. var status="0";
  170. if(this.wdRecordValue[eleName]){
  171. status=("true"==this.wdRecordValue[eleName].default)?"1":"2";
  172. }
  173. var rule={"0":{class:"icon-empty",status:"0",next:"1",title:"未启用"},
  174. "1":{class:"icon-warningFull",status:"1",next:"2",title:"填左边录入的值"},
  175. "2":{class:"icon-copy",status:"2",next:"0",title:"填上次录入的值"}}
  176. $(chartDiv).html("<div title=\""+rule[status].title+"\" status=\""+status+"\" wdrecordcheckbox=\"true\" class=\""+rule[status].class+"\" style=\"display: inline-block; position: absolute;\"></div>")
  177. $(ele).after(chartDiv);
  178. chartDiv.css({width:chartDiv.children().css("width"),height:chartDiv.children().css("height")})
  179. chartDiv[0].inputbox=inputbox;
  180. // var bounding=ele.getBoundingClientRect();
  181. // var $p=$(ele).parents().filter(function(){
  182. // if($(this).css("position")=="relative"|| $(this).css("position") == "absolute"|| $(this).css("position") == "fixed")return true;
  183. // }).first()
  184. // var $p=$(ele).offsetParent();
  185. // if($p.length==0)$p=null
  186. //
  187. // var chartDivWidth=chartDiv.width();
  188. // var chartDivHeight=chartDiv.height();
  189. // var pbounding=$p? $p[0].getBoundingClientRect():null;
  190. //
  191. // chartDiv.css("left" ,(bounding.width+bounding.left-(pbounding?pbounding.left:0) )+"px")
  192. // chartDiv.css("top" ,(bounding.top-(pbounding?pbounding.top:0)+(bounding.height-chartDivHeight)*0.5)+"px")
  193. var pos=$(ele).position();
  194. var bounding=ele.getBoundingClientRect();
  195. console.log(pos.left+bounding.width);
  196. chartDiv.css("left",pos.left+bounding.width)
  197. chartDiv.css("top",pos.top+(bounding.height-bounding.height)*0.5)
  198. var leftx=chartDiv.offset().left+chartDiv.width()-$(window).width();
  199. if(leftx>0){
  200. chartDiv.animate({left:"-="+leftx});
  201. }
  202. $(chartDiv).on("click","[wdrecordcheckbox=true]",function(){
  203. var thisstatus= $(this).attr("status");
  204. var nextrule=rule[rule[thisstatus].next];
  205. $(this).attr("class","").addClass(nextrule.class).attr("title",nextrule.title).attr("status",nextrule.status);
  206. })
  207. },
  208. recursionIframe:function(win){
  209. if(win.parent==top&&win.parent==win){
  210. // var xy = this.getAbsPoint(win);
  211. return {"x": 0, "y": 0 , "w" : 0 , "h" : 0 };
  212. }
  213. var winPar = win.parent;// .opener
  214. var iframeArr = winPar.document.getElementsByTagName('IFRAME');
  215. var targetIframe;
  216. for(var i=0;i<iframeArr.length;i++){
  217. var iframeElem = iframeArr[i];
  218. if(iframeElem.contentWindow==win){
  219. targetIframe = iframeElem;
  220. break;
  221. }
  222. }
  223. // alert(targetIframe==null)
  224. // var xy = this.getAbsPoint(targetIframe);
  225. var xy={x:this.getLeft(targetIframe),y:this.getTop(targetIframe)}
  226. if(winPar.parent!=winPar){
  227. var xy2 =this.recursionIframe(winPar);
  228. xy.x += xy2.x;
  229. xy.y += xy2.y;
  230. }
  231. return xy
  232. }
  233. ,
  234. getTop: function (e){
  235. var offset=e.offsetTop;
  236. if(e.offsetParent!=null) offset+=this.getTop(e.offsetParent);
  237. return offset;
  238. }
  239. ,
  240. getLeft:function (e){
  241. var offset=e.offsetLeft;
  242. if(e.offsetParent!=null) offset+=this.getLeft(e.offsetParent);
  243. return offset;
  244. }
  245. ,
  246. /*
  247. * 返回页面所有带wdRecord="true"的元素
  248. */
  249. findWdRecord:function(){
  250. var wdRecordList=[]
  251. var groups= wd.display.getInputsGroups();
  252. for(var key in groups){
  253. if("ueditor"==groups.type||"onoffbutton"==groups.type)
  254. continue;
  255. wdRecordList.push(groups[key])
  256. }
  257. return wdRecordList;
  258. }
  259. ,findDialog:function(){
  260. return document.getElementsByClassName(this.dialogClassName)
  261. }
  262. /*删除勾选框*/
  263. ,removeDialog:function(){
  264. while(this.findDialog().length>0){
  265. var record={}
  266. var removeEle= this.findDialog()[0];
  267. // console.log(removeEle.record)
  268. removeEle.parentNode.removeChild(removeEle)
  269. }
  270. }
  271. ,
  272. /*获得部件ID:bjid */
  273. getBjid:function(){
  274. var con=document.getElementsByName("wdComponentID");
  275. if(con.length==0)return;
  276. return con[0].value;
  277. }
  278. /*根据勾选框+元素值生成数据 */
  279. ,getRecordData:function(){
  280. var recordZhi={};
  281. var cancelZhi={};//删除
  282. if(window.wdRecordValue&&typeof wdRecordValue=="string"){
  283. recordZhi=eval("("+wdRecordValue+")")
  284. }else if(window.wdRecordValue&&typeof wdRecordValue=="object"){
  285. recordZhi=wdRecordValue;
  286. }
  287. console.log(recordZhi);
  288. var dialogList=this.findDialog();
  289. // {"nrid": {value:"440120001400",defualt:true},"bt":{"nrid": {value:"标题",defualt:false} }
  290. for(var i=0;i<dialogList.length;i++){
  291. var inputbox=dialogList[i].inputbox;
  292. var recordName=inputbox.name;
  293. var recordValue=inputbox.getValue();
  294. var status=dialogList[i].querySelector("[wdrecordcheckbox=true]").getAttribute("status");
  295. //value空清除选值
  296. recordZhi[recordName]={value:(status=="0")?"":recordValue,default:("1"==status?true:false)}
  297. }
  298. return recordZhi;
  299. }
  300. ,
  301. insertRecordsService:function(recordZhi){
  302. var THIS=this;
  303. var token;
  304. var ps=window.location.href.replace(/.*\?/,"").split("&");
  305. for(var i=0;i<ps.length;i++){
  306. if(ps[i].indexOf("ssToken=")>-1){ // ("token=")>。Lin
  307. token=ps[i].replace("ssToken\=",''); // ("token\=",。Lin
  308. break;
  309. }
  310. }
  311. // if(!THIS.getBjid()){
  312. // console.log("找不到bjid!")
  313. // return;
  314. // }
  315. $.ajax({
  316. type:"post",
  317. url:"/service?ssServ=insertRecords",
  318. async:true,
  319. data:{
  320. // bjid:THIS.getBjid(),
  321. zhi:JSON.stringify(recordZhi),
  322. tokenstring:token
  323. },
  324. success:function(data){
  325. // alert(data)
  326. THIS.removeDialog()
  327. },error:function(){
  328. alert("保存选值失败")
  329. }
  330. });
  331. }
  332. }