registerDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <el-dialog
  3. :close-on-click-modal="false"
  4. :visible.sync="telDl"
  5. @close="delDlClose"
  6. class="register-free-dialog"
  7. center>
  8. <i></i>
  9. <h4>为帮助您更好的使用产品,请先验证手机信息</h4>
  10. <p v-if="systemType==='ksAdmin'||systemType==='ksClient'">今日已有<span>{{kaoshiCnt}}</span>人 体验了考试系统</p>
  11. <p v-if="systemType==='pxAdmin'||systemType==='pxClient'">今日已有<span>{{peixunCnt}}</span>人 体验了培训系统</p>
  12. <el-form :model="telChangeDate" status-icon :rules="telRules" ref="ruleTelForm" class="application-scheme-form">
  13. <el-form-item prop="tel">
  14. <el-input v-model="telChangeDate.tel" placeholder="请输入手机号" class="dialog-input-tel"></el-input>
  15. </el-form-item>
  16. <div id="your-dom-id" class="nc-container"></div>
  17. <el-form-item prop="verification">
  18. <div class="verification">
  19. <el-input v-model="telChangeDate.verification" placeholder="请输入验证码" class="dialog-input-code"></el-input>
  20. <el-button @click="checkVerification" :disabled="btnTextDisabled" type="primary" class="jcrk-primary-btn">{{btnText}}</el-button>
  21. </div>
  22. </el-form-item>
  23. <el-form-item prop="company">
  24. <el-input v-model="telChangeDate.company" placeholder="请输入公司名称" class="dialog-input-tel"></el-input>
  25. </el-form-item>
  26. </el-form>
  27. <div class="application-scheme-btn" @click="dialogSave">进入使用</div>
  28. </el-dialog>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'regDialog',
  33. props: {
  34. //弹窗显隐 flag
  35. dialogVisible: {
  36. type: Boolean,
  37. require: true,
  38. },
  39. // ks为考试 px为培训
  40. systemType: {
  41. type: String,
  42. default: 'ksClient',
  43. require: true,
  44. },
  45. },
  46. data() {
  47. return {
  48. telDl: false,
  49. telChangeDate: {},// 弹窗信息
  50. btnTextDisabled: false,
  51. btnText: '获取验证码',
  52. countdown: 60, // 60秒倒计时
  53. sliderData: {},
  54. appKey: 'FFFF0N00000000007EC0',
  55. telRules: {
  56. tel: [
  57. { trigger: 'blur', required: true, message: '请输入手机号' },
  58. ],
  59. verification: [
  60. { trigger: 'blur', required: true, message: '请输入验证码' },
  61. ],
  62. },
  63. kaoshiCnt:0,// 考试人数
  64. peixunCnt:0,// 培训人数
  65. };
  66. },
  67. computed: {
  68. baseUrl() {
  69. },
  70. },
  71. watch:{
  72. // 监听 addOrUpdateVisible 改变
  73. dialogVisible(oldVal,newVal){
  74. this.telDl = this.dialogVisible;
  75. if(this.telDl){
  76. this.sliderFun();
  77. }
  78. },
  79. },
  80. methods: {
  81. // 关闭
  82. delDlClose(){
  83. this.countdown = -1;
  84. this.telChangeDate.appKey=undefined;
  85. this.$refs.ruleTelForm.resetFields();
  86. // 子组件调用父组件方法,并传递参数
  87. this.$emit('changeShow','false')
  88. },
  89. // 滑块
  90. sliderFun() {
  91. const nc_token = [this.appKey, (new Date()).getTime(), Math.random()].join(':');
  92. console.log(nc_token);
  93. const NC_Opt = {
  94. //声明滑动验证需要渲染的目标元素ID。
  95. renderTo: '#your-dom-id',
  96. //应用类型标识。它和使用场景标识(scene字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在人机验证控制台的配置管理页签找到对应的appkey字段值,请务必正确填写。
  97. appkey: this.appKey,
  98. //使用场景标识。它和应用类型标识(appkey字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在人机验证控制台的配置管理页签找到对应的scene值,请务必正确填写。
  99. scene: 'nc_message',
  100. //滑动验证码的主键,请勿将该字段定义为固定值。确保每个用户每次打开页面时,其token值都是不同的。系统默认的格式为:”您的appkey”+”时间戳”+”随机数”。
  101. token: nc_token,
  102. //滑动条的宽度。
  103. customWidth: 300,
  104. //业务键字段,可为空。为便于线上问题的排查,建议您按照线上问题定位文档中推荐的方法配置该字段值。
  105. trans: { 'key1': 'code0' },
  106. //通过Dom的ID属性自动填写trans业务键,可为空。建议您按照线上问题定位文档中推荐的方法配置该字段值。
  107. elementID: ['usernameID'],
  108. //是否自定义配置底层采集组件。如无特殊场景,请使用默认值(0),即不自定义配置底层采集组件。
  109. is_Opt: 0,
  110. //语言。PC端Web页面场景默认支持18国语言,详细配置方法请参见自定义文案与多语言文档。
  111. language: 'cn',
  112. //是否启用。一般情况,保持默认值(true)即可。
  113. isEnabled: true,
  114. //内部网络请求的超时时间。一般情况建议保持默认值(3000ms)。
  115. timeout: 3000,
  116. //允许服务器超时重复次数,默认5次。超过重复次数后将触发报错。
  117. times: 5,
  118. //用于自定义滑动验证各项请求的接口地址。一般情况,请勿配置该参数。
  119. apimap: {
  120. // 'analyze': '//a.com/nocaptcha/analyze.jsonp',
  121. // 'get_captcha': '//b.com/get_captcha/ver3',
  122. // 'get_captcha': '//pin3.aliyun.com/get_captcha/ver3'
  123. // 'get_img': '//c.com/get_img',
  124. // 'checkcode': '//d.com/captcha/checkcode.jsonp',
  125. // 'umid_Url': '//e.com/security/umscript/3.2.1/um.js',
  126. // 'uab_Url': '//aeu.alicdn.com/js/uac/909.js',
  127. // 'umid_serUrl': 'https://g.com/service/um.json'
  128. },
  129. //前端滑动验证通过时会触发该回调参数。您可以在该回调参数中将请求标识(token)、会话ID(sessionid)、签名串(sig)字段记录下来,随业务请求一同发送至您的服务端调用验签。
  130. callback: (data) => {
  131. this.sliderData = Object.assign({}, data, {
  132. appkey: NC_Opt.appkey,
  133. scene: NC_Opt.scene,
  134. });
  135. console.log( this.sliderData);
  136. },
  137. };
  138. let date11 = () => {
  139. let _date = new Date();
  140. let year = _date.getFullYear().toString();
  141. let month = _date.getMonth().toString();
  142. let day = _date.getDate().toString();
  143. let a = _date.getHours().toString();
  144. let b = _date.getMinutes().toString();
  145. let c = _date.getSeconds().toString();
  146. return year + month + day + a + b + c;
  147. };
  148. let c = date11();
  149. const scripts = [
  150. `https://g.alicdn.com/sd/ncpc/nc.js?t=${c}`,
  151. ];
  152. this.seriesLoadScripts(scripts, function () {
  153. var nc = new noCaptcha(NC_Opt);
  154. nc.upLang('cn', {
  155. _startTEXT: '请按住滑块,拖动到最右边',
  156. _yesTEXT: '验证通过',
  157. _error300: '哎呀,出错了,点击<a href="javascript:__nc.reset()">刷新</a>再来一次',
  158. _errorNetwork: '网络不给力,请<a href="javascript:__nc.reset()">点击刷新</a>',
  159. });
  160. });
  161. },
  162. // 倒计时60秒
  163. setTime() {
  164. if (this.countdown === 0) {
  165. this.btnTextDisabled = false;
  166. this.btnText = '免费获取验证码';
  167. this.countdown = 60;
  168. } else if(this.countdown === -1){
  169. this.btnTextDisabled = false;
  170. this.btnText = '获取验证码';
  171. this.countdown = 60;
  172. } else {
  173. this.btnTextDisabled = true;
  174. this.btnText = '重新发送(' + this.countdown + 's)';
  175. this.countdown--;
  176. setTimeout(() => {
  177. this.setTime();
  178. }, 1000);
  179. }
  180. },
  181. // 验证码
  182. checkVerification() {
  183. if (this.telChangeDate.tel === undefined) {
  184. this.$message.error('请输入手机号');
  185. return;
  186. }
  187. if (this.sliderData.appkey === undefined) {
  188. this.$message.error('请先进行滑块校验');
  189. return;
  190. }
  191. let req = {
  192. 'appkey': this.sliderData.appkey,
  193. 'phone': this.telChangeDate.tel,
  194. 'scene': this.sliderData.scene,
  195. 'sessionid': this.sliderData.csessionid,
  196. 'sig': this.sliderData.sig,
  197. 'token': this.sliderData.token,
  198. 'type': 0,
  199. }
  200. this.$axios.$post('/sendCode',req).then(res=>{
  201. if (res.code === 0 && res.data) {
  202. this.setTime();
  203. }else {
  204. this.$message.error(res.msg||'手机号已存在');
  205. }
  206. })
  207. },
  208. /**
  209. * 串联加载指定的脚本
  210. * 串联加载[异步]逐个加载,每个加载完成后加载下一个
  211. * 全部加载完成后执行回调
  212. * @param array|string 指定的脚本们
  213. * @param function 成功后回调的函数
  214. * @return array 所有生成的脚本元素对象数组
  215. * 异步加载js后运行回调函数callback / scripts 为数组或字符串
  216. */
  217. seriesLoadScripts(scripts, callback) {
  218. if (typeof (scripts) != 'object') {
  219. var scripts = [scripts];
  220. }
  221. var HEAD = document.getElementsByTagName('head').item(0) || document.documentElement;
  222. var s = new Array(), last = scripts.length - 1, recursiveLoad = function (i) { //递归
  223. s[i] = document.createElement('script');
  224. s[i].setAttribute('type', 'text/javascript');
  225. s[i].onload = s[i].onreadystatechange = function () { //Attach handlers for all browsers
  226. if (!/*@cc_on!@*/0 || this.readyState == 'loaded' || this.readyState == 'complete') {
  227. this.onload = this.onreadystatechange = null;
  228. this.parentNode.removeChild(this);
  229. if (i != last) {
  230. recursiveLoad(i + 1);
  231. } else if (typeof (callback) == 'function') {
  232. callback();
  233. }
  234. }
  235. };
  236. s[i].setAttribute('src', scripts[i]);
  237. HEAD.appendChild(s[i]);
  238. };
  239. recursiveLoad(0);
  240. },
  241. // 进入使用
  242. dialogSave(){
  243. this.$refs.ruleTelForm.validate((valid) => {
  244. if (valid) {
  245. // 请求后台
  246. const options = {
  247. tel: this.telChangeDate.tel,
  248. code: this.telChangeDate.verification,
  249. company: this.telChangeDate.company,
  250. };
  251. this.$axios.$post('/user/tiyan/add',options).then(res=>{
  252. if (res.code === 0 && res.data) {
  253. this.telDl = false;
  254. if(this.systemType === 'ksAdmin'){
  255. window.open('http://8.144.165.203:8087/kaoshi/admin/loginForTiyan.html')
  256. }else if(this.systemType === 'ksClient') {
  257. window.open('http://8.144.165.203:8087/kaoshi/mta/loginForTiyan.html')
  258. }else if(this.systemType === 'pxAdmin'){
  259. window.open('http://8.144.165.203:8087/peixun/admin/loginForTiyan.html')
  260. }else{
  261. window.open('http://8.144.165.203:8087/peixun/mta/loginForTiyan.html')
  262. }
  263. this.$message.success('申请成功');
  264. } else {
  265. this.$message.error('申请失败');
  266. }
  267. });
  268. }
  269. });
  270. },
  271. },
  272. created() {
  273. // 页面初始化
  274. this.$axios.$post('/user/tiyan/info').then(res=>{
  275. this.kaoshiCnt = res.data.kaoshiCnt;
  276. this.peixunCnt = res.data.kaoshiCnt;
  277. });
  278. },
  279. };
  280. </script>