当前位置: 首页 > Web前端 > vue.js

electron-vue聊天实例-electron仿微信电脑端界面

时间:2023-03-31 19:52:23 vue.js

椤圭洰浠嬬粛锛歟lectron-vChat鑱婂ぉ鏄熀浜巈lectron+electron-vue+vue+vuex+Nodejs+vue-router绛夋妧鏈紑鍙戠殑楂樹豢寰俊pc瀹㈡埛绔€傜晫闈㈣亰澶╁椤圭洰瀹炵幇娑堟伅鍙戦€?琛ㄦ儏銆佸浘鐗?瑙嗛棰勮銆佹嫋鎷戒笂浼?绮樿创鎴浘鍙戦€?寰俊dll鎴浘銆佸彸閿彍鍗曘€佹湅鍙嬪湀/绾㈠寘/鎹㈣偆绛夊姛鑳介瑙堝浘鐗?鎶€鏈鏋?搴旂敤鎶€鏈?electron+electron-vue+vue鐘舵€佺鐞?Vuex鍦板潃璺敱:Vue-router瀛椾綋鍥炬爣:闃块噷iconfont瀛椾綋鍥炬爣搴撳脊绐楁彃浠?wcPop鎵撳寘宸ュ叿:electron-builder鍥剧墖棰勮:vue-photo-preview瑙嗛缁勪欢锛歷ue-video-player濡備笂鍥撅細鍙互鑷敱鍒囨崲妗岄潰鑱婂ぉ鑳屾櫙鐨偆Electron鏄疓ithub寮€鍙戠殑寮€婧愬簱锛屼娇鐢℉TML銆丆SS鍜孞avaScript鏋勫缓璺ㄥ钩鍙版闈㈠簲鐢?https://electronjs.org/鑷充簬濡備綍鎼缓寮€鍙戠幆澧冨拰浣跨敤electron-vue锛屽彲浠ュ弬鑰冨畼缃戝拰鎼滅储璧勬枡锛屽熀浜巚ue璇硶鏋勫缓electron搴旂敤鐨勭ず渚嬩唬鐮併€俬ttps://electron.org.cn/vue/i...https://simulatedgreg.gitbook...electron涓绘祦绋嬶細鍒涘缓鍜岄厤缃甧lectron涓€氳繃BrowserWindow瀵硅薄鍒涘缓鍜屾帶鍒舵祻瑙堝櫒绐楀彛鏈塵ainsrc鐩綍,renderer涓や釜鏂囦欢澶癸紝鍒嗗埆鏄富杩涚▼鍜屾覆鏌撹繘绋嬶紝鍙渶瑕佷慨鏀归厤缃獥鍙d腑鐨剆rc/main/index.js鏂囦欢鍗冲彲銆俵etmainWinlettrayletforceQuit=falseletloggedin=false/***鍒涘缓涓荤獥鍙?==============================================*/functioncreateMainWin(){mainWin=newBrowserWindow({//鑳屾櫙棰滆壊//backgroundColor:'#ebebeb',width:Common.WIN_SIZE_MAIN.width,height:Common.WIN_SIZE_MAIN.height,title:Common.WIN_TITLE,useContentSize:true,autoHideMenuBar:true,//鏃犺竟妗嗙獥鍙rame:false,resizable:true,//鍒涘缓绐楀彛鏃舵槸鍚︽樉绀猴紝榛樿鍊间负trueshow:false,webPreferences:{//devTools:false,webSecurity:false}})mainWin.setMenu(null)mainWin.loadURL(Common.WIN_LOAD_URL())mainWin.once('ready-to-show',()=>{mainWin.show()mainWin.focus()})//鐐瑰嚮鍏抽棴鏈€灏忓埌鎵樼洏鍒ゆ柇mainWin.on('close',(e)=>{if(logined&&!forceQuit){e.preventDefault()mainWin.hide()}else{mainWin=nullapp.quit()}})...apptray.createTray()}app.on('ready',createMainWin)app.on('activate',()=>{if(mainWin===null){createMainWin()}})...electron鍒涘缓鎵樼洏鍥炬爣锛屾墭鐩樺浘鏍囬棯鐑侊紝鏈€灏忓寲鍒版墭鐩橈紝鎵樼洏鍙抽敭/***鎵樼洏鍥炬爣浜嬩欢*/letflashTrayTimer=nulllettrayIco1=`${__static}/icon.ico`lettrayIco2=`${__static}/empty.ico`letapptray={//鍒涘缓鎵樼洏鍥炬爣createTray(){tray=newTray(trayIco1)constmenu=Menu.buildFromTemplate([{label:'鎵撳紑涓籭nterface',icon:`${__static}/tray-ico1.png`,鐐瑰嚮:()=>{if(mainWin.isMinimized())mainWin.restore()mainWin.show()mainWin.focus()this.flashTray(false)}},{label:'About',},{label:'閫€鍑?,鐐瑰嚮:()=>{if(process.platform!=='darwin'){mainWin.show()//娓呴櫎鐧诲綍淇℃伅mainWin.webContents.send('clearLoggedInfo')forceQuit=truemainWin=nullapp.quit()}}},])tray.setContextMenu(menu)tray.setToolTip('electron-vchatv1.0.0')//鎵樼洏鐐瑰嚮浜嬩欢tray.on('click',()=>{if(mainWin.isMinimized())mainWin.restore()mainWin.show()mainWin.focus()this.flashTray(false)})},//鎵樼洏鍥炬爣flashflashTray(flash){lethasIco=falseif(flash){if(flashTrayTimer)杩斿洖flashTrayTimer=setInterval(()=>{tray.setImage(hasIco?trayIco1:trayIco2)hasIco=!hasIco},500)}else{if(flashTrayTimer){clearInterval(flashTrayTimer)flashTrayTimer=null}tray.setImage(trayIco1)}},//閿€姣佹墭鐩樺浘鏍嘾estroyTray(){this.flashTray(false)tray.destroy()tray=null}}鐐瑰嚮绐楀彛鍏抽棴锛岀洃鍚琧lose浜嬩欢,骞跺垽鏂槸鍚︽渶灏忓寲鍒版墭鐩?/鐐瑰嚮鍏抽棴鏈€灏忓寲鍒版墭鐩樺垽鏂璵ainWin.on('close',(e)=>{if(logined&&!forceQuit){e.preventDefault()mainWin.hide()}else{mainWin=nullapp.quit()}})electron娓叉煋杩囩▼锛氫富鍏ュ彛椤甸潰閰嶇疆/***@Desc涓诲叆鍙i〉闈S*@aboutQ:282310962wx:xy190310*/importVuefrom'vue'importaxiosfrom'axios'importAppfrom'./App'importrouterfrom'./router'importstorefrom'./store'//瀵煎叆缁勪欢閰嶇疆import$componentsfrom'./components'Vue.use($components)if(!process.env.IS_WEB)Vue.use(require('vue-electron'))Vue.http=Vue.prototype.$http=axios/*eslint-disableno-new*/newVue({components:{App},router,store,template:''}).$mount('#app')涓荤獥鍙i〉闈㈠垎涓轰晶杈规爮+涓诲竷灞€锛岄《閮ㄤ富甯冨眬鍖呭惈鏈€澶?鏈€灏忓寲鍜屽叧闂寜閽?template>

electron鏃犺竟妗嗙獥鍙e疄鐜版嫋鍔ㄣ€佹渶澶у寲/鏈€灏忓寲銆佸叧闂姛鑳介厤缃甪rame:false鍙互瀹炵幇鏃犺竟妗嗙獥浣擄紝鎷栧姩绐楀彛鍔熻兘闇€瑕佸崟鐙鐞嗛€氳繃mousedown銆乵ousemove绛変簨浠跺鐞嗚缃紝鎷栨嫿鍖哄煙css灞炴€?webkit-app-region璁剧疆css-webkit-app-region:drag;鍙互瀹炵幇鎷栨嫿绐楀彛璁剧疆-webkit-app-region:drag,涓嬮潰鐨勫厓绱犱笉鑳界偣鍑伙紝鍙互璁剧疆no-drag浠ュ崟鍑诲厓绱爐opwinbar.vue缁勪欢import{app,remote,ipcRenderer}from'electron'import{mapState,mapMutations}from'vuex'letcurrentWin=remote.getCurrentWindow()exportdefault{props:{title:String,},data(){return{//鏄惁缃《isAlwaysOnTop:false,//绐楀彛鏄惁鍙互鏈€灏忓寲isMinimizable:true,//绐楀彛鏄惁鍙互鏈€澶у寲isMaximizable:true,}},computed:{...mapState(['isWinMaxed'])},mounted(){if(!currentWin.isMinimizable()){this.isMinimizable=false}if(!currentWin.isMaximizable()){this.isMaximizable=false}if(this.isWinMaxed&¤tWin.isMaximizable()){currentWin.maximize()}//鐩戝惉鏄惁鏈€澶у寲currentWin.on('maximize',()=>{this.SET_WINMAXIMIZE(true)})currentWin.on('unmaximize',()=>{this.SET_WINMAXIMIZE(false)})},methods:{...mapMutations(['SET_WINMAXIMIZE']),//椤堕儴绐楀彛handleFixTop(){this.isAlwaysOnTop=!this.isAlwaysOnTopcurrentWin.setAlwaysOnTop(this.isAlwaysOnTop)},//鏈€灏忓寲handleMin(){currentWin.minimize()},//鏈€澶у寲handleMax(){if(!currentWin.isMaximizable())returnif(currentWin.isMaximized()){currentWin.unmaximize()this.SET_WINMAXIMIZE(false)}else{currentWin.maximize()this.SET_WINMAXIMIZE(true)}},//closehandleQuit(){currentWin.close()}}}鍦╡lectron缂栬緫鍣ㄥ厜鏍囧鎻掑叆琛ㄦ儏锛宒iveditablecontenteditable="true"鍙屽悜缁戝畾锛宔lectron鎴浘濡備綍Vue鍑芥暟瀹炵幇缂栬緫妗嗗厜鏍囧鎻掑叆鍔ㄦ€佽〃鎯卌ontenteditable锛熻繖閲屽氨涓嶅浠嬬粛浜嗭紝澶у鍙互鐪嬬湅涔嬪墠鐨勪竴绡囧垎浜枃绔燛lectron+vue瀹炵幇divcontenteditable鍔熻兘|鎴浘瀹屾垚锛屽熀浜巈lectron+vue寮€鍙戜豢寰俊妗岄潰鑱婂ぉ瀹炰緥鍒嗕韩鍒拌繖閲岋紝甯屾湜瀵瑰ぇ瀹舵湁鎵€甯姪锛侊紒馃挭馃挭鏈€鍚庡垎浜竴涓猽niapp+vue绀轰緥椤圭洰uniapp鍗虫椂鑱婂ぉ|vue+uniapp浠垮井淇pp鑱婂ぉ瀹炰緥|uniapp浠垮井淇$晫闈?/p>