Skip to content

Commit

Permalink
可设置发送聊天前必须设置昵称
Browse files Browse the repository at this point in the history
  • Loading branch information
aipaw committed Dec 20, 2021
1 parent 75ac1e9 commit a202227
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 7 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/Api/DialogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public function msg__sendtext()
{
$user = User::auth();
//
$chat_nickname = Base::settingFind('system', 'chat_nickname');
if ($chat_nickname == 'required') {
$nickname = User::select(['nickname as nickname_original'])->whereUserid($user->userid)->value('nickname_original');
if (empty($nickname)) {
return Base::retError('请设置昵称', [], -2);
}
}
//
$dialog_id = intval(Request::input('dialog_id'));
$text = trim(Request::input('text'));
//
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/Api/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SystemController extends AbstractController
*
* @apiParam {String} type
* - get: 获取(默认)
* - save: 保存设置(参数:reg、login_code、password_policy)
* - save: 保存设置(参数:reg、login_code、password_policy、chat_nickname
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
* @apiSuccess {String} msg 返回信息(错误描述)
Expand All @@ -40,7 +40,7 @@ public function setting()
User::auth('admin');
$all = Request::input();
foreach ($all AS $key => $value) {
if (!in_array($key, ['reg', 'login_code', 'password_policy'])) {
if (!in_array($key, ['reg', 'login_code', 'password_policy', 'chat_nickname'])) {
unset($all[$key]);
}
}
Expand All @@ -52,6 +52,7 @@ public function setting()
$setting['reg'] = $setting['reg'] ?: 'open';
$setting['login_code'] = $setting['login_code'] ?: 'auto';
$setting['password_policy'] = $setting['password_policy'] ?: 'simple';
$setting['chat_nickname'] = $setting['chat_nickname'] ?: 'optional';
//
return Base::retSuccess('success', $setting ?: json_decode('{}'));
}
Expand Down
9 changes: 8 additions & 1 deletion resources/assets/js/functions/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
})
])
},
loading: true,
onOk: () => {
if (typeof config.onOk === "function") {
if (config.onOk(config.value, () => {
Expand All @@ -66,6 +65,14 @@
$A.Modal.remove();
}
},
onCancel: () => {
if (typeof config.onCancel === "function") {
config.onCancel();
}
},
loading: true,
okText: $A.L(config.okText || '确定'),
cancelText: $A.L(config.cancelText || '取消'),
});
setTimeout(() => {
document.getElementById(inputId) && document.getElementById(inputId).focus();
Expand Down
8 changes: 8 additions & 0 deletions resources/assets/js/pages/manage/setting/system.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Radio label="open">{{$L('开启')}}</Radio>
<Radio label="close">{{$L('关闭')}}</Radio>
</RadioGroup>
<div v-if="formDatum.login_code == 'auto'" class="form-tip">{{$L('自动:密码输入错误后必须添加验证码。')}}</div>
</FormItem>
<FormItem :label="$L('密码策略')" prop="passwordPolicy">
<RadioGroup v-model="formDatum.password_policy">
Expand All @@ -22,6 +23,13 @@
<div v-if="formDatum.password_policy == 'simple'" class="form-tip">{{$L('简单:大于或等于6个字符。')}}</div>
<div v-else-if="formDatum.password_policy == 'complex'" class="form-tip">{{$L('复杂:大于或等于6个字符,包含数字、字母大小写或者特殊字符。')}}</div>
</FormItem>
<FormItem :label="$L('聊天昵称')" prop="chatNickname">
<RadioGroup v-model="formDatum.chat_nickname">
<Radio label="optional">{{$L('可选')}}</Radio>
<Radio label="required">{{$L('必填')}}</Radio>
</RadioGroup>
<div v-if="formDatum.chat_nickname == 'required'" class="form-tip">{{$L('必填:发送聊天内容前必须设置昵称。')}}</div>
</FormItem>
</Form>
<div class="setting-footer">
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{$L('提交')}}</Button>
Expand Down
66 changes: 62 additions & 4 deletions resources/assets/js/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@ export default {
params.header['token'] = state.userToken;
params.header['fd'] = state.method.getStorageString("userWsFd");
//
const cloneParams = state.method.cloneJSON(params);
return new Promise(function (resolve, reject) {
if (params.spinner === true) {
const spinner = document.getElementById("common-spinner");
if (spinner) {
const beforeCall = params.before;
params.before = () => {
state.ajaxLoadNum++;
spinner.style.display = "block"
typeof beforeCall == "function" && beforeCall();
};
//
const completeCall = params.complete;
params.complete = () => {
state.ajaxLoadNum--;
if (state.ajaxLoadNum <= 0) {
spinner.style.display = "none"
}
typeof completeCall == "function" && completeCall();
};
}
}
Expand All @@ -57,6 +54,17 @@ export default {
});
return;
}
if (ret === -2 && params.checkNick !== false) {
// 需要昵称
dispatch("userNickNameInput").then(() => {
dispatch("call", Object.assign(cloneParams, {
checkNick: false
})).then(resolve).catch(reject);
}).catch(() => {
reject({data, msg: $A.L('请设置昵称!')})
});
return;
}
if (ret === 1) {
resolve({data, msg});
} else {
Expand Down Expand Up @@ -307,6 +315,56 @@ export default {
})
},

/**
* 设置用户昵称
* @param dispatch
* @returns {Promise<unknown>}
*/
userNickNameInput({dispatch}) {
return new Promise(function (resolve, reject) {
let callback = (cb, success) => {
if (typeof cb === "function") {
cb();
}
if (success === true) {
setTimeout(resolve, 301)
} else {
setTimeout(reject, 301)
}
}
$A.modalInput({
title: "设置昵称",
placeholder: "请输入昵称",
okText: "保存",
onOk: (value, cb) => {
if (value) {
dispatch("call", {
url: 'users/editdata',
data: {
nickname: value,
},
checkNick: false,
}).then(() => {
dispatch('getUserInfo').then(() => {
callback(cb, true);
}).catch(() => {
callback(cb, false);
});
}).catch(({msg}) => {
$A.modalError(msg, 301);
callback(cb, false);
});
} else {
callback(cb, false);
}
},
onCancel: () => {
callback(null, false);
}
});
});
},

/**
* 登出(打开登录页面)
* @param state
Expand Down

0 comments on commit a202227

Please sign in to comment.