Skip to content

Commit

Permalink
perf: 优化数据结构
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Mar 19, 2024
1 parent 0be6c70 commit 6e68f39
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 33 deletions.
11 changes: 9 additions & 2 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1101,10 +1101,17 @@ public function umeng__alias()
];
$row = UmengAlias::where($inArray);
if ($row->exists()) {
$row->update(['updated_at' => Carbon::now()]);
$row->update([
'ua' => $data['userAgent'],
'device' => $data['deviceModel'],
'updated_at' => Carbon::now()
]);
return Base::retSuccess('别名已存在');
}
$row = UmengAlias::createInstance($inArray);
$row = UmengAlias::createInstance(array_merge($inArray, [
'ua' => $data['userAgent'],
'device' => $data['deviceModel'],
]));
if ($row->save()) {
return Base::retSuccess('添加成功');
} else {
Expand Down
38 changes: 38 additions & 0 deletions database/migrations/2024_03_20_024119_add_umeng_alias_device.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddUmengAliasDevice extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('umeng_alias', function (Blueprint $table) {
if (!Schema::hasColumn('umeng_alias', 'device')) {
$table->text('ua')->nullable()->after('platform')->comment('userAgent');
$table->string('device', 100)->nullable()->default('')->after('platform')->comment('设备类型');
}
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('umeng_alias', function (Blueprint $table) {
$table->dropColumn("ua");
$table->dropColumn("device");
});
}
}
8 changes: 5 additions & 3 deletions resources/assets/js/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ export default {
//
if (this.userId > 0 && this.$isEEUiApp) {
$A.eeuiAppSendMessage({
action: 'intiUmeng',
action: 'initApp',
apiUrl: $A.apiUrl(''),
userid: this.userId,
token: this.userToken,
userAgent: window.navigator.userAgent,
});
setTimeout(_ => {
$A.eeuiAppSendMessage({
action: 'setUmengAlias',
userid: this.userId,
token: this.userToken,
url: $A.apiUrl('users/umeng/alias')
});
}, 6000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

<script>
import {mapState} from "vuex";
export default {
name: 'DialogDroupWordChain',
Expand All @@ -85,46 +86,46 @@ export default {
computed: {
...mapState(['dialogDroupWordChain', 'userInfo', 'dialogMsgs', 'cacheDialogs']),
isFullscreen({ windowWidth }) {
isFullscreen({windowWidth}) {
return windowWidth < 576;
},
num(){
return this.list.filter(h=>h.type != 'case')?.length || 0;
num() {
return this.list.filter(h => h.type != 'case')?.length || 0;
},
allList(){
allList() {
const msg = this.dialogDroupWordChain.msgData?.msg || {};
let list = JSON.parse(JSON.stringify(msg.list || []));
this.dialogMsgs.filter(h=>{
this.dialogMsgs.filter(h => {
return h.type == "word-chain" && h.msg?.uuid == msg.uuid
}).forEach((h)=>{
(h.msg.list || []).forEach(k=>{
if (k.type != 'case' && list.map(j=>j.id).indexOf(k.id) == -1) {
}).forEach((h) => {
(h.msg.list || []).forEach(k => {
if (k.type != 'case' && list.map(j => j.id).indexOf(k.id) == -1) {
list.push(k)
}
})
});
return list.filter(h=>(h.text || '').trim());
return list.filter(h => (h.text || '').trim());
},
isEdit(){
isEdit() {
return this.oldData != JSON.stringify(this.list);
},
dialog(){
return this.cacheDialogs.find(h=>h.id == this.dialogDroupWordChain.dialog_id) || {}
dialog() {
return this.cacheDialogs.find(h => h.id == this.dialogDroupWordChain.dialog_id) || {}
},
},
watch: {
show(val){
if(!val){
show(val) {
if (!val) {
this.value = "#" + this.$L('接龙') + " \n";
this.list = [];
}else{
if(this.dialogDroupWordChain.type == 'create'){
this.$nextTick(()=>{
} else {
if (this.dialogDroupWordChain.type == 'create') {
this.$nextTick(() => {
this.$refs.wordChainTextareaRef.focus()
})
}
Expand All @@ -133,7 +134,7 @@ export default {
},
dialogDroupWordChain(data) {
if(data.type == 'create' && data.dialog_id){
if (data.type == 'create' && data.dialog_id) {
this.show = true;
this.createId = this.userId;
this.list = [];
Expand All @@ -150,18 +151,18 @@ export default {
text: this.userInfo.nickname
});
}
if(data.type == 'participate' && data.dialog_id && data.msgData){
if (data.type == 'participate' && data.dialog_id && data.msgData) {
this.show = true;
this.createId = data.msgData.msg.createid || data.msgData.msg.userid;
this.value = data.msgData.msg.text;
this.list = this.allList;
this.list = this.allList;
this.oldData = JSON.stringify(this.list);
}
}
},
methods: {
onAdd(){
onAdd() {
this.list.push({
id: Date.now(),
type: 'text',
Expand All @@ -171,8 +172,8 @@ export default {
this.scrollTo();
},
scrollTo(){
this.$nextTick(()=>{
scrollTo() {
this.$nextTick(() => {
this.$refs.wordChainListRef.scrollTo(0, 99999);
});
},
Expand All @@ -186,14 +187,14 @@ export default {
return;
}
//
const texts = this.list.map(h=> h.text);
if( texts.length != [...new Set(texts)].length ){
const texts = this.list.map(h => h.text);
if (texts.length != [...new Set(texts)].length) {
$A.modalConfirm({
content: '重复内容将不再计入接龙结果',
cancelText: '返回编辑',
okText: '继续发送',
onOk: () => {
this.send()
this.send()
}
})
return;
Expand All @@ -206,8 +207,8 @@ export default {
*/
send() {
const list = [];
this.list.forEach(h=>{
if ((h.text || h.type != "case") && list.map(h=> h.text).indexOf(h.text) == -1) {
this.list.forEach(h => {
if ((h.text || h.type != "case") && list.map(h => h.text).indexOf(h.text) == -1) {
list.push(h);
}
});
Expand Down

0 comments on commit 6e68f39

Please sign in to comment.