vue-组件.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //注册组件
  2. Vue.component('logon',{
  3. template:`
  4. <div type="login" v-on:click="on.button.exit()" v-bind:style="style.box" align="center">
  5. <input accept=".jpg,.png,.jpeg" type="file" hidden="hidden"/>
  6. <div v-bind:style="style.frame">
  7. <label v-bind:style="style.label">
  8. <span v-bind:style="style.head">注册</span>
  9. </label>
  10. <label v-bind:style="style.label.portrait">
  11. <span v-bind:style="style.i">*</span>
  12. <span v-bind:style="[style.title,{marginRight:'0px'}]">头像</span>
  13. <div v-on:mousedown="on.button.file" v-bind:style="style.portrait.box">
  14. <i v-bind:style="style.portrait.x"></i>
  15. <i v-bind:style="style.portrait.y"></i>
  16. </div>
  17. </label>
  18. <span v-bind:style="style.info"></span>
  19. <label v-bind:style="style.label">
  20. <span v-bind:style="style.i">*</span>
  21. <span v-bind:style="style.title">昵称</span>
  22. <input maxlength="9" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  23. </label>
  24. <span v-bind:style="style.info"></span>
  25. <label v-bind:style="style.label">
  26. <span v-bind:style="style.i">*</span>
  27. <span v-bind:style="style.title">密码</span>
  28. <input maxlength="16" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  29. </label>
  30. <span v-bind:style="style.info"></span>
  31. <label v-bind:style="style.label">
  32. <span v-bind:style="style.i">*</span>
  33. <span v-bind:style="style.title">邮箱</span>
  34. <input type="email" v-on:focus="on.input.focus()" v-on:blur="on.input.blur()" v-bind:style="style.input"/>
  35. </label>
  36. <span v-bind:style="style.info"></span>
  37. <label v-bind:style="style.label">
  38. <button v-on:click="on.button.logon()" v-bind:style="[style.button,style.button[2]]">注册</button>
  39. <button v-on:click="on.button.exit()" type="quit" v-bind:style="[style.button,style.button[1]]">关闭</button>
  40. </label>
  41. </div>
  42. </div>`,
  43. data:function () {
  44. return {
  45. style:{
  46. box:{
  47. width:'100%',
  48. height:'100%',
  49. position:'fixed',
  50. zIndex:$('*').length * 2,
  51. background:'rgba(0,0,0,.2)',
  52. },
  53. frame:{
  54. display:'inline-grid',
  55. position: 'absolute',
  56. top:0,
  57. bottom:0,
  58. left:0,
  59. right:0,
  60. margin:'auto',
  61. width:'300px',
  62. height:'350px',
  63. borderRadius:'2.5px',
  64. padding:'20px 50px',
  65. background: '#FFF',
  66. },
  67. label:{
  68. height:'30px',
  69. portrait:{
  70. marginTop:'10px',
  71. width:'100%',
  72. height:'70px',
  73. lineHeight:'70px',
  74. }
  75. },
  76. head:{
  77. lineHeight: '24px',
  78. fontSize: '18px',
  79. color: '#303133',
  80. },
  81. i:{
  82. color:'red',
  83. },
  84. title:{
  85. letterSpacing: '2.5px',
  86. marginRight:'5px',
  87. fontSize:'14px',
  88. color: '#606266',
  89. height:'30px',
  90. lineHeight:'30px',
  91. },
  92. input:{
  93. padding: '5px 10px',
  94. width: '200px',
  95. height: '20px',
  96. border:'1px solid #c3c3c3',
  97. borderRadius: '2.5px',
  98. outline:'none',
  99. },
  100. portrait:{
  101. box:{
  102. float:'right',
  103. position:'relative',
  104. marginRight:'163px',
  105. width:'70px',
  106. height:'70px',
  107. backgroundRepeat:'no-repeat',
  108. backgroundPosition:'center center',
  109. backgroundSize:'100% 100%',
  110. outline:'1px dotted #c3c3c3'
  111. },
  112. x:{
  113. left:'15px',
  114. right:'15px',
  115. top:'0px',
  116. bottom:'0px',
  117. margin:'auto',
  118. position:'absolute',
  119. height:'1px',
  120. background:'#c3c3c3',
  121. },
  122. y:{
  123. left:'0px',
  124. right:'0px',
  125. top:'15px',
  126. bottom:'15px',
  127. margin:'auto',
  128. position:'absolute',
  129. width:'1px',
  130. background:'#c3c3c3',
  131. }
  132. },
  133. button:{
  134. cursor:'pointer',
  135. marginRight: '15px',
  136. float:'right',
  137. height:'30px',
  138. width:'70px',
  139. border:'none',
  140. borderRadius:'2.5px',
  141. outline: 'none',
  142. 1:{
  143. border:'1px solid #c3c3c3',
  144. background:'#FFF',
  145. color:'black'
  146. },
  147. 2:{
  148. border:'1px solid #409EFF',
  149. background:'#409EFF',
  150. color:'#FFF'
  151. }
  152. },
  153. info:{
  154. textAlign:'left',
  155. margin:'0 70px',
  156. height:'15px',
  157. letterSpacing:'2px',
  158. lineHeight: '15px',
  159. color:'red',
  160. fontSize: '10px',
  161. },
  162. qr:{
  163. box:{
  164. display:'none',
  165. height:'150px',
  166. },
  167. img:{
  168. borderRadius:'2.5px',
  169. },
  170. button:{
  171. cursor: 'pointer',
  172. marginTop:'15px',
  173. height:'30px',
  174. background:'#FFF',
  175. border:'1px solid #c3c3c3',
  176. outline:'none',
  177. width:'150px',
  178. }
  179. }
  180. },
  181. on:{
  182. input:{
  183. focus:function () {
  184. event.target.style.borderColor = '#409EFF';
  185. },
  186. blur:function () {
  187. var input = event.target;
  188. var info = $(input).parent('label').next('span')[0];
  189. var title = $(input).prev('span')[0].innerText;
  190. if ($(input).val() === defaultStatus||$(input).val()===null){
  191. info.innerText = title+'不能为空';
  192. } else if ($(input).val().indexOf(' ') !== -1){
  193. info.innerText = title+'不能包含空格';
  194. } else {
  195. info.innerText = '';
  196. }
  197. input.style.borderColor = '#c3c3c3';
  198. }
  199. },
  200. button:{
  201. exit:function () {
  202. if ($("div[type='login']").is(event.target) || $("button[type='quit']").is(event.target)){
  203. $("div[type='login']").css('display','none');
  204. }
  205. },
  206. file:function () {
  207. let div_image = $(event.target);
  208. let input_file = $(event.target).parent('label').parent('div').prev('input');
  209. input_file.trigger('click').change(function(){
  210. if($(this).val().length > 0){
  211. var file_Reader = new FileReader();
  212. file_Reader.readAsDataURL(this.files[0]);
  213. // 获取成功
  214. file_Reader.onload = function(){
  215. sessionStorage.setItem('image',this.result);
  216. div_image.css({
  217. backgroundImage:'url('+this.result+')',
  218. outline:'none'
  219. }).find('i').css('display','none');
  220. }
  221. } else {
  222. div_image.css({
  223. backgroundImage: 'url()',
  224. outline: 'rgb(195, 195, 195) dotted 1px',
  225. }).find('i').css('display','block');
  226. }
  227. });
  228. },
  229. logon:function () {
  230. var message = $(event.target).parent('label').prevAll('label');
  231. var input_file = $(event.target).parent('label').parent('div').prev('input').val();
  232. var username = $(message[2]).find('input').val();
  233. var password = $(message[1]).find('input').val();
  234. var email = $(message[0]).find('input').val();
  235. var username_info = $(message[2]).next('span')[0];
  236. var password_info = $(message[1]).next('span')[0];
  237. var email_info = $(message[0]).next('span')[0];
  238. var username_title = $(message[2]).find('span').eq(1).text();
  239. var password_title = $(message[1]).find('span').eq(1).text();
  240. var email_title = $(message[0]).find('span').eq(1).text();
  241. if(
  242. $(event.target).parent('label').parent('div').prev('input').val() === defaultStatus
  243. ||
  244. $(event.target).parent('label').parent('div').prev('input').val() === null
  245. ) {
  246. $(message[3]).next('span')[0].innerText = '请设置头像'
  247. } else {
  248. $(message[3]).next('span')[0].innerText = ''
  249. }
  250. if (username === defaultStatus||username===null){
  251. username_info.innerText = username_title+'不能为空';
  252. } else if (username.indexOf(' ') !== -1){
  253. username_info.innerText = username_title+'不能包含空格';
  254. }
  255. if (password === defaultStatus||password ===null){
  256. password_info.innerText = password_title+'不能为空';
  257. } else if (password.indexOf(' ') !== -1){
  258. password_info.innerText = password_title+'不能包含空格';
  259. }
  260. if (email === defaultStatus||email ===null){
  261. email_info.innerText = email_title+'不能为空';
  262. } else if (email.indexOf(' ') !== -1){
  263. email_info.innerText = email_title+'不能包含空格';
  264. } else if (email.indexOf('@') === -1){
  265. email_info.innerText = email_title+'缺少必要@标识符';
  266. }
  267. if (
  268. input_file !== defaultStatus
  269. &&input_file !== null
  270. &&username !== defaultStatus
  271. &&username !== null
  272. &&username.indexOf(' ') === -1
  273. &&password !== defaultStatus
  274. &&password !== null
  275. &&password.indexOf(' ') === -1
  276. &&email !== defaultStatus
  277. &&email !== null
  278. &&email.indexOf(' ') === -1
  279. &&email.indexOf('@') !== -1){
  280. POST('logon',{
  281. image:sessionStorage.getItem('image'),
  282. account:username,
  283. password:password,
  284. email:email,
  285. },function (data) {
  286. console.log(data)
  287. alert_s(data.msg);
  288. if (data.error === 1){
  289. this.exit();
  290. }
  291. })
  292. }
  293. }
  294. }
  295. }
  296. };
  297. }
  298. });