cacheUserInfo.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. layui.config({
  2. base : "../../js/"
  3. }).use(['form','jquery',"address"],function() {
  4. var form = layui.form,
  5. $ = layui.jquery,
  6. address = layui.address;
  7. //判断是否设置过头像,如果设置过则修改顶部、左侧和个人资料中的头像,否则使用默认头像
  8. if(window.sessionStorage.getItem('userFace')){
  9. $("#userFace").attr("src",window.sessionStorage.getItem('userFace'));
  10. $(".userAvatar").attr("src",$(".userAvatar").attr("src").split("images/")[0] + "images/" + window.sessionStorage.getItem('userFace').split("images/")[1]);
  11. }else{
  12. $("#userFace").attr("src","../../images/face.jpg");
  13. }
  14. //判断是否修改过用户信息,如果修改过则填充修改后的信息
  15. var menuText = $("#top_tabs",parent.document).text(); //判断打开的窗口是否存在“个人资料”页面
  16. var citys,areas;
  17. if(window.sessionStorage.getItem('userInfo')){
  18. //获取省信息
  19. address.provinces();
  20. var userInfo = JSON.parse(window.sessionStorage.getItem('userInfo'));
  21. var citys;
  22. $(".realName").val(userInfo.realName); //用户名
  23. $(".userSex input[value="+userInfo.sex+"]").attr("checked","checked"); //性别
  24. $(".userPhone").val(userInfo.userPhone); //手机号
  25. $(".userBirthday").val(userInfo.userBirthday); //出生年月
  26. //填充省份信息,同时调取市级信息列表
  27. $.get("../../json/address.json", function (addressData) {
  28. $(".userAddress select[name='province']").val(userInfo.province); //省
  29. var value = userInfo.province;
  30. if (value > 0) {
  31. address.citys(addressData[$(".userAddress select[name='province'] option[value='"+userInfo.province+"']").index()-1].childs);
  32. citys = addressData[$(".userAddress select[name='province'] option[value='"+userInfo.province+"']").index()-1].childs;
  33. } else {
  34. $('.userAddress select[name=city]').attr("disabled","disabled");
  35. }
  36. $(".userAddress select[name='city']").val(userInfo.city); //市
  37. //填充市级信息,同时调取区县信息列表
  38. var value = userInfo.city;
  39. if (value > 0) {
  40. address.areas(citys[$(".userAddress select[name=city] option[value='"+userInfo.city+"']").index()-1].childs);
  41. } else {
  42. $('.userAddress select[name=area]').attr("disabled","disabled");
  43. }
  44. $(".userAddress select[name='area']").val(userInfo.area); //区
  45. form.render();
  46. })
  47. for(key in userInfo){
  48. if(key.indexOf("like") != -1){
  49. $(".userHobby input[name='"+key+"']").attr("checked","checked");
  50. }
  51. }
  52. $(".userEmail").val(userInfo.userEmail); //用户邮箱
  53. $(".myself").val(userInfo.myself); //自我评价
  54. form.render();
  55. }
  56. })