vue-组件.js 18 KB

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