go语言写的人脸本地化程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

396 rindas
10 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>注册页面</title>
  7. <style>
  8. body{
  9. margin: 0;
  10. }
  11. li {
  12. list-style-type: none;
  13. }
  14. @media screen and (orientation: portrait) {
  15. .login {
  16. width: 100vw;
  17. height: 100vh;
  18. background-image: url("/static/img/phoneBgc.jpg");
  19. background-size: 100% 100%;
  20. background-repeat: no-repeat;
  21. }
  22. .register {
  23. background-image: url("/static/img/registerBgc.jpg") !important;
  24. padding-top: 15vh;
  25. }
  26. .register_loginTitle {
  27. width: 100vw;
  28. font-size: 8vw;
  29. text-align: center;
  30. }
  31. .register_inputBox {
  32. display: flex;
  33. flex-direction: column;
  34. justify-content: center;
  35. align-items: center;
  36. margin-top: 5vh;
  37. position: relative;
  38. }
  39. .register_phoneInput {
  40. width: 50vw;
  41. height: 5vh;
  42. border-radius: 2vw;
  43. background-color: transparent;
  44. font-size: 3vw;
  45. padding-left: 2vw;
  46. border: 1px solid #000;
  47. margin-bottom: 2vh;
  48. }
  49. .register_nameInput {
  50. width: 50vw;
  51. height: 5vh;
  52. border-radius: 2vw;
  53. background-color: transparent;
  54. font-size: 3vw;
  55. padding-left: 2vw;
  56. border: 1px solid #000;
  57. margin-bottom: 2vh;
  58. }
  59. .reg_button {
  60. width: 40vw;
  61. height: 5vh;
  62. background-color: rgb(101, 161, 255);
  63. border-radius: 10vw;
  64. display: flex;
  65. justify-content: center;
  66. align-items: center;
  67. color:#fff;
  68. font-size: 4vw;
  69. margin: 2vh 0 0 30vw;
  70. }
  71. .register_loginButton {
  72. width: 40vw;
  73. height: 5vh;
  74. background-color: rgb(101, 161, 255);
  75. border-radius: 10vw;
  76. display: flex;
  77. justify-content: center;
  78. align-items: center;
  79. color:#fff;
  80. font-size: 4vw;
  81. margin: 2vh 0 0 30vw;
  82. }
  83. #scroll-to-top-btn {
  84. display: none;
  85. position: fixed;
  86. right: 20px;
  87. bottom: 20px;
  88. width: 7vw;
  89. height: 10vh;
  90. color: #fff;
  91. border: none;
  92. border-radius: 5px;
  93. font-size: 3vw;
  94. cursor: pointer;
  95. }
  96. .uploadImg{
  97. width: 46vw !important;
  98. transform: translate(0%, 0%) !important;
  99. left: 27vw !important;
  100. position: relative;
  101. }
  102. }
  103. @media screen and (orientation: landscape) {
  104. input:focus {
  105. border: 0.1vw solid #000;
  106. outline: none; /* 可选,用于去除默认的外边框样式 */
  107. }
  108. .login {
  109. width: 100vw;
  110. height: 100vh;
  111. background-image: url("/static/img/phoneBgc_pc.jpg");
  112. background-size: 100% 100%;
  113. background-repeat: no-repeat;
  114. position: relative;
  115. }
  116. .register {
  117. background-image: url("/static/img/registerBgc_pc.jpg") !important;
  118. }
  119. .register_loginTitle {
  120. width: 100vw;
  121. display: flex;
  122. justify-content: center;
  123. font-size: 4vh;
  124. text-align: center;
  125. position: absolute;
  126. z-index: 10;
  127. top: 10vh;
  128. }
  129. .uploadImg {
  130. width: 15vw;
  131. }
  132. .register_inputBox {
  133. width: 100vw;
  134. display: flex;
  135. flex-direction: column;
  136. justify-content: center;
  137. align-items: center;
  138. position: relative;
  139. padding-top: 42vh;
  140. }
  141. .register_phoneInput {
  142. width: 37vh;
  143. height: 6vh;
  144. border-radius: 2vh;
  145. background-color: transparent;
  146. font-size: 3vh;
  147. border: 0.1vw solid #000;
  148. margin-bottom: 5vh;
  149. padding-left:1vw ;
  150. }
  151. .register_nameInput {
  152. width: 37vh;
  153. height: 6vh;
  154. border-radius: 2vh;
  155. background-color: transparent;
  156. font-size: 3vh;
  157. border: 0.1vw solid #000;
  158. padding-left: 1vw ;
  159. margin-bottom: 2vh;
  160. }
  161. .reg_button {
  162. width: 16vw;
  163. height: 3vw;
  164. background-color: rgb(101, 161, 255);
  165. border-radius: 10vh;
  166. display: flex;
  167. justify-content: center;
  168. align-items: center;
  169. color: #fff;
  170. font-size: 2vw;
  171. /* margin: 2vh 0 0 30vh; */
  172. position: absolute;
  173. left: 55vw;
  174. top: 65vh;
  175. }
  176. .register_loginButton {
  177. width: 8vw;
  178. height: 2vw;
  179. background-color: rgb(101, 161, 255);
  180. border-radius: 1vw;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. color: #fff;
  185. font-size: 3vh;
  186. position: absolute;
  187. left: 46vw;
  188. top: 65vh;
  189. }
  190. .hand:hover{
  191. cursor: pointer;
  192. }
  193. #scroll-to-top-btn {
  194. display: none;
  195. position: fixed;
  196. right: 20px;
  197. bottom: 20px;
  198. width: 7vh;
  199. height: 10vw;
  200. color: #fff;
  201. border: none;
  202. border-radius: 5px;
  203. font-size: 3vh;
  204. cursor: pointer;
  205. }
  206. .uploadImg{
  207. width: 200px !important;
  208. transform: translate(0%, 0%) !important;
  209. left: 2vw !important;
  210. position: relative;
  211. }
  212. }
  213. .upload-img-box {
  214. position: relative;
  215. }
  216. .upload-img-box .input-box {
  217. display: inline-block;
  218. width: 144px;
  219. height: 144px;
  220. /*border: solid black 1px;*/
  221. }
  222. .upload-img-box .befor-img {
  223. display: flex;
  224. /*width: 300px;*/
  225. /*height: 90px;*/
  226. /*border: solid black 1px;*/
  227. position: absolute;
  228. top: 0px;
  229. left: 0px;
  230. /*background: #ffffff;*/
  231. z-index: 30;
  232. align-items: center;
  233. justify-content: center;
  234. }
  235. .upload-img-box .befor-img.hasImg {
  236. display: none;
  237. }
  238. .upload-img-box .after-img {
  239. display: inline-block;
  240. width: 144px;
  241. height: 144px;
  242. border: none;
  243. /*position: absolute;*/
  244. top: 0px;
  245. left: 0px;
  246. /*background: #ffffff;*/
  247. z-index: 20;
  248. }
  249. .after-img img, .uploadImg {
  250. /*position: absolute;*/
  251. width: 100%;
  252. height: 100%;
  253. object-fit: cover; /*根据父容器的尺寸裁剪和缩放图片,以填充整个容器,并保持长宽比例不变。*/
  254. object-position: center; /*指定对象的位置,如果不设置,则默认是center*/
  255. background-size: cover; /*背景图片的大小,如果不设置,则默认是auto*/
  256. background-position: center;
  257. top: 50%;
  258. left: 50%;
  259. transform: translate(-50%, 0%);/*将元素移动到中心*/
  260. border-radius: 50%;
  261. }
  262. </style>
  263. </head>
  264. <body>
  265. <!-- 注册页面 -->
  266. <div class="register login">
  267. <div class="register_loginTitle ">
  268. <div class="upload-img-box">
  269. <div class="input-box">
  270. <input type="file" id="img-file" hidden="hidden" name="选择图片">
  271. </div>
  272. <div class="befor-img">
  273. <img class="uploadImg hand" src="/static/img/upload.png" alt="">
  274. </div>
  275. <div class="after-img">
  276. <img id="img-box" src="" width="30%" height="auto">
  277. </div>
  278. </div>
  279. </div>
  280. <div class="register_inputBox">
  281. <input class="register_nameInput" name="staffName" type="text" placeholder="员工姓名">
  282. <input class="register_phoneInput" name="staffPhone" type="text" placeholder="员工手机号">
  283. </div>
  284. <div class="register_loginButton hand">注册人脸</div>
  285. </div>
  286. <script src="/static/js/jquery.min.js"></script>
  287. <script src="/static/js/msg-box.js"></script>
  288. <script>
  289. $(function(){
  290. $.MsgBox = {
  291. Alert: function(title, msg) {
  292. GenerateHtml("alert", title, msg);
  293. btnOk(); //alert只是弹出消息,因此没必要用到回调函数callback
  294. btnNo();
  295. },
  296. Confirm: function(title, msg, callback) {
  297. GenerateHtml("confirm", title, msg);
  298. btnOk(callback);
  299. btnNo();
  300. }
  301. }
  302. $(".register_loginButton").on("click",function() {
  303. var staffPhone = $(".register_phoneInput").val();
  304. var staffName = $(".register_nameInput").val();
  305. const regex = /^1[3-9]\d{9}$/;
  306. if (staffPhone == "" || !regex.test(staffPhone)){
  307. $.MsgBox.Alert("提示", "手机号为空或不合法,请检查");
  308. return;
  309. }
  310. if (staffName == ""){
  311. $.MsgBox.Alert("提示", "员工姓名为空,请检查");
  312. return;
  313. }
  314. var img = $("#img-box").attr("src");
  315. console.log(img);
  316. $.ajax({
  317. url: "/register",
  318. type: "post",
  319. data: {
  320. staffPhone: staffPhone,
  321. staffName: staffName,
  322. avatar: img
  323. },
  324. success: function(data) {
  325. $.MsgBox.Alert("提示", data.Message);
  326. },
  327. error: function(error) {
  328. console.log(error);
  329. $.MsgBox.Alert("提示", error.responseJSON.Message);
  330. }
  331. })
  332. })
  333. $(document).on("click", ".upload-img-box .befor-img,.upload-img-box .after-img", function (e) {
  334. $(".input-box input").trigger("click");
  335. })
  336. // 使用input 的change事件,监听当文件上传的值进行改变的时候,才触发事件。
  337. $(document).on("change", ".upload-img-box #img-file", function () {
  338. var file = $("#img-file")[0].files[0];
  339. console.log(file);
  340. // file 内容包括: lastModified , lastModifiedDate , name , size , type
  341. var formdata = new FormData();
  342. formdata.append('file', file);
  343. if (window.FileReader) {
  344. var fr = new FileReader();
  345. fr.onloadend = function (e) {
  346. // console.log(this.result);
  347. // document.getElementById("portrait").src = e.target.result;
  348. $("#img-box").attr("src",e.target.result)
  349. $(".upload-img-box .befor-img").addClass("hasImg")
  350. };
  351. //给FileReader对象一个读取完成的方法,
  352. //使用readAsDataURL会返回一个url
  353. //这个值就保存在事件对象的result里
  354. //img通过加载这个地址,完成图片的加载
  355. fr.readAsDataURL(file);
  356. }
  357. //判断图片大小
  358. if (file.size > 3 * 1024 * 1024) {
  359. alert("上传图片不能大于3M");
  360. }
  361. //判断图片数据类型
  362. if (!/.(gif|jpg|jpeg|png|GIF|JPG|bmp)$/.test(file.name)) {
  363. alert("图片类型必须是.gif,jpeg,jpg,png,bmp中的一种");
  364. }
  365. })
  366. })
  367. </script>
  368. </body>
  369. </html>