52,797
社区成员
发帖
与我相关
我的任务
分享
<div class="layui-form-item">
<label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="phone"></label>
<input type="text" name="phone" id="phone" lay-verify="phone" placeholder="手机" class="layui-input">
</div>
<div class="layui-form-item">
<div class="layui-row">
<div class="layui-col-xs7">
<label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="code"></label>
<input type="text" name="code" id="code" lay-verify="required" placeholder="验证码"
class="layui-input">
</div>
<div class="layui-col-xs5">
<div style="margin-left: 10px;">
<button name="btn" type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
id="btn" onclick="time(this)">获取验证码
</button>
</div>
</div>
</div>
</div>
<script src="resource/layuiadmin/layui/layui.js"></script>
<script>
layui.config({
base: 'resource/layuiadmin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'user'], function () {
var $ = layui.$
, setter = layui.setter
, admin = layui.admin
, form = layui.form
, router = layui.router()
, search = router.search;
form.render();
//$("body").on("click","#get-vercode",function(){
//alert(1);
//});
$("#get-vercode").click(function () {
this.src = "system/admin/validateCode?t=" + (new Date).getTime();
});
//提交
form.on('submit(user-login-submit)', function (data) {
doLogin(data.field);
});
/**
* 存字符形式
* @returns
*/
function doLogin(params) {
var index = layer.load(1, {shade: 0.7});
$.ajax({
type: 'post',
url: 'system/admin/dologin',
dataType: "json",
traditional: true,
//设置contentType类型为json
//contentType : 'application/json;charset=utf-8',
//json数据
data: params,
//请求成功后的回调函数
success: function (data) {
layer.close(index);
if (data.success) {
layer.msg(data.msg, {
offset: 'auto'
, icon: 1
, shade: 0.3
, shadeClose: true
, anim: 1
, time: 2000
},
function () {
location.href = '/system/admin/index';
});
//后台主页
} else {
layer.msg(data.msg, {
offset: 'auto'
, icon: 2
, shade: 0.3
, shadeClose: true
, anim: 1
});
}
},
error: function () {
layer.close(index);
layer.msg("网络请求失败!", {
offset: 'auto'
, icon: 2
, shade: 0.3
, shadeClose: true
, anim: 1
});
}
});
}
/**
* 短信验证码
* @type {string}
*/
var sms = "";
$("#btn").click(function () {
var phone = $("#phone").val();
if (phone != "") {
$.ajax({
type: "POST",
URL: "/smscode/sendsms/logged", //发送请求 admin\core\arm\controller\SmsCodeController system/core/arm/controller/sendSms
data: {
smsType: "1004",
phone: phone
},
success: function (res) {
sms = res;
}
});
} else {
alert("请输入手机号");
return false;
}
});
$("#lo").click(function () {
var code = $("#code").val();
if (code == "") {
alert("请输入验证码");
} else {
if (sms == code) {
window.location.href = "success.jsp";
} else {
alert("验证码错误");
};
};
});
});
</script>
package com.zwh.admin.core.arm.controller.index;
import com.yhzq.base.ccl.datastructure.Dto;
import com.yhzq.base.ccl.datastructure.impl.ResponseDto;
import com.yhzq.base.mvc.BaseController;
import com.yhzq.common.service.core.SmsCodeService;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
*
* 功能描述 短信controller
*
* @author chenshuai QQ:394785275
* @date 2019/1/2 21:45
*/
@Controller
@RequestMapping("/smscode")
public class SmsCodeController extends BaseController {
@Resource(name = "smsCodeService")
private SmsCodeService smsCodeService;
@RequestMapping(value = "/sendsms/logged", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public Object sendSms() throws Exception {
Dto<String, Object> pDto = super.getParamAsDto();
ResponseDto<String, Object> responseDto = super.newResponseDto();
smsCodeService.sendMsg(responseDto, pDto.getAsInteger("smsType"), pDto.getAsString("receiver"), pDto);
return super.write(responseDto, null);
}
}