条件样式
This commit is contained in:
parent
bb61474472
commit
6f3b109c90
2 changed files with 96 additions and 29 deletions
101
src/App.vue
101
src/App.vue
|
@ -7,7 +7,7 @@
|
||||||
<b-avatar
|
<b-avatar
|
||||||
button
|
button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
:text="avatarAbbr"
|
:text="avatarAbbr(nickname)"
|
||||||
size="4em"
|
size="4em"
|
||||||
class="my-3"
|
class="my-3"
|
||||||
></b-avatar>
|
></b-avatar>
|
||||||
|
@ -21,32 +21,45 @@
|
||||||
</b-row>
|
</b-row>
|
||||||
</b-container>
|
</b-container>
|
||||||
</div>
|
</div>
|
||||||
|
<b-alert
|
||||||
|
v-model="error"
|
||||||
|
class="position-fixed fixed-top m-3"
|
||||||
|
variant="danger"
|
||||||
|
dismissible
|
||||||
|
>
|
||||||
|
Error: {{ loginInfo }}
|
||||||
|
</b-alert>
|
||||||
<div class="vh-100 d-flex flex-column" v-if="loggedIn">
|
<div class="vh-100 d-flex flex-column" v-if="loggedIn">
|
||||||
<div class="flex-fill overflow-auto pt-3 px-3">
|
<div class="flex-fill overflow-auto pt-3 px-3">
|
||||||
<div class="d-flex my-2">
|
<div
|
||||||
<b-avatar variant="primary" text="ZZ" class="my-2 mr-2"> </b-avatar>
|
v-for="(msg, index) in messages"
|
||||||
|
:key="index"
|
||||||
|
class="d-flex my-2"
|
||||||
|
:class="{ 'flex-row-reverse': nickname == msg.nickname }"
|
||||||
|
>
|
||||||
|
<b-avatar
|
||||||
|
:variant="nickname == msg.nickname ? 'success' : 'primary'"
|
||||||
|
:text="msg.avatar"
|
||||||
|
class="my-2 mr-2"
|
||||||
|
:class="nickname == msg.nickname ? 'ml-2' : 'mr-2'"
|
||||||
|
>
|
||||||
|
</b-avatar>
|
||||||
<div class="d-flex flex-column">
|
<div class="d-flex flex-column">
|
||||||
<p class="my-1">Zhao Zuohong</p>
|
<p class="my-1" :class="{ 'text-right': nickname == msg.nickname }">
|
||||||
<b-button variant="primary" class="mb-2 mr-5 text-left"
|
{{ msg.nickname }}
|
||||||
>Earth is the third planet from the Sun and the only astronomical
|
</p>
|
||||||
object known to harbor life.</b-button
|
<b-button
|
||||||
>
|
:variant="nickname == msg.nickname ? 'success' : 'primary'"
|
||||||
</div>
|
class="mb-2 text-left"
|
||||||
</div>
|
:class="nickname == msg.nickname ? 'ml-5' : 'mr-5'"
|
||||||
<div class="d-flex flex-row-reverse my-2">
|
>{{ msg.message }}</b-button
|
||||||
<b-avatar variant="success" text="ZZ" class="my-2 ml-2"> </b-avatar>
|
|
||||||
<div class="d-flex flex-column">
|
|
||||||
<p class="my-1 text-right">Zhao Zuohong</p>
|
|
||||||
<b-button variant="success" class="mb-2 ml-5 text-left"
|
|
||||||
>It is the densest planet in the Solar System and the largest and
|
|
||||||
most massive of the four rocky planets.</b-button
|
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<b-form class="d-flex m-3">
|
<b-form class="d-flex m-3" @submit.prevent="sendMessage">
|
||||||
<b-form-input class="flex-fill mr-2"> </b-form-input>
|
<b-form-input class="flex-fill mr-2" v-model="message"> </b-form-input>
|
||||||
<b-button pill variant="success">Button</b-button>
|
<b-button pill variant="success" type="submit">Button</b-button>
|
||||||
</b-form>
|
</b-form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,14 +69,23 @@
|
||||||
import { Component, Vue } from "vue-property-decorator";
|
import { Component, Vue } from "vue-property-decorator";
|
||||||
import { ipcRenderer } from "electron";
|
import { ipcRenderer } from "electron";
|
||||||
|
|
||||||
|
interface Message {
|
||||||
|
avatar: string;
|
||||||
|
nickname: string;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class App extends Vue {
|
export default class App extends Vue {
|
||||||
private nickname = "";
|
private nickname = "Zhao Zuohong";
|
||||||
private loggedIn = false;
|
private loggedIn = true;
|
||||||
private error = true;
|
private error = false;
|
||||||
get avatarAbbr(): string {
|
private loginInfo = "";
|
||||||
|
private message = "";
|
||||||
|
private messages: Array<Message> = [];
|
||||||
|
public avatarAbbr(nickname: string): string {
|
||||||
const chineseChar = new RegExp("[\u4E00-\u9FA5]");
|
const chineseChar = new RegExp("[\u4E00-\u9FA5]");
|
||||||
let firstChar = this.nickname.charAt(0);
|
let firstChar = nickname[0];
|
||||||
if (chineseChar.test(firstChar)) {
|
if (chineseChar.test(firstChar)) {
|
||||||
return firstChar;
|
return firstChar;
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,13 +93,38 @@ export default class App extends Vue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public login(): void {
|
public login(): void {
|
||||||
console.log(this.nickname);
|
|
||||||
ipcRenderer.send("login", this.nickname);
|
ipcRenderer.send("login", this.nickname);
|
||||||
ipcRenderer.on("loginStatus", (_, success) => {
|
ipcRenderer.once("loginStatus", (_, success, message) => {
|
||||||
if (success) {
|
if (success) {
|
||||||
this.loggedIn = true;
|
this.loggedIn = true;
|
||||||
|
} else {
|
||||||
|
this.error = true;
|
||||||
|
this.loginInfo = message;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public sendMessage(): void {
|
||||||
|
ipcRenderer.send("message", this.message);
|
||||||
|
}
|
||||||
|
mounted(): void {
|
||||||
|
this.messages.push({
|
||||||
|
avatar: "EE",
|
||||||
|
nickname: "EE0000",
|
||||||
|
message:
|
||||||
|
"The Old Spanish Trail half dollar was a commemorative coin struck by the United States Bureau of the Mint in 1935.",
|
||||||
|
});
|
||||||
|
this.messages.push({
|
||||||
|
avatar: "66",
|
||||||
|
nickname: "66CCFF",
|
||||||
|
message:
|
||||||
|
"It was designed by L. W. Hoffecker, a coin dealer who had been the moving force behind the effort for a Gadsden Purchase half dollar, vetoed by President Herbert Hoover in 1930, and he sought another commemorative coin that he could control if authorizing legislation was passed.",
|
||||||
|
});
|
||||||
|
this.messages.push({
|
||||||
|
avatar: "ZH",
|
||||||
|
nickname: "Zhao Zuohong",
|
||||||
|
message:
|
||||||
|
"He chose the travels of Spanish officer Álvar Núñez Cabeza de Vaca in the early 16th century.",
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
import { app, protocol, BrowserWindow, ipcMain } from "electron";
|
import { app, protocol, BrowserWindow, ipcMain } from "electron";
|
||||||
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||||
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
|
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
|
||||||
|
|
||||||
|
import net from "net";
|
||||||
|
|
||||||
const isDevelopment = process.env.NODE_ENV !== "production";
|
const isDevelopment = process.env.NODE_ENV !== "production";
|
||||||
|
|
||||||
// Scheme must be registered before the app is ready
|
// Scheme must be registered before the app is ready
|
||||||
|
@ -79,7 +82,24 @@ if (isDevelopment) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let client: net.Socket;
|
||||||
|
|
||||||
ipcMain.on("login", (event, nickname) => {
|
ipcMain.on("login", (event, nickname) => {
|
||||||
event.reply("loginStatus", true);
|
if (nickname.length <= 3) {
|
||||||
console.log(nickname);
|
event.reply("loginStatus", false, "Nickname too short!");
|
||||||
|
} else {
|
||||||
|
event.reply("loginStatus", true, "");
|
||||||
|
client = net.createConnection({ port: 8000 }, () => {
|
||||||
|
console.log("connected to server.");
|
||||||
|
client.write(`login: ${nickname}\n`);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on("data", (data) => {
|
||||||
|
console.log(data.toString());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.on("message", (_, message) => {
|
||||||
|
client.write(message);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue