registerDialog.vue 11 KB

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