|
22 | 22 | use ModStart\Core\Util\EventUtil; |
23 | 23 | use ModStart\Core\Util\RandomUtil; |
24 | 24 | use ModStart\Core\Util\TimeUtil; |
| 25 | +use ModStart\Detail\Detail; |
25 | 26 | use ModStart\Field\AbstractField; |
26 | 27 | use ModStart\Field\AutoRenderedFieldValue; |
27 | 28 | use ModStart\Field\Select; |
|
32 | 33 | use ModStart\Module\ModuleManager; |
33 | 34 | use ModStart\Repository\Filter\RepositoryFilter; |
34 | 35 | use ModStart\Support\Concern\HasFields; |
| 36 | +use ModStart\Widget\Box; |
35 | 37 | use ModStart\Widget\TextDialogRequest; |
36 | 38 | use Module\Member\Config\MemberAdminList; |
37 | 39 | use Module\Member\Config\MemberOauth; |
@@ -82,23 +84,47 @@ protected function crud(AdminCRUDBuilder $builder) |
82 | 84 | }); |
83 | 85 | $builder->text('email', '邮箱'); |
84 | 86 | $builder->text('phone', '手机'); |
85 | | - $builder->text('nickname', '昵称'); |
| 87 | + $builder->text('nickname', '昵称')->required()->ruleUnique('member_user') |
| 88 | + ->hookRendering(function (AbstractField $field, $item, $index) { |
| 89 | + switch ($field->renderMode()) { |
| 90 | + case FieldRenderMode::GRID: |
| 91 | + case FieldRenderMode::DETAIL: |
| 92 | + return AutoRenderedFieldValue::make( |
| 93 | + TextDialogRequest::make( |
| 94 | + 'primary', |
| 95 | + htmlspecialchars($item->username), |
| 96 | + modstart_admin_url('member/show', ['_id' => $item->id]) |
| 97 | + )->width('90%')->height('90%')->render() |
| 98 | + ); |
| 99 | + break; |
| 100 | + } |
| 101 | + }); |
86 | 102 | if (MemberOauth::hasEnableItems()) { |
87 | 103 | $builder->display('_oauth', '授权')->hookRendering(function (AbstractField $field, $item, $index) { |
88 | 104 | $oauthList = []; |
89 | 105 | $oauthRecords = MemberUtil::listOauths($item->id); |
90 | 106 | foreach ($oauthRecords as $oauthRecord) { |
91 | 107 | $color = null; |
| 108 | + $icon = 'iconfont icon-dot'; |
92 | 109 | $title = $oauthRecord['type']; |
93 | 110 | $oauth = MemberOauth::getByOauthKey($oauthRecord['type']); |
94 | 111 | if ($oauth) { |
95 | 112 | $color = $oauth->color(); |
96 | 113 | $title = $oauth->title(); |
| 114 | + if (method_exists($oauth, 'icon')) { |
| 115 | + $icon = $oauth->icon(); |
| 116 | + } |
97 | 117 | } |
98 | 118 | if (empty($color)) { |
99 | 119 | $color = ColorUtil::pick($oauthRecord['type']); |
100 | 120 | } |
101 | | - $oauthList[] = '<a style="color:' . $color . ';" href="javascript:;" data-tip-popover="' . $title . '"><i class="iconfont icon-dot"></i></a>'; |
| 121 | + $oauthList[] = join('', [ |
| 122 | + "<a style='color:{$color};'", |
| 123 | + "href='javascript:;'", |
| 124 | + "data-tip-popover='{$title}'", |
| 125 | + "data-dialog-request='" . modstart_admin_url('member/oauth', ['_id' => $item->id]) . "'", |
| 126 | + "><i class='{$icon}'></i></a>", |
| 127 | + ]); |
102 | 128 | } |
103 | 129 | return join('', $oauthList); |
104 | 130 | }); |
@@ -161,6 +187,33 @@ public function selectRemote() |
161 | 187 | return Select::optionRemoteHandleModel('member_user', 'id', 'username'); |
162 | 188 | } |
163 | 189 |
|
| 190 | + public function oauth(AdminDialogPage $page) |
| 191 | + { |
| 192 | + $memberUser = MemberUtil::get(CRUDUtil::id()); |
| 193 | + BizException::throwsIfEmpty('用户不存在', $memberUser); |
| 194 | + $detail = Detail::make(''); |
| 195 | + $oauthRecords = MemberUtil::listOauths($memberUser['id']); |
| 196 | + foreach ($oauthRecords as $oauthRecord) { |
| 197 | + $color = null; |
| 198 | + $icon = 'iconfont icon-dot'; |
| 199 | + $title = $oauthRecord['type']; |
| 200 | + $oauth = MemberOauth::getByOauthKey($oauthRecord['type']); |
| 201 | + if ($oauth) { |
| 202 | + $color = $oauth->color(); |
| 203 | + $title = $oauth->title(); |
| 204 | + if (method_exists($oauth, 'icon')) { |
| 205 | + $icon = $oauth->icon(); |
| 206 | + } |
| 207 | + } |
| 208 | + if (empty($color)) { |
| 209 | + $color = ColorUtil::pick($oauthRecord['type']); |
| 210 | + } |
| 211 | + $detail->html('_', $title)->html($oauthRecord['openId']); |
| 212 | + } |
| 213 | + return $page->pageTitle('授权登录信息') |
| 214 | + ->body(Box::make($detail, '授权登录信息')); |
| 215 | + } |
| 216 | + |
164 | 217 | public function add(AdminDialogPage $page) |
165 | 218 | { |
166 | 219 | $form = Form::make(''); |
|
0 commit comments