const{createApp}=Vue const{createVuetify}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},login:{tab:'username',mode:0,username:undefined,email:undefined,phoneNum:undefined,password:undefined,showPassword:false,isLoading:false,failCount:0,warning:false,},theme:{dark:false,},search:{width:80,text:null,loading:false,},} const App={data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)}},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},goBack(){window.history.back()},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},async doLogin(){this.login.isLoading=true try{const response=await axios.post('/fapi/v1/user/login',{username:this.login.username,email:this.login.email,phoneNum:this.login.phoneNum,password:this.login.password,mode:this.login.mode,}) if(response.data.code===0){this.successAlert('登录成功!') setTimeout(()=>{window.location.href='/my/';},800);}else{if(response.data.data&&response.data.data.failCount>=3){this.login.failCount=response.data.data.failCount this.login.warning=true} this.failureAlert('登录失败: '+response.data.msg)}}catch(error){this.failureAlert(error)} this.login.isLoading=false},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},},watch:{'login.tab':{handler:function(newV,oldV){if(newV==="username"){this.login.mode=0 this.login.email='' this.login.phoneNum=''}else if(newV==="email"){this.login.mode=1 this.login.username='' this.login.phoneNum=''}else if(newV==="phoneNum"){this.login.mode=2 this.login.username='' this.login.email=''}},immediate:true},},} const vuetify=Vuetify.createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")