Base.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. //保存z-index
  2. var z_index = 1;
  3. //部门服务地址
  4. var depSrv = "http://" + window.location.host + "/SysMain/Setting/DepSrv.aspx";
  5. //用户服务地址
  6. var UserSrv = "http://" + window.location.host + "/SysMain/Setting/UserSrv.aspx";
  7. //主窗口数据地址
  8. var MainOp = "http://" + window.location.host + "/SysMain/MainOp.xml";
  9. //构造 功能窗口式DIV
  10. function ActionDiv(action, id, title) {
  11. var divStr = "<div class=\"Action_Box\" isClose=\"f\" id=\"" + action + id + "\"><div class=\"Box_info\">" + title + "<div class=\"Box_Close\">关闭</div></div><div class=\"Action_Box_Content\" id=\"" + action + "_Con_" + id + "\"></div></div>";
  12. $("body").append(divStr);
  13. var divId = "#" + action + id;
  14. $(divId).css("z-index", "99999");
  15. $(divId).fadeIn("slow", function () {
  16. $(this).animate({ left: '200px' }, "slow");
  17. });
  18. Close_Main_Box();
  19. Action_BoxClick();
  20. DragDiv();
  21. }
  22. //构造 标准窗口式DIV
  23. function StanderDiv(id, title,menuHtml) {
  24. var divStr = "<div class=\"Main_Box\" isClose=\"f\" id=\"Div_" + id + "\"><div class=\"Box_info\">" + title + "<div class=\"Box_Close\">关闭</div></div><div class=\"Box_Menu\"><table id=\"menu_" + id + "\"><tr>" + menuHtml + "</tr></table></div><div class=\"Box_Content\" id=\"Con_" + id + "\"></div></div>";
  25. $("body").append(divStr);
  26. var divId = "#Div_" + id;
  27. $(divId).css("z-index", z_index + 1);
  28. z_index = z_index + 1;
  29. $(divId).fadeIn("slow", function () {
  30. $(this).animate({ left: '200px' }, "slow");
  31. });
  32. Close_Main_Box();
  33. Main_BoxClick();
  34. DragDiv();
  35. }
  36. //构造 标准菜单(搜索,增加,删除,修改)
  37. function StanderMenu(id) {
  38. return "<td><input id=\"searchT_" + id + "\" type=\"text\"/><input value=\"搜索\" id=\"searchB_" + id + "\" type=\"button\"></td><td><input value=\"新增\" id=\"Insert_" + id + "\" type=\"button\"></td><td><input value=\"修改\" id=\"Update_" + id + "\" type=\"button\"></td><td><input value=\"删除\" id=\"Del_" + id + "\" type=\"button\"></td>";
  39. }
  40. //菜单扩展
  41. function Vmenu(menuid, text) {
  42. var tid = "#menu_" + menuid + " tr";
  43. $(tid).append("<td>" + text + "</td>");
  44. }
  45. //左侧菜单隐藏和显示
  46. function ShowLeftMenu() {
  47. $(".Div_leftMenu_Btn").mouseover(function () {
  48. $(this).animate({ left: '-100px' }, "slow");
  49. $(".leftNav").animate({ left: '0px' }, "slow");
  50. });
  51. $(".leftNav").mouseleave(function () {
  52. $(this).animate({ left: '-100px' }, "slow");
  53. $(".Div_leftMenu_Btn").animate({ left: '0px' }, "slow");
  54. });
  55. }
  56. //关闭Main_Box
  57. function Close_Main_Box() {
  58. $(".Box_Close").click(function () {
  59. $(this).parent().parent().attr("isClose", "t");
  60. $(this).parent().parent().fadeOut("slow");
  61. });
  62. }
  63. //关闭普通窗口
  64. function CloseBox(id) {
  65. var tid = "#" + id;
  66. $(tid).attr("isClose", "t");
  67. $(tid).fadeOut("slow");
  68. }
  69. //改变Main_Box Z-index 或显示Main_Box
  70. function Show_Main_Box(id) {
  71. var divId = "#" + id;
  72. $(divId).css("z-index", z_index + 1);
  73. z_index = z_index + 1;
  74. if ($(divId).attr("isClose") == "t") {
  75. $(divId).fadeIn("slow");
  76. $(divId).attr("isClose","f");
  77. }
  78. }
  79. //显示Action_Box
  80. function Show_Action_Box(id) {
  81. var divId = "#" + id;
  82. $(divId).css("z-index", "99999");
  83. if ($(divId).attr("isClose") == "t") {
  84. $(divId).fadeIn("slow");
  85. $(divId).attr("isClose", "f");
  86. }
  87. }
  88. //构造Main_Box后,对Main_Box的操作
  89. function Opera_Main_Box(id) {
  90. var divId = "#" + id;
  91. $(divId).unbind();
  92. $(divId).bind("click", function () {
  93. Show_Main_Box("Div_" + id);
  94. });
  95. }
  96. //左边菜单点击基本事件
  97. function Left_Menu_Click(id, name,hasMenu) {
  98. if (hasMenu) {
  99. StanderDiv(id, name, StanderMenu(id));
  100. } else {
  101. StanderDiv(id, name, "");
  102. }
  103. Opera_Main_Box(id);
  104. }
  105. //Main_Box 点击 ,提高Main_Box z-index
  106. function Main_BoxClick() {
  107. $(".Main_Box").click(function () {
  108. $(this).css("z-index", z_index+1);
  109. z_index = z_index + 1;
  110. });
  111. }
  112. //Action_Box 点击 ,提高Action_Box z-index
  113. function Action_BoxClick() {
  114. $(".Action_Box").click(function () {
  115. $(this).css("z-index", z_index + 1);
  116. z_index = z_index + 1;
  117. });
  118. }
  119. //窗口式DIV拖动
  120. function DragDiv() {
  121. $(function () {
  122. $(".Main_Box").draggable({ handle: ".Box_info", scroll: false });
  123. });
  124. $(function () {
  125. $(".Action_Box").draggable({ handle: ".Box_info", scroll: false });
  126. });
  127. }
  128. //判断输入是否为数字
  129. function IsNum(str) {
  130. var ex = /^\d+.?\d*$/;
  131. if (ex.test(str)) {
  132. return true;
  133. } else {
  134. return false;
  135. }
  136. }
  137. $(document).ready(function () {
  138. ShowLeftMenu();
  139. $("#UPWD").unbind();
  140. $("#UPWD").bind("click", function () {
  141. UPWD();
  142. });
  143. });
  144. //按钮加载图片开始
  145. function loading(id) {
  146. var tid = "#" + id;
  147. $(tid).fadeOut();
  148. $(tid).parent().append("<img class=\"datagrid-mask-msg\" src=\"http://" + window.location.host + "\\Images\\loading.gif\"/>");
  149. var f = "stopW(\"" + id + "\")";
  150. setTimeout(f, 10000);
  151. }
  152. //按钮加载图片结束
  153. function stopW(id) {
  154. var tid = "#" + id;
  155. $(tid).fadeIn();
  156. $('.datagrid-mask-msg').remove();
  157. }
  158. //内容加载图片开始
  159. function Cloading(id) {
  160. var tid = "#" + id;
  161. $(tid).html("<img class=\"datagrid-mask-msg\" src=\"http://" + window.location.host + "\\Images\\loading.gif\"/>");
  162. setTimeout('Cstop()', 10000);
  163. }
  164. //内容加载图片结束
  165. function Cstop() {
  166. $('.datagrid-mask-msg').remove();
  167. }
  168. //清空table 里面 的表单数据
  169. function clearDataForm(id) {
  170. var inputid = "#" + id + " input";
  171. var textid = "#" + id + " textarea";
  172. $(inputid).val("");
  173. $(textid).val("");
  174. }
  175. //判断标准表的checkbox选中的值 用','分开
  176. function CheckBoxVal(id) {
  177. var ids = "";
  178. var tid = "#" + id + " input[type='checkbox']";
  179. $(tid).each(function () {
  180. if ($(this).is(':checked')) {
  181. ids += $(this).val() + ",";
  182. }
  183. });
  184. if (ids != "") {
  185. ids=ids.substring(0, ids.length - 1);
  186. }
  187. return ids;
  188. }
  189. //判断标准表的checkbox未选中的值 用','分开
  190. function NoCheckBoxVal(id) {
  191. var ids = "";
  192. var tid = "#" + id + " input[type='checkbox']";
  193. $(tid).each(function () {
  194. if (!$(this).is(':checked')) {
  195. ids += $(this).val() + ",";
  196. }
  197. });
  198. if (ids != "") {
  199. ids = ids.substring(0, ids.length - 1);
  200. }
  201. return ids;
  202. }
  203. //获取日期
  204. function GetDateStr(addDayCount) {
  205. var dd = new Date();
  206. var ddd = dd.DateAdd('d', addDayCount);
  207. var y = ddd.getYear();
  208. var m = ddd.getMonth() + 1; //获取当前月
  209. var d = ddd.getDate();
  210. return y + "-" + m + "-" + d;
  211. }
  212. //传入一个日期yyyy/mm/dd,格式化成yyyy-MM-dd
  213. function DateF(dateStr) {
  214. var dateS = dateStr.split('/');
  215. for (var i = 0; i < dateS.length; i++) {
  216. if (dateS[i].length <= 1) {
  217. dateS[i] = "0" + dateS[i];
  218. }
  219. }
  220. return dateS[0] + "-" + dateS[1] + "-" + dateS[2];
  221. }
  222. //获取部门选择框
  223. function SelectDep(id, selectVal) {
  224. var tid = "#" + id;
  225. //执行ajax
  226. $.get(depSrv, { type: "SelectDep" }, function (data) {
  227. if (data != "") {
  228. $(tid).html("");
  229. $(tid).append(data);
  230. if (selectVal != "") {
  231. var selectI = tid + " option[value='" + selectVal + "']";
  232. $(selectI).attr("selected", true);
  233. }
  234. } else {
  235. $(tid).html("");
  236. alert('没有可选择的部门,请到系统设置添加部门');
  237. }
  238. });
  239. }
  240. //获取用户选择框
  241. function SelectUser(id, d,selectVal) {
  242. var tid = "#" + id;
  243. //执行ajax
  244. $.get(UserSrv, { type: "SelectUser", depid: d }, function (data) {
  245. stopW(id);
  246. if (data != "") {
  247. $(tid).html("");
  248. $(tid).append(data);
  249. if (selectVal != "") {
  250. var selectI = tid + " option[value='" + selectVal + "']";
  251. $(selectI).attr("selected", true);
  252. }
  253. } else {
  254. $(tid).html("");
  255. alert('没有可选择的用户,请到系统设置添加用户');
  256. }
  257. });
  258. }
  259. //用户修改密码
  260. function UPWD() {
  261. //构造 修改密码DIV
  262. ActionDiv("Update", "PWD", "修改密码");
  263. //读取XML 获取修改表单
  264. $.get(MainOp, function (data) {
  265. $("#Update_Con_PWD").html($(data).find("Action[name='UpdatePWD']").html());
  266. $("#PWDUpdate").unbind();
  267. $("#PWDUpdate").bind("click", function () {
  268. UPWDGo();
  269. });
  270. });
  271. //重新定义修改密码点击事件
  272. $("#UPWD").unbind();
  273. $("#UPWD").bind("click", function () {
  274. Show_Action_Box("UpdatePWD");
  275. });
  276. }
  277. //修改密码ajax
  278. function UPWDGo() {
  279. //获取数据
  280. var o = $("#OPWD").val();
  281. var n = $("#NPWD").val();
  282. var rn = $("#RNPWD").val();
  283. if (n != rn) {
  284. alert('新密码不一样,请重新输入');
  285. return;
  286. }
  287. //加载等待
  288. loading("PWDUpdate");
  289. //执行ajax
  290. $.get(UserSrv, { type: "Upwd", oPwd: o, nPwd: n }, function (data) {
  291. //等待结束
  292. stopW("PWDUpdate");
  293. if (data == "true") {
  294. alert('修改成功!');
  295. CloseBox("UpdatePWD"); //关闭窗口
  296. }
  297. else {
  298. alert("修改失败...失败原因:" + data);
  299. }
  300. });
  301. }
  302. //输出指定位数的随机数的随机整数
  303. function RandNum(n) {
  304. var rnd = "";
  305. for (var i = 0; i < n; i++)
  306. rnd += Math.floor(Math.random() * 10);
  307. return rnd;
  308. }
  309. //单位数时间前加0
  310. function checkTime(i) {
  311. if (i < 10) {
  312. i = "0" + i;
  313. }
  314. return i;
  315. }
  316. //获取当前时间
  317. function NowTime() {
  318. var today = new Date();
  319. var h = today.getHours();
  320. var m = today.getMinutes();
  321. var s = today.getSeconds();
  322. m = checkTime(m);
  323. s = checkTime(s);
  324. return h + ":" + m + ":" + s;
  325. }