Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import router from '@ohos.router'
- import fetch from '@system.fetch';
- import promptAction from '@ohos.promptAction';
- export default {
- goToRegeditPage(){
- console.info("login","点击了注册页面")
- router.replaceUrl({url:"pages/regedit/index"})
- },
- test_info(txt) {
- console.info("__TEST__: ", txt);
- },
- if_roles_login(formData, role) {
- console.info("__TEST__,"+JSON.stringify(formData))
- let ret_ok = false;
- fetch.fetch({
- url: this.$t("strings.url")+ role + '/login', //服务的地址
- data:formData.value, //可有可无,提交的数据
- method:"POST",
- header: {
- 'Content-Type': 'application/json'
- },
- success:(res) => {
- // this.test_info(JSON.parse(res.data).name === undefined)
- if(JSON.parse(res.data).name === undefined) {
- this.test_info("错误错误" + role)
- }
- if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
- router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
- ret_ok = true;
- }else{
- //登录失败进行Toast提示
- // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
- this.test_info("登录失败")
- }
- },
- });
- this.test_info(ret_ok)
- return ret_ok;
- },
- // TODO: 融合在同一个中
- if_cleaner_login(formData){
- console.info("__TEST__,"+JSON.stringify(formData))
- let ok = false;
- fetch.fetch({
- url: this.$t("strings.url")+'cleaner/login', //服务的地址
- data:formData.value, //可有可无,提交的数据
- method:"POST",
- header: {
- 'Content-Type': 'application/json'
- },
- success:(res) => {
- // this.test_info(JSON.parse(res.data).name === undefined)
- if(JSON.parse(res.data).name === undefined) {
- this.test_info("错误错误")
- }
- if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
- router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
- ok = true;
- }else{
- //登录失败进行Toast提示
- // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
- this.test_info("登录失败")
- }
- },
- });
- return ok
- },
- if_customer_login(formData){
- console.info("__TEST__,"+JSON.stringify(formData))
- let ok = false;
- fetch.fetch({
- url: this.$t("strings.url")+'customer/login', //服务的地址
- data:formData.value, //可有可无,提交的数据
- method:"POST",
- header: {
- 'Content-Type': 'application/json'
- },
- success:(res) => {
- // this.test_info(JSON.parse(res.data).name === undefined)
- if(JSON.parse(res.data).name === undefined) {
- this.test_info("错误错误")
- }
- if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
- router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
- ok = true;
- }else{
- //登录失败进行Toast提示
- // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
- this.test_info("登录失败")
- }
- },
- });
- return ok;
- },
- if_management_login(formData){
- console.info("__TEST__,"+JSON.stringify(formData))
- let ok = false;
- fetch.fetch({
- url: this.$t("strings.url")+'management/login', //服务的地址
- data:formData.value, //可有可无,提交的数据
- method:"POST",
- header: {
- 'Content-Type': 'application/json'
- },
- success:(res) => {
- // this.test_info(JSON.parse(res.data).name === undefined)
- if(JSON.parse(res.data).name === undefined) {
- this.test_info("错误错误")
- }
- if(JSON.parse(res.data).name != null){ //登录成功,res.data是json数据
- router.replaceUrl({url:"pages/main/index",params:JSON.parse(res.data)})
- ok = true;
- }else{
- //登录失败进行Toast提示
- // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
- this.test_info("登录失败")
- }
- },
- });
- return true;
- },
- dispose_diff_login(formData) {
- // this.test_info("dkkdjlkfj;sdkjf")
- // let hasName = this.if_cleaner_login(formData) === true;
- // if(hasName === false) hasName = this.if_customer_login(formData) === true;
- // if(hasName === false) hasName = this.if_management_login(formData) === true;
- // this.test_info(hasName);
- // if(hasName === false) {
- // promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
- // this.test_info("都没有")
- // }
- this.test_info("start")
- let hasName = this.if_roles_login(formData, "cleaner") === true;
- if(hasName === false) hasName = this.if_roles_login(formData, "customer") === true;
- if(hasName === false) hasName = this.if_roles_login(formData, "management") === true;
- this.test_info("last " + hasName)
- if(hasName === false) {
- promptAction.showToast({message:"账号或密码输入错误!",duration:5000})
- this.test_info("都没有")
- }
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement