UserInfo.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. Namespace.register("U.MD.U.P"); //个人资料设置
  2. U.MD.U.P.inpEl = {}
  3. //#region 用户登录个人资料
  4. //打开个人资料
  5. U.MD.U.P.userDataSet = function () {
  6. U.MD.U.P.L_init()
  7. }
  8. /**
  9. * 个人设置初始化函数
  10. */
  11. U.MD.U.P.L_init = function () {
  12. if (!U.MD.U.L.isLogin()) { //判断是否有登录
  13. var _form = $('#U_MD_U_P_Set'), _personal = $("#U_MD_U_P_Uc_B")[0]; //个人资料元素
  14. if (!_form.length) { //窗体是否存在
  15. new U.UF.UI.form("<div class='U_MD_F_S_TI'>个人设置</div>", _personal, { "id": "U_MD_U_P_Set", "style": { "width": "664px", "height": "549px" } }, { isenlarge: false, isstretching: false }).form; //打开个人资料函数实例化
  16. U.MD.U.P.L_eventBind(); //绑定事件
  17. _personal.style.display = 'block'; //显示打印内容
  18. } else {
  19. $('#U_MD_U_P_tab_lable_info')[0].checked = 'checked'; //让第一个选项选中
  20. _form[0].style.display = 'block'; //显示出来
  21. }
  22. }
  23. }
  24. /**
  25. * 事件绑定,打印页面
  26. */
  27. U.MD.U.P.L_eventBind = function () {
  28. U.MD.U.P.EL = { //元素集合
  29. "headImage": $('#U_MD_U_P_simpleInfo_img')[0], //用户头像 左侧
  30. "name": $('.U_MD_U_P_simpleInfo_name')[0], //用户昵称 左侧
  31. "nickName": $('#U_MD_U_P_tab_userNickName')[0], //用户昵称 基本信息
  32. "selfIntroduction": $('#U_MD_U_P_tab_selfIntroduction')[0], // 个人介绍 基本信息
  33. "email": $('#U_MD_U_P_tab_email')[0], //邮箱 基本信息
  34. "phoneNumber": $('#U_MD_U_P_tab_phoneNumber')[0], //手机号码 基本信息
  35. "address": $('#U_MD_U_P_tab_address')[0], //地址 基本信息
  36. "trueName": $('#U_MD_U_P_tab_trueName')[0], //真实姓名 个人隐私
  37. "birthday": $('#U_MD_U_P_tab_birthday')[0], //出生日期 个人隐私
  38. "loginName": $('#U_MD_U_P_tab_loginName')[0], //用户名 账号安全
  39. "oldPW": $('#U_MD_U_P_tab_oldPW')[0], //旧密码 账号安全-修改密码
  40. "newPW": $('#U_MD_U_P_tab_newPW')[0], //新密码 账号安全-修改密码
  41. "confirmPW": $('#U_MD_U_P_tab_confirmPW')[0], //确认密码 账号安全-修改密码
  42. "phone": $('#U_MD_U_P_tab_phone')[0], //手机号码 账号安全-手机找回
  43. "accountNPW": $('#U_MD_U_P_tab_lable_accountNext_n')[0], //新密码 账号安全-手机找回
  44. "accountCPW": $('#U_MD_U_P_tab_lable_accountNext_c')[0] //确认密码 账号安全-手机找回
  45. };
  46. var _bindEl = ["nickName", "email", "phoneNumber", "newPW", "confirmPW,newPW", "phone", "accountNPW", "accountCPW,accountNPW"], //元素数组
  47. _bindString = ["NickName", "Email", "TelephoneNumber", "PassWord", "contrastPW", "TelephoneNumber", "PassWord", "contrastPW"], //绑定验证类型
  48. _lastPage = $('.U_MD_U_P_tab_inp')[0], //上一个停留的位置
  49. _isDataChanged = false, //用户是否修改过数据
  50. _changeDataNum = "", //序号
  51. _isNextStep = false; //是否可点击下一步
  52. U.UF.DL.asynLoadJs({ type: "text/javascript", src: "/js/Controls/Basic/City.js" }, function () { new U.MD.UI.city(); }); //加载城市控件js
  53. U.UF.DL.asynLoadCss({ "href": "/css/Controls/Basic/City.css", type: "text/css", rel: "stylesheet" }); //加载城市控件css
  54. $('#U_MD_U_P_tab_address').bind({
  55. click: function () {
  56. U.MD.UI.city(this);
  57. $("#U_MD_UI_city_cityBox")[0].style.display = "block";
  58. $("#U_MD_UI_city_cityBox")[0].style.zIndex = "999";
  59. }
  60. });
  61. $('#U_MD_U_P_tab_birthday').bind({ //绑定生日的日历控件
  62. click: function () {
  63. U.MD.UI.calendar(this, $('#U_MD_U_P_tab_calendar')[0], false);
  64. }
  65. })
  66. $('#U_MD_U_P_save').bind({ //绑定保存点击事件
  67. click: function () {
  68. switch (_lastPage.value) { //判断停留在那一页上
  69. case "0": case "1":
  70. U.MD.U.P.L_updateUserBasicInfo(_lastPage.value); break;
  71. case "2":
  72. if ($('.U_MD_U_P_tab_accountRadio:checked')[0].value == 0) {
  73. U.MD.U.P.L_setPassword(_bindEl, _bindString);
  74. } else if ($('.U_MD_U_P_tab_accountRadio:checked')[0].value == 1) {
  75. U.MD.U.P.L_updatePassword();
  76. }
  77. break;
  78. }
  79. $('.U_MD_U_P_simpleInfo_address')[0].innerText = $("#U_MD_U_P_tab_address")[0].value;
  80. }
  81. })
  82. $('.U_MD_U_P_tab_inp').bind({ //绑定事件
  83. change: function () {
  84. U.MD.U.P.L_reset(_changeDataNum, _isDataChanged);
  85. _lastPage = this;
  86. _isDataChanged = false;
  87. }
  88. })
  89. $('.U_MD_U_P_tab_lable_content input').bind({ //判断某一页用户是否修改了数据
  90. change: function () {
  91. if (!_isDataChanged) {
  92. _changeDataNum = _lastPage.value;
  93. _isDataChanged = true;
  94. }
  95. }
  96. })
  97. $('.U_MD_U_P_tab_accountRadio').bind({ //账号安全的‘下一步’与“保存设置”按钮的显示隐藏
  98. change: function () {
  99. if (this.value == 0) {
  100. $('#U_MD_U_P_save')[0].style.display = "inline-block";
  101. $('#U_MD_U_P_next')[0].style.display = "none";
  102. } else {
  103. $('#U_MD_U_P_save')[0].style.display = "none";
  104. $('#U_MD_U_P_next')[0].style.display = "inline-block";
  105. }
  106. }
  107. })
  108. $('#U_MD_U_P_authCodeBtn').bind({
  109. click: function () { //发送验证码
  110. _isNextStep = U.MD.U.P.L_sendAuthCode(_isNextStep);
  111. }
  112. })
  113. $('#U_MD_U_P_next').bind({
  114. click: function () { //下一步
  115. U.MD.U.P.L_phoneConfirm();
  116. }
  117. })
  118. $('#U_MD_U_P_authCodeInp').bind({
  119. change: function () { //验证码文本框的不为空清除错误
  120. if (this.value.trim().length > 0) {
  121. $(this).removeClass('U_MD_U_P_tab_user_emptyInp')
  122. }
  123. }
  124. })
  125. $('#U_MD_U_P_cancel').bind({
  126. click: function () { //关闭
  127. $('#U_MD_U_P_Set')[0].style.display = 'none';
  128. }
  129. })
  130. $('#U_MD_U_P_tab_oldPW').bind({
  131. change: function () {
  132. var _bool = U.MD.U.P.L_checkEmpty(this);
  133. !_bool && $(this).removeClass('U_MD_U_P_tab_user_emptyInp');
  134. }
  135. })
  136. U.MD.U.P.L_dataPrint(); //数据打印
  137. U.MD.U.P.L_bindCheckFormat(_bindEl, _bindString); //绑定文本框的格式
  138. }
  139. /**
  140. * 绑定事件
  141. * @param elarr {Array} 元素数组
  142. * @param eventarr {Array} 绑定验证类型
  143. */
  144. U.MD.U.P.L_bindCheckFormat = function (elarr, eventarr) {
  145. var _len = elarr.length;
  146. for (var i = 0; i < _len; i++) {
  147. var _el = U.MD.U.P.EL[elarr[i].split(',')[0]];
  148. _el.i = i;
  149. $(_el).bind({
  150. change: function () {
  151. U.MD.U.P.L_inpFormatCheck(this, elarr, eventarr);
  152. }
  153. })
  154. }
  155. }
  156. /**
  157. * 数据重置
  158. * @param that {string} 标记
  159. * @param elarr {Array} 是否更改数据
  160. * @param eventarr {Array} 是否更改数据
  161. */
  162. U.MD.U.P.L_inpFormatCheck = function (that, elarr, eventarr) {
  163. var _bool = false;
  164. if (U.UF.S[eventarr[that.i]]) {
  165. _bool = U.UF.S[eventarr[that.i]].test(that.value.trim());
  166. } else if (eventarr[that.i] == 'contrastPW') {
  167. _bool = (U.MD.U.P.EL[elarr[that.i].split(',')[0]].value === U.MD.U.P.EL[elarr[that.i].split(',')[1]].value);
  168. }
  169. if (!_bool) {
  170. if (!that.value.trim().length) {
  171. $(that).removeClass('U_MD_U_P_tab_user_errorInp');
  172. $(that).addClass('U_MD_U_P_tab_user_emptyInp');
  173. $(that).next().removeClass('U_MD_U_P_tab_errorAlear');
  174. } else {
  175. $(that).removeClass('U_MD_U_P_tab_user_emptyInp');
  176. $(that).addClass('U_MD_U_P_tab_user_errorInp');
  177. $(that).next().addClass('U_MD_U_P_tab_errorAlear');
  178. }
  179. } else {
  180. $(that).removeClass('U_MD_U_P_tab_user_errorInp');
  181. $(that).removeClass('U_MD_U_P_tab_user_emptyInp');
  182. $(that).next().removeClass('U_MD_U_P_tab_errorAlear');
  183. }
  184. }
  185. /**
  186. * 数据重置
  187. * @param mark {string} 标记
  188. * @param flag {boolean} 是否更改数据
  189. */
  190. U.MD.U.P.L_reset = function (mark, flag) {
  191. if (!flag)
  192. return;
  193. var _info = US.userInfo, _elObj = U.MD.U.P.EL;
  194. switch (mark) {
  195. case "0":
  196. U.MD.U.P.L_dataPrint.simpleInfo(_info, _elObj);
  197. break;
  198. case "1":
  199. U.MD.U.P.L_dataPrint.privacy(_info, _elObj);
  200. break;
  201. case "2":
  202. U.MD.U.P.L_dataPrint.account(_info, _elObj);
  203. break;
  204. }
  205. }
  206. /**
  207. * 打印数据
  208. */
  209. U.MD.U.P.L_dataPrint = function () {
  210. var _info = US.userInfo, _elObj = U.MD.U.P.EL;
  211. U.MD.U.P.L_dataPrint.privacy(_info, _elObj);
  212. U.MD.U.P.L_dataPrint.simpleInfo(_info, _elObj);
  213. U.MD.U.P.L_dataPrint.account(_info, _elObj);
  214. U.MD.U.P.L_dataPrint.left(_info, _elObj);
  215. }
  216. /**
  217. * 初始化左侧栏数据
  218. * @param info {Array} 元素数组
  219. * @param elobj {Array} 绑定验证类型
  220. */
  221. U.MD.U.P.L_dataPrint.left = function (info, elobj) {
  222. elobj["headImage"].src = U.MD.C.getHeadImage(info.UserImageHead);
  223. /*$('.U_MD_U_P_simpleInfo_address')[0].innerText = info.LoginAddress.slice(2, 6);*/
  224. $('.U_MD_U_P_simpleInfo_address')[0].innerText = elobj["address"].value;
  225. elobj["name"].innerText = info.UserNickName || "";
  226. elobj["name"].title = info.UserNickName || "";
  227. }
  228. /**
  229. * 初始化个人隐私数据
  230. * @param info {Array} 元素数组
  231. * @param elobj {Array} 绑定验证类型
  232. */
  233. U.MD.U.P.L_dataPrint.privacy = function (info, elobj) {
  234. elobj["trueName"].value = info.TrueName;
  235. elobj["birthday"].value = U.UF.D.getYearMonthDay(info.Birthday);
  236. }
  237. /**
  238. * 初始化基本信息数据
  239. * @param info {Array} 元素数组
  240. * @param elobj {Array} 绑定验证类型
  241. */
  242. U.MD.U.P.L_dataPrint.simpleInfo = function (info, elobj) {
  243. $(".U_MD_U_P_tab_user_radio[value$=" + (info.UserSex ? "'1'" : "'0'") + "]")[0].checked = true;
  244. elobj["selfIntroduction"].value = info.UserIndividualitysignature;
  245. elobj["address"].innerText = info.Province || "";
  246. elobj["nickName"].value = info.UserNickName || "";
  247. elobj["email"].value = info.UserEmail;
  248. elobj["phoneNumber"].value = info.UserTelephoneNumber;
  249. elobj["address"].value = info.City;
  250. elobj["loginName"].innerText = info.UserName;
  251. }
  252. /**
  253. * 初始化账号安全数据
  254. * @param info {Array} 元素数组
  255. * @param elobj {Array} 绑定验证类型
  256. */
  257. U.MD.U.P.L_dataPrint.account = function (info, elobj) {
  258. $('#U_MD_U_P_tab_lable_accountNext_t')[0].innerText = info.UserName;
  259. $('.U_MD_U_P_tab_lable_account').css('display', 'block');
  260. $('.U_MD_U_P_tab_lable_accountNext').css('display', 'none');
  261. $('.U_MD_U_P_tab_accountRadio')[0].checked = "checked";
  262. var _arr = Array.prototype.slice.call($('.U_MD_U_P_tab_item')[2].querySelectorAll('[type="text"]')).concat(Array.prototype.slice.call($('.U_MD_U_P_tab_item')[2].querySelectorAll('[type="password"]')));
  263. for (var i = 0; i < _arr.length; i++) {
  264. _arr[i].value = "";
  265. $(_arr[i]).removeClass('U_MD_U_P_tab_user_errorInp');
  266. $(_arr[i]).removeClass('U_MD_U_P_tab_user_emptyInp');
  267. $(_arr[i]).next().removeClass('U_MD_U_P_tab_errorAlear');
  268. }
  269. $('#U_MD_U_P_save').css('display', 'inline-block');
  270. $('#U_MD_U_P_next').css('display', 'none');
  271. }
  272. /**
  273. * 更新用户基本信息
  274. */
  275. U.MD.U.P.L_updateUserBasicInfo = function (type) {
  276. var _info = US.userInfo, _elObj = U.MD.U.P.EL, _sex = parseInt($('.U_MD_U_P_tab_user_radio:checked')[0].value);
  277. if (!parseInt(type)) {
  278. var _bool = U.MD.U.P.L_checkEmpty(_elObj['nickName']) || U.MD.U.P.L_checkEmpty(_elObj['email']) || U.MD.U.P.L_checkEmpty(_elObj['phoneNumber']) || U.MD.U.P.L_checkEmpty(_elObj['address']);
  279. if ($('.U_MD_U_P_tab_user_errorInp').length || $('.U_MD_U_P_tab_user_emptyInp').length || _bool) {
  280. if ($(".U_MD_U_P_tab_user_errorInp")[0].id == "U_MD_U_P_tab_email" && $(".U_MD_U_P_tab_user_errorInp").length == 1) {
  281. U.Alert("邮箱填写错误!");
  282. return;
  283. } else if ($(".U_MD_U_P_tab_user_errorInp")[0].id == "U_MD_U_P_tab_phoneNumber" && $(".U_MD_U_P_tab_user_errorInp").length == 1) {
  284. U.Alert("手机号码填写错误!");
  285. return;
  286. } else {
  287. U.Alert("信息录入错误!");
  288. return;
  289. }
  290. }
  291. }
  292. U.A.Request(US.USER, ["UpdateUserBasicInfo", _info.UserId, _elObj["trueName"].value, _elObj["nickName"].value, _elObj["phoneNumber"].value, '', '', _elObj["selfIntroduction"].value, _sex, _elObj["email"].value,
  293. "中国", _elObj["address"].textContent, _elObj["address"].value || "", _elObj["birthday"].value],
  294. function (r) {
  295. if (r.value) {//判断是否更改成功
  296. US.userInfo.UserSex = _sex ? true : false;
  297. US.userInfo.TrueName = _elObj["trueName"].value;
  298. US.userInfo.UserNickName = _elObj["nickName"].value;
  299. US.userInfo.UserTelephoneNumber = _elObj["phoneNumber"].value;
  300. US.userInfo.UserIndividualitysignature = _elObj["selfIntroduction"].value;
  301. US.userInfo.UserEmail = _elObj["email"];
  302. US.userInfo.Province = _elObj["address"].value;
  303. US.userInfo.City = _elObj["address"].value;
  304. U.Alert("更改个人资料成功");
  305. }
  306. else {
  307. U.alert("更改个人资料失败");
  308. }
  309. })
  310. }
  311. /**
  312. * 设置密码
  313. * @param elarr {Array} 元素数组
  314. * @param eventarr {Array} 绑定验证类型
  315. */
  316. U.MD.U.P.L_setPassword = function (elarr, eventarr) {
  317. var _elObj = U.MD.U.P.EL,
  318. _emptyEl = $($('.U_MD_U_P_tab_lable_content')[2]).find('.U_MD_U_P_tab_user_emptyInp'),
  319. _errorEl = $($('.U_MD_U_P_tab_lable_content')[2]).find('.U_MD_U_P_tab_user_errorInp');
  320. if (!_emptyEl.length && !_errorEl.length) {
  321. if (_elObj["oldPW"].value == "") {
  322. U.MD.U.P.L_inpFormatCheck(_elObj["oldPW"], elarr, eventarr);
  323. return;
  324. } else if (_elObj["newPW"].value == "") {
  325. U.MD.U.P.L_inpFormatCheck(_elObj["newPW"], elarr, eventarr);
  326. return;
  327. } else if (_elObj["confirmPW"].value == "") {
  328. U.MD.U.P.L_inpFormatCheck(_elObj["confirmPW"], elarr, eventarr);
  329. return;
  330. }
  331. U.A.Request(US.USER, ["UpdateUserPasswordByOldPassword", US.userInfo.userid, _elObj["oldPW"].value, _elObj["confirmPW"].value], function (r) {
  332. if (r.value) {
  333. U.Alert("更改密码成功,请重新登录");
  334. U.MD.U.LO.logout();
  335. U.MD.U.L.login();
  336. } else {
  337. U.Alert("原密码错误");
  338. $(_elObj["oldPW"]).addClass("U_MD_U_P_tab_user_emptyInp");
  339. }
  340. });
  341. }
  342. }
  343. /**
  344. * 通过手机号码修改账户密码
  345. */
  346. U.MD.U.P.L_updatePassword = function () {
  347. var _pw = $('#U_MD_U_P_tab_lable_accountNext_n')[0];
  348. var _pwconfirm = $('#U_MD_U_P_tab_lable_accountNext_c')[0];
  349. if (U.MD.U.P.inputFormat(_pw, false, 'PassWord') && U.MD.U.P.inputFormat(_pwconfirm, false, 'PassWord')) {
  350. if (_pwconfirm.value == _pw.value) {
  351. U.A.Request(US.USER, ["UpdateUserPassword", US.userInfo.userid, _pw.value], function (r) {//更改密码存储过程
  352. if (r.value) {//判断是否更改成功
  353. U.Alert('更改密码成功');
  354. }
  355. else {
  356. U.Alert('更改密码失败');
  357. }
  358. });
  359. } else {
  360. U.Alert('请输入相同的新密码');
  361. }
  362. }
  363. }
  364. /**
  365. * 发送验证码
  366. * @param flag {boolean} 是否已发送
  367. */
  368. U.MD.U.P.L_sendAuthCode = function (flag) {
  369. if (flag) {
  370. U.Aleart('请在60秒后重试');
  371. return;
  372. }
  373. var _phoneInp = U.MD.U.P.EL["phone"],
  374. _bool = U.MD.U.P.L_checkEmpty(_phoneInp) || U.MD.U.P.L_isCanUse(_phoneInp);
  375. if (_bool) {
  376. U.Alert('信息录入错误!');
  377. return;
  378. }
  379. U.A.Request(US.CD, [US.DB, "UseStudio_Users", "GetUserinfoByUserName", US.userInfo.username], function (r) {//根据用户名获取用户信息
  380. if (r.value[0].UserTelephoneNumber != _phoneInp.value) {//如果输入手机号与账号设置的手机号不匹配)
  381. U.Alert('输入的手机号与账号不匹配');
  382. } else {
  383. var _xhttp = new XMLHttpRequest(); //XMLHttpRequest 对象用于在后台与服务器交换数据
  384. _xhttp.onreadystatechange = function () {//每当 readyState 属性改变时,就会调用该函数。
  385. if (this.readyState == 4) {//发送成功后
  386. if (this.status == 201) {
  387. U.Alert('发送成功'); //弹出发送成功
  388. U.MD.U.P.L_setTime($('#U_MD_U_P_authCodeBtn')[0]);
  389. return true;
  390. } else {
  391. U.Alert(JSON.parse(this.response).err || '验证码发送失败,请重新发送...');
  392. }
  393. }
  394. };
  395. _xhttp.open("POST", "http://api.cloudsql.1473.cn/postnumber", true); //指定和服务器端交互的HTTP方法,URL地址及其他请求信息
  396. _xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //向一个打开但未发送的请求设置或添加一个 HTTP 请求
  397. _xhttp.withCredentials = true; //发送cookie等认证信息到服务端
  398. _xhttp.send("number=" + _phoneInp.value); //$("#userphone")[0].children[0].children[0].value 发送的手机号输入的框
  399. }
  400. });
  401. }
  402. /**
  403. * 验证手机验证码
  404. */
  405. U.MD.U.P.L_phoneConfirm = function () {
  406. var _input = $('#U_MD_U_P_authCodeInp')[0];
  407. if (U.MD.U.P.L_checkEmpty(_input)) {
  408. U.Alert('验证码不为空');
  409. return;
  410. }
  411. var _xhttp = new XMLHttpRequest(); //XMLHttpRequest 对象用于在后台与服务器交换数据
  412. _xhttp.onreadystatechange = function (r) {//每当 readyState 属性改变时,就会调用该函数
  413. if (this.readyState == 4) {//验证成功后
  414. if (this.status == 201) {
  415. $('#U_MD_U_P_save').css('display', 'inline-block');
  416. $('#U_MD_U_P_next').css('display', 'none');
  417. $('.U_MD_U_P_tab_lable_account').css('display', 'none');
  418. $('.U_MD_U_P_tab_lable_accountNext').css('display', 'block');
  419. U.Alert("验证成功"); //弹出验证成功
  420. } else {
  421. U.Alert(JSON.parse(this.response).err || "验证码有误");
  422. }
  423. }
  424. };
  425. _xhttp.open("POST", "http://api.cloudsql.1473.cn/verifi", true); ////指定和服务器端交互的HTTP方法,URL地址及其他请求信息
  426. _xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //向一个打开但未发送的请求设置或添加一个 HTTP 请求
  427. _xhttp.withCredentials = true; //发送cookie等认证信息到服务端
  428. _xhttp.send("code=" + _input.value);
  429. }
  430. /**
  431. * 设置验证码时间
  432. * @param inp {elenemt} 元素
  433. */
  434. U.MD.U.P.L_setTime = function (inp) {
  435. if (this._timer) {
  436. U.Alert('请在60后重试!');
  437. return;
  438. }
  439. var _second = 60,
  440. _this = this;
  441. this._timer = setInterval(function () {
  442. inp.innerText = --_second + 's';
  443. if (!_second) {
  444. inp.innerText = '发送验证码';
  445. clearInterval(_this._timer);
  446. _this._timer = null;
  447. }
  448. }, 1000);
  449. }
  450. /**
  451. * 重置文本框
  452. * @param inp {elenemt} 元素
  453. */
  454. U.MD.U.P.L_restoreInp = function (el) {
  455. el.value = "";
  456. $(el).removeClass('U_MD_U_P_tab_user_errorInp');
  457. $(el).removeClass('U_MD_U_P_tab_user_emptyInp');
  458. }
  459. /**
  460. * 判断元素是否有错误
  461. * @param inp {elenemt} 元素
  462. */
  463. U.MD.U.P.L_isCanUse = function (el) {
  464. return $(el).hasClass('U_MD_U_P_tab_user_emptyInp') || $(el).hasClass('U_MD_U_P_tab_user_errorInp');
  465. }
  466. /**
  467. * 判断元素是否为空
  468. * @param inp {elenemt} 元素
  469. */
  470. U.MD.U.P.L_checkEmpty = function (el) {
  471. if (el.value.trim() == "" || !!!el.value) {
  472. $(el).addClass('U_MD_U_P_tab_user_emptyInp');
  473. return true;
  474. }
  475. return false;
  476. }
  477. /**
  478. * 上传头像到服务器处理
  479. * @param input {ele} 上传图片的input
  480. */
  481. U.MD.U.P.uploadUserHeadImg = function (input) {
  482. //判断是否支持FileReader
  483. //头像预览
  484. if (window.FileReader) {
  485. var reader = new FileReader();
  486. } else {
  487. U.alert("您的设备不支持图片预览功能,如需该功能请升级您的设备!");
  488. }
  489. //获取文件
  490. var file = input.files[0];
  491. var imageType = /^image\//;
  492. //是否是图片
  493. if (!imageType.test(file.type)) {
  494. U.alert("请选择图片!");
  495. return;
  496. }
  497. var img = $('#U_MD_U_P_simpleInfo_img')[0];
  498. //读取完成
  499. reader.onload = function (e) {
  500. //获取图片dom
  501. //图片路径设置为读取的图片
  502. img.src = e.target.result;
  503. };
  504. reader.readAsDataURL(file);
  505. //上传图片
  506. U.UF.UP.inputUpload([input], "http://main.1473.cn/USUpfile.ashx?typename=UploadHeadImage", function (url) {
  507. //console.log(url.value);
  508. //修改头像
  509. U.A.Request(US.USER, ["UpdateUserHeaderImage", US.userInfo.userid, url.value.UserFilesServerName, url.value.UseFilesServerThumbnailName], function (r) {
  510. if (r.value) {
  511. //动态修改全局属性
  512. US.userInfo.UserImageHead = url.value.UserFilesServerName;
  513. US.userInfo.UserThumbnailImageHead = url.value.UseFilesServerThumbnailName;
  514. U.Alert('头像修改成功!');
  515. } else {
  516. U.Alert('头像修改失败!');
  517. }
  518. });
  519. }, []);
  520. }