diff --git a/application/api/controller/Favorite.php b/application/api/controller/Favorite.php index 704791c..7ccbd63 100644 --- a/application/api/controller/Favorite.php +++ b/application/api/controller/Favorite.php @@ -87,6 +87,61 @@ class Favorite extends V1 $this->ok(['faved' => $faved, 'count' => $count]); } + /** + * GET /api/v1/follow/list {page,size} + * → 分页 {list,page,size,total,hasMore} + * 返回当前登录用户关注的用户/商家列表 + * + * @return void + */ + public function followList() + { + $user = $this->auth(); + + list($rows, $total, $page, $size) = $this->pageQuery(function ($forCount) use ($user) { + $q = Db::name('fc_follow')->where('user_id', $user['id']); + if ($forCount) { + return $q; + } + return $q->order('id desc'); + }); + + $list = []; + foreach ($rows as $row) { + $targetId = (int)$row['target_user_id']; + $targetUser = Db::name('user')->where('id', $targetId)->find(); + if (!$targetUser) { + continue; + } + $ext = Db::name('fc_user_ext')->where('user_id', $targetId)->find(); + $merchant = Db::name('fc_merchant')->where('user_id', $targetId)->find(); + $isMerchant = $merchant && (int)$merchant['audit_status'] === 1; + + // 统计该用户发布的有效信息条数 + $postCount = (int)Db::name('fc_post') + ->where('user_id', $targetId) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime') + ->count(); + + $list[] = [ + 'id' => (int)$row['id'], + 'userId' => $targetId, + 'nickname' => (string)($merchant && $merchant['name'] ? $merchant['name'] : $targetUser['nickname']), + 'avatar' => (string)($merchant && $merchant['logo'] ? $merchant['logo'] : $targetUser['avatar']), + 'isMerchant' => $isMerchant, + 'merchantId' => $merchant ? (int)$merchant['id'] : 0, + 'category' => (string)($merchant && $merchant['category'] ? $merchant['category'] : ''), + 'postCount' => $postCount, + 'followed' => true, + 'followTime' => $this->iso($row['createtime']), + ]; + } + + $this->ok($this->paginate($list, $total, $page, $size)); + } + /** * POST /api/v1/follow/toggle {userId} * → {followed} diff --git a/application/api/controller/User.php b/application/api/controller/User.php index df6c025..2619cb5 100755 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -2,355 +2,172 @@ namespace app\api\controller; -use app\common\controller\Api; -use app\common\library\Ems; -use app\common\library\Sms; -use fast\Random; -use think\Config; -use think\Validate; +use think\Db; /** - * 会员接口 + * 用户端 · 个人主页与用户详情(Module-USER) + * 路由: + * GET /api/v1/user/:id U1 个人主页公开信息 + * GET /api/v1/user/:id/posts U2 个人发布的信息流(分页) */ -class User extends Api +class User extends V1 { - protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third']; - protected $noNeedRight = '*'; - - public function _initialize() - { - parent::_initialize(); - - if (!Config::get('fastadmin.usercenter')) { - $this->error(__('User center already closed')); - } - - } - /** - * 会员中心 - */ - public function index() - { - $this->success('', ['welcome' => $this->auth->nickname]); - } - - /** - * 会员登录 + * U1 获取用户公开档案与发帖概况 + * GET /api/v1/user/:id + * 规则:允许游客查询;若用户是认证商家,带出对应关联的商家门店ID * - * @ApiMethod (POST) - * @ApiParams (name="account", type="string", required=true, description="账号") - * @ApiParams (name="password", type="string", required=true, description="密码") + * @return void */ - public function login() + public function detail() { - $account = $this->request->post('account'); - $password = $this->request->post('password'); - if (!$account || !$password) { - $this->error(__('Invalid parameters')); + $id = (int)$this->routeId(); + if ($id <= 0) { + $id = (int)$this->input('id', 0) ?: (int)$this->input('userId', 0); } - $ret = $this->auth->login($account, $password); - if ($ret) { - $data = ['userinfo' => $this->auth->getUserinfo()]; - $this->success(__('Logged in successful'), $data); - } else { - $this->error($this->auth->getError()); + if ($id <= 0) { + $this->fail('缺少用户参数', 400); } + + $user = Db::name('user')->where('id', $id)->find(); + if (!$user) { + $this->fail('用户不存在', 404); + } + + $ext = Db::name('fc_user_ext')->where('user_id', $id)->find(); + $merchant = Db::name('fc_merchant')->where('user_id', $id)->find(); + $isMerchant = $merchant && (int)$merchant['audit_status'] === 1; + + // 统计真实有效发布数量 + $postCount = (int)Db::name('fc_post') + ->where('user_id', $id) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime') + ->count(); + + // 判定当前查看者是否已关注该用户 + $followed = false; + $me = $this->user(); + if ($me && (int)$me['id'] !== $id) { + $followed = (bool)Db::name('fc_follow') + ->where('user_id', $me['id']) + ->where('target_user_id', $id) + ->find(); + } + + // 首屏拉取前 6 条该用户的有效发帖 + $posts = $this->fetchUserPosts($id, 1, 6); + + $data = [ + 'id' => (int)$user['id'], + 'nickname' => (string)$user['nickname'], + 'avatar' => (string)$user['avatar'], + 'isMerchant' => $isMerchant, + 'merchantId' => $merchant ? (int)$merchant['id'] : 0, + 'merchantName' => $merchant ? (string)$merchant['name'] : '', + 'postCount' => $postCount, + 'followed' => $followed, + 'isSelf' => $me ? ((int)$me['id'] === $id) : false, + 'createdAt' => $this->iso($user['createtime']), + 'posts' => $posts['list'], + 'hasMorePosts' => $posts['hasMore'], + ]; + + $this->ok($data); } /** - * 手机验证码登录 + * U2 分页获取该用户发布的信息流 + * GET /api/v1/user/:id/posts * - * @ApiMethod (POST) - * @ApiParams (name="mobile", type="string", required=true, description="手机号") - * @ApiParams (name="captcha", type="string", required=true, description="验证码") + * @return void */ - public function mobilelogin() + public function posts() { - $mobile = $this->request->post('mobile'); - $captcha = $this->request->post('captcha'); - if (!$mobile || !$captcha) { - $this->error(__('Invalid parameters')); + $id = (int)$this->routeId(); + if ($id <= 0) { + $id = (int)$this->input('id', 0) ?: (int)$this->input('userId', 0); } - if (!Validate::regex($mobile, "^1\d{10}$")) { - $this->error(__('Mobile is incorrect')); - } - if (!Sms::check($mobile, $captcha, 'mobilelogin', true)) { - $this->error(__('Captcha is incorrect')); - } - $user = \app\common\model\User::getByMobile($mobile); - if ($user) { - if ($user->status != 'normal') { - $this->error(__('Account is locked')); - } - //如果已经有账号则直接登录 - $ret = $this->auth->direct($user->id); - } else { - $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []); - } - if ($ret) { - Sms::flush($mobile, 'mobilelogin'); - $data = ['userinfo' => $this->auth->getUserinfo()]; - $this->success(__('Logged in successful'), $data); - } else { - $this->error($this->auth->getError()); + if ($id <= 0) { + $this->fail('缺少用户参数', 400); } + + list($page, $size) = $this->pager(10); + $res = $this->fetchUserPosts($id, $page, $size); + $this->ok($res); } /** - * 注册会员 + * 查询指定用户的发帖列表统一组装 * - * @ApiMethod (POST) - * @ApiParams (name="username", type="string", required=true, description="用户名") - * @ApiParams (name="password", type="string", required=true, description="密码") - * @ApiParams (name="email", type="string", required=true, description="邮箱") - * @ApiParams (name="mobile", type="string", required=true, description="手机号") - * @ApiParams (name="code", type="string", required=true, description="验证码") + * @param int $userId 发布者用户ID + * @param int $page 页码 + * @param int $size 每页数量 + * @return array */ - public function register() + protected function fetchUserPosts($userId, $page, $size) { - $username = $this->request->post('username'); - $password = $this->request->post('password'); - $email = $this->request->post('email'); - $mobile = $this->request->post('mobile'); - $code = $this->request->post('code'); - if (!$username || !$password) { - $this->error(__('Invalid parameters')); - } - if ($email && !Validate::is($email, "email")) { - $this->error(__('Email is incorrect')); - } - if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) { - $this->error(__('Mobile is incorrect')); - } - $ret = Sms::check($mobile, $code, 'register', true); - if (!$ret) { - $this->error(__('Captcha is incorrect')); - } - $ret = $this->auth->register($username, $password, $email, $mobile, []); - if ($ret) { - Sms::flush($mobile, 'register'); - $data = ['userinfo' => $this->auth->getUserinfo()]; - $this->success(__('Sign up successful'), $data); - } else { - $this->error($this->auth->getError()); - } - } + $q = Db::name('fc_post') + ->where('user_id', $userId) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime'); - /** - * 退出登录 - * @ApiMethod (POST) - */ - public function logout() - { - if (!$this->request->isPost()) { - $this->error(__('Invalid parameters')); - } - $this->auth->logout(); - $this->success(__('Logout successful')); - } + $total = (int)$q->count(); + $rows = Db::name('fc_post') + ->where('user_id', $userId) + ->where('status', 1) + ->where('audit_status', 1) + ->whereNull('deletetime') + ->order('is_top desc, id desc') + ->page($page, $size) + ->select(); - /** - * 修改会员个人信息 - * - * @ApiMethod (POST) - * @ApiParams (name="avatar", type="string", required=true, description="头像地址") - * @ApiParams (name="username", type="string", required=true, description="用户名") - * @ApiParams (name="nickname", type="string", required=true, description="昵称") - * @ApiParams (name="bio", type="string", required=true, description="个人简介") - */ - public function profile() - { - $user = $this->auth->getUser(); - $username = $this->request->post('username'); - $nickname = $this->request->post('nickname'); - $bio = $this->request->post('bio'); - $avatar = $this->request->post('avatar', '', 'trim,strip_tags,htmlspecialchars'); - if ($username) { - $exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find(); - if ($exists) { - $this->error(__('Username already exists')); + $list = []; + foreach ($rows as $r) { + $catName = ''; + if (!empty($r['category_id'])) { + $cat = Db::name('fc_category')->where('id', $r['category_id'])->find(); + $catName = $cat ? (string)$cat['name'] : ''; } - $user->username = $username; - } - if ($nickname) { - $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find(); - if ($exists) { - $this->error(__('Nickname already exists')); + $cover = trim((string)$r['cover']); + $media = json_decode((string)$r['media'], true); + $mediaList = is_array($media) ? array_values(array_filter($media)) : []; + if ($cover === '' && !empty($mediaList)) { + $cover = $mediaList[0]; } - $user->nickname = $nickname; - } - if ($avatar) { - //判断是否匹配config('upload.cdnurl')开头以及当前$SERVER['HTTP_HOST']开头。 - if (preg_match('/^' . preg_quote(config('upload.cdnurl') . '/', '/') . '/i', $avatar) - || preg_match('/^' . preg_quote(substr(config('upload.savekey'), 0, strpos(config('upload.savekey'), '{')), '/') . '/i', $avatar) - || preg_match('/^' . preg_quote($_SERVER['HTTP_HOST'] . '/', '/') . '/i', $avatar)) { - $user->avatar = $avatar; + $tags = []; + if (!empty($r['tags'])) { + $tags = array_values(array_filter(array_map('trim', explode(',', (string)$r['tags'])))); } - } - $user->bio = $bio; - $user->save(); - $this->success(); - } - /** - * 修改邮箱 - * - * @ApiMethod (POST) - * @ApiParams (name="email", type="string", required=true, description="邮箱") - * @ApiParams (name="captcha", type="string", required=true, description="验证码") - */ - public function changeemail() - { - $user = $this->auth->getUser(); - $email = $this->request->post('email'); - $captcha = $this->request->post('captcha'); - if (!$email || !$captcha) { - $this->error(__('Invalid parameters')); + $list[] = [ + 'id' => (int)$r['id'], + 'title' => (string)$r['title'], + 'content' => (string)$r['content'], + 'price' => (float)$r['price'], + 'priceUnit' => (string)$r['price_unit'], + 'cover' => $cover, + 'media' => $mediaList, + 'area' => (string)$r['area'], + 'address' => (string)$r['address'], + 'categoryId' => (int)$r['category_id'], + 'categoryName' => $catName, + 'isTop' => (int)$r['is_top'] === 1, + 'views' => (int)$r['views'], + 'commentCount' => (int)$r['comment_count'], + 'createdAt' => $this->iso($r['createtime']), + 'tags' => $tags, + ]; } - if (!Validate::is($email, "email")) { - $this->error(__('Email is incorrect')); - } - if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) { - $this->error(__('Email already exists')); - } - $result = Ems::check($email, $captcha, 'changeemail', true); - if (!$result) { - $this->error(__('Captcha is incorrect')); - } - $verification = $user->verification; - $verification->email = 1; - $user->verification = $verification; - $user->email = $email; - $user->save(); - Ems::flush($email, 'changeemail'); - $this->success(); - } - - /** - * 修改手机号 - * - * @ApiMethod (POST) - * @ApiParams (name="mobile", type="string", required=true, description="手机号") - * @ApiParams (name="captcha", type="string", required=true, description="验证码") - */ - public function changemobile() - { - $user = $this->auth->getUser(); - $mobile = $this->request->post('mobile'); - $captcha = $this->request->post('captcha'); - if (!$mobile || !$captcha) { - $this->error(__('Invalid parameters')); - } - if (!Validate::regex($mobile, "^1\d{10}$")) { - $this->error(__('Mobile is incorrect')); - } - if (\app\common\model\User::where('mobile', $mobile)->where('id', '<>', $user->id)->find()) { - $this->error(__('Mobile already exists')); - } - $result = Sms::check($mobile, $captcha, 'changemobile', true); - if (!$result) { - $this->error(__('Captcha is incorrect')); - } - $verification = $user->verification; - $verification->mobile = 1; - $user->verification = $verification; - $user->mobile = $mobile; - $user->save(); - - Sms::flush($mobile, 'changemobile'); - $this->success(); - } - - /** - * 第三方登录 - * - * @ApiMethod (POST) - * @ApiParams (name="platform", type="string", required=true, description="平台名称") - * @ApiParams (name="code", type="string", required=true, description="Code码") - */ - public function third() - { - $url = url('user/index'); - $platform = $this->request->post("platform"); - $code = $this->request->post("code"); - $config = get_addon_config('third'); - if (!$config || !isset($config[$platform])) { - $this->error(__('Invalid parameters')); - } - $app = new \addons\third\library\Application($config); - //通过code换access_token和绑定会员 - $result = $app->{$platform}->getUserInfo(['code' => $code]); - if ($result) { - $loginret = \addons\third\library\Service::connect($platform, $result); - if ($loginret) { - $data = [ - 'userinfo' => $this->auth->getUserinfo(), - 'thirdinfo' => $result - ]; - $this->success(__('Logged in successful'), $data); - } - } - $this->error(__('Operation failed'), $url); - } - - /** - * 重置密码 - * - * @ApiMethod (POST) - * @ApiParams (name="mobile", type="string", required=true, description="手机号") - * @ApiParams (name="newpassword", type="string", required=true, description="新密码") - * @ApiParams (name="captcha", type="string", required=true, description="验证码") - */ - public function resetpwd() - { - $type = $this->request->post("type", "mobile"); - $mobile = $this->request->post("mobile"); - $email = $this->request->post("email"); - $newpassword = $this->request->post("newpassword"); - $captcha = $this->request->post("captcha"); - if (!$newpassword || !$captcha) { - $this->error(__('Invalid parameters')); - } - //验证Token - if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) { - $this->error(__('Password must be 6 to 30 characters')); - } - if ($type == 'mobile') { - if (!Validate::regex($mobile, "^1\d{10}$")) { - $this->error(__('Mobile is incorrect')); - } - $user = \app\common\model\User::getByMobile($mobile); - if (!$user) { - $this->error(__('User not found')); - } - $ret = Sms::check($mobile, $captcha, 'resetpwd', true); - if (!$ret) { - $this->error(__('Captcha is incorrect')); - } - Sms::flush($mobile, 'resetpwd'); - } else { - if (!Validate::is($email, "email")) { - $this->error(__('Email is incorrect')); - } - $user = \app\common\model\User::getByEmail($email); - if (!$user) { - $this->error(__('User not found')); - } - $ret = Ems::check($email, $captcha, 'resetpwd', true); - if (!$ret) { - $this->error(__('Captcha is incorrect')); - } - Ems::flush($email, 'resetpwd'); - } - //模拟一次登录 - $this->auth->direct($user->id); - $ret = $this->auth->changepwd($newpassword, '', true); - if ($ret) { - $this->success(__('Reset password successful')); - } else { - $this->error($this->auth->getError()); - } + return [ + 'list' => $list, + 'total' => $total, + 'page' => $page, + 'size' => $size, + 'hasMore' => ($page * $size) < $total, + ]; } } diff --git a/application/api/controller/V1.php b/application/api/controller/V1.php index 2f5ea6b..6ee9af4 100644 --- a/application/api/controller/V1.php +++ b/application/api/controller/V1.php @@ -359,6 +359,40 @@ class V1 extends Api return [$rows, $total, $page, $size]; } + /** + * 读取路由 :id 参数(兼容 POST 体/查询串传入) + * + * @return int + */ + protected function routeId() + { + $id = (int)$this->input('id', 0); + if ($id <= 0) { + $id = (int)$this->request->param('id', 0); + } + return $id; + } + + /** + * 提取请求中的经纬度入参(可选 float,gcj02) + * 未传 / 非数字 / 越界 / 为 0 时返回 null + * @param string $key lat|lng + * @param float $limit 绝对值上限(纬度 90 / 经度 180) + * @return float|null + */ + protected function coord($key, $limit) + { + $val = $this->input($key, null); + if ($val === null || $val === '' || !is_numeric($val)) { + return null; + } + $val = round((float)$val, 6); + if ($val == 0.0 || $val < -$limit || $val > $limit) { + return null; + } + return $val; + } + /* ==================== 业务配置(fa_fc_config) ==================== */ /** diff --git a/application/route.php b/application/route.php index 09be2da..35e8fa0 100755 --- a/application/route.php +++ b/application/route.php @@ -71,15 +71,20 @@ return [ /* =============== 三·B、用户端 · 互动(举报 / 收藏 / 关注) =============== * 顺序说明:本组全部是「同前缀、不同后缀」的静态路径(favorite/list、favorite/toggle、 - * favorite/status、follow/toggle),彼此不构成前缀包含关系,注册顺序互不吞并; + * favorite/status、follow/toggle、follow/list),彼此不构成前缀包含关系,注册顺序互不吞并; * 且本表未登记 favorite/:id、follow/:id、report/:id 之类通配规则,不存在被吞风险。 */ 'api/v1/report' => 'api/Report/create', 'api/v1/favorite/list' => 'api/Favorite/list', 'api/v1/favorite/toggle' => 'api/Favorite/toggle', 'api/v1/favorite/status' => 'api/Favorite/status', + 'api/v1/follow/list' => 'api/Favorite/followList', 'api/v1/follow/toggle' => 'api/Favorite/follow', + /* =============== 三·C、用户端 · 个人主页与用户详情 =============== */ + 'api/v1/user/:id/posts' => 'api/User/posts', + 'api/v1/user/:id' => 'api/User/detail', + /* =============== 四、用户端 · 会员中心(Module-MEMBER) =============== */ 'api/v1/member/plans' => 'api/Member/plans', 'api/v1/member/benefits' => 'api/Member/benefits', diff --git a/uniapp/common/api/favorite.js b/uniapp/common/api/favorite.js index 0cc0b9f..3fb507e 100644 --- a/uniapp/common/api/favorite.js +++ b/uniapp/common/api/favorite.js @@ -3,6 +3,7 @@ * 对应契约 §2.1: * GET /favorite/list 分页(list 项为 Post 结构) * POST /favorite/toggle {postId} → {faved,count} + * GET /follow/list 分页(list 项为关注的用户/商家结构) * POST /follow/toggle {userId} → {followed} * POST /favorite/status {postIds:[],userIds:[]} → {faved:{},followed:{}} */ @@ -13,6 +14,8 @@ export const favoriteApi = { list: (params = {}) => get('/favorite/list', params, { silent: true }), /** 收藏 / 取消收藏(返回最新状态与收藏总数) */ toggle: (payload = {}) => post('/favorite/toggle', payload, { silent: true }), + /** 我的关注列表(分页) */ + followList: (params = {}) => get('/follow/list', params, { silent: true }), /** 关注 / 取消关注发布者 */ follow: (payload = {}) => post('/follow/toggle', payload, { silent: true }), /** 批量回显收藏 / 关注状态 */ diff --git a/uniapp/common/api/index.js b/uniapp/common/api/index.js index abbdc1d..d153cf5 100644 --- a/uniapp/common/api/index.js +++ b/uniapp/common/api/index.js @@ -17,3 +17,4 @@ export { orderApi } from './order.js' export { payApi } from './pay.js' export { couponApi } from './coupon.js' export { merchantApi } from './merchant.js' +export { userApi } from './user.js' diff --git a/uniapp/common/api/user.js b/uniapp/common/api/user.js new file mode 100644 index 0000000..3fe4eb9 --- /dev/null +++ b/uniapp/common/api/user.js @@ -0,0 +1,26 @@ +/** + * 接口模块 · 用户个人公开主页(用户端) + * 对应路由: + * GET /api/v1/user/:id 获取用户公开主页与档案 + * GET /api/v1/user/:id/posts 获取用户发布的信息列表 + */ +import { get } from '../utils/request.js' + +export const userApi = { + /** + * 获取用户公开档案主页 + * @param {number|string} id 用户ID + * @returns {Promise} + */ + detail: (id) => get(`/user/${id}`, {}, { silent: true }), + + /** + * 获取用户发布的信息流(分页) + * @param {number|string} id 用户ID + * @param {Object} params {page, size} + * @returns {Promise<{list:Array, total:number, hasMore:boolean}>} + */ + posts: (id, params = {}) => get(`/user/${id}/posts`, params, { silent: true }), +} + +export default userApi diff --git a/uniapp/common/assets/icons.js b/uniapp/common/assets/icons.js index c235030..6f35b09 100644 --- a/uniapp/common/assets/icons.js +++ b/uniapp/common/assets/icons.js @@ -100,6 +100,7 @@ export const ICON_GROUPS = [ { key: 'mine-dist', name: '分销中心', file: 'mine-dist.png' }, { key: 'mine-vip', name: '会员中心', file: 'mine-vip.png' }, { key: 'mine-draft', name: '草稿箱', file: 'mine-draft.png' }, + { key: 'mine-follow', name: '我的关注', file: 'mine-follow.png' }, { key: 'mine-history', name: '搜索记录', file: 'mine-history.png' }, { key: 'mine-setting', name: '系统设置', file: 'mine-setting.png' }, { key: 'mine-service', name: '联系客服', file: 'mine-service.png' }, diff --git a/uniapp/common/mock/index.js b/uniapp/common/mock/index.js index 6780985..e0de799 100644 --- a/uniapp/common/mock/index.js +++ b/uniapp/common/mock/index.js @@ -530,6 +530,48 @@ export const mockRoutes = { } return ok({ faved, count: datasets.favorites.length }) }, + 'GET /follow/list': ({ data }) => { + const list = datasets.follows.map((f) => { + const isMerchant = String(f.targetUserId) === '2001'; + return { + id: f.id, + userId: Number(f.targetUserId), + nickname: isMerchant ? '顺捷物流' : '同城用户' + f.targetUserId, + avatar: '', + isMerchant, + merchantId: isMerchant ? 1 : 0, + category: isMerchant ? '物流服务' : '', + postCount: 2, + followed: true, + followTime: f.createtime, + }; + }); + return ok({ list, total: list.length, page: 1, size: 10, hasMore: false }); + }, + 'GET /user/:id': ({ url }) => { + const { id } = parseParams('/user/:id', url); + const userId = Number(id); + const isMerchant = userId === 2001; + const posts = datasets.posts.filter(p => !p.auditStatus || p.auditStatus === 1).slice(0, 6); + return ok({ + id: userId, + nickname: isMerchant ? '顺捷物流' : (userId === 1001 ? datasets.user.nickname : '同城用户' + userId), + avatar: userId === 1001 ? datasets.user.avatar : '', + isMerchant, + merchantId: isMerchant ? 1 : 0, + merchantName: isMerchant ? '顺捷物流' : '', + postCount: posts.length, + followed: datasets.follows.some(f => String(f.targetUserId) === String(userId)), + isSelf: userId === datasets.user.id, + createdAt: '2026-04-18T15:37:12+08:00', + posts, + hasMorePosts: false + }); + }, + 'GET /user/:id/posts': ({ url }) => { + const posts = datasets.posts.filter(p => !p.auditStatus || p.auditStatus === 1); + return ok({ list: posts, total: posts.length, page: 1, size: 10, hasMore: false }); + }, 'POST /follow/toggle': ({ data }) => { const userId = Number(data && data.userId) if (!userId) fail('缺少用户 ID') diff --git a/uniapp/components/fc-navbar/fc-navbar.vue b/uniapp/components/fc-navbar/fc-navbar.vue index 53f8452..fcb9919 100644 --- a/uniapp/components/fc-navbar/fc-navbar.vue +++ b/uniapp/components/fc-navbar/fc-navbar.vue @@ -44,6 +44,8 @@ export default { showBack: { type: Boolean, default: false }, /** 标题文字是否居中,默认 true(居中排列) */ center: { type: Boolean, default: true }, + /** 自定义返回兜底跳转路径(默认返回首页 /pages/index/index) */ + fallbackUrl: { type: String, default: '' }, }, data() { return { @@ -84,11 +86,19 @@ export default { } catch (e) {} }, /** - * 点击返回上一页,若无历史页面或返回失败则执行降级跳转 + * 点击返回上一页 + * 优先 navigateBack;若无上一页历史(如分享直达、热重载、单页直开)或返回失败,则立即执行安全降级,绝不卡死在原地 */ onBack() { this.$emit('back') - const pages = (typeof getCurrentPages === 'function') ? getCurrentPages() : [] + let pages = [] + try { + pages = (typeof getCurrentPages === 'function') ? getCurrentPages() : [] + } catch (e) { + pages = [] + } + + // 页面栈深度 > 1 时,执行系统级返回 if (pages && pages.length > 1) { uni.navigateBack({ delta: 1, @@ -97,34 +107,38 @@ export default { }, }) } else { + // 页面栈仅有 1 页(分享直达、编译刷新),直接执行降级跳转,避免微信底层静默丢弃导致卡死原地 this.fallbackNavigation() } }, /** - * 导航失败时的降级逻辑(优先返回上一级业务列表,最后兜底首页) + * 导航失败或无页面栈时的降级逻辑(优先降级至指定 fallbackUrl,否则平滑回到同城首页) */ fallbackNavigation() { - // #ifdef H5 - uni.redirectTo({ - url: '/pages/index/index', - fail: () => { - uni.reLaunch({ url: '/pages/index/index' }) - }, - }) - // #endif - // #ifndef H5 - uni.navigateBack({ - delta: 1, - fail: () => { - uni.redirectTo({ - url: '/pages/member/orders', - fail: () => { - uni.reLaunch({ url: '/pages/index/index' }) - }, - }) - }, - }) - // #endif + const target = this.fallbackUrl || '/pages/index/index' + const tabPages = ['/pages/index/index', '/pages/category/index', '/pages/post/create', '/pages/message/index', '/pages/mine/index'] + const isTabBar = tabPages.includes(target) + + if (isTabBar) { + uni.switchTab({ + url: target, + fail: () => { + uni.reLaunch({ url: target }) + }, + }) + } else { + uni.redirectTo({ + url: target, + fail: () => { + uni.reLaunch({ + url: target, + fail: () => { + uni.switchTab({ url: '/pages/index/index' }) + }, + }) + }, + }) + } }, }, } @@ -174,16 +188,16 @@ export default { width: 100%; } .fc-navbar__back { - width: 80rpx; + width: 96rpx; height: 100%; - min-height: 76rpx; + min-height: 80rpx; display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; position: relative; - z-index: 10; + z-index: 25; transition: opacity 0.15s ease, transform 0.15s ease; &:active { transform: scale(0.92); diff --git a/uniapp/pages.json b/uniapp/pages.json index 470bc11..4ec3355 100644 --- a/uniapp/pages.json +++ b/uniapp/pages.json @@ -177,7 +177,8 @@ "style": { "navigationBarTitleText": "店铺详情", "navigationStyle": "custom", - "backgroundColor": "#f2fef7" + "backgroundColor": "#f2fef7", + "enablePullDownRefresh": true } }, { @@ -195,6 +196,32 @@ "navigationStyle": "custom", "backgroundColor": "#f2fef7" } + }, + { + "path": "pages/order/success", + "style": { + "navigationBarTitleText": "支付结果", + "navigationStyle": "custom", + "backgroundColor": "#f2fef7" + } + }, + { + "path": "pages/favorite/follows", + "style": { + "navigationBarTitleText": "我的关注", + "navigationStyle": "custom", + "backgroundColor": "#f2fef7", + "enablePullDownRefresh": true + } + }, + { + "path": "pages/user/detail", + "style": { + "navigationBarTitleText": "个人主页", + "navigationStyle": "custom", + "backgroundColor": "#f2fef7", + "enablePullDownRefresh": true + } } ], "globalStyle": { diff --git a/uniapp/pages/detail/detail.vue b/uniapp/pages/detail/detail.vue index 9076bfa..d091681 100644 --- a/uniapp/pages/detail/detail.vue +++ b/uniapp/pages/detail/detail.vue @@ -118,8 +118,8 @@ - - + + 已认证 - {{ post.publisher && post.publisher.isMerchant ? '商家用户' : '个人用户' }} · {{ timeText }}发布 + 个人用户 · {{ timeText }}发布 - + @@ -1004,6 +1004,16 @@ export default { /** * 导航或复制地址 */ + /** + * 跳转至个人用户公开主页 + */ + goUserDetail() { + const uid = (this.post.publisher && this.post.publisher.id) || this.post.userId || this.post.user_id + if (!uid) return + uni.navigateTo({ + url: '/pages/user/detail?id=' + uid, + }) + }, /** * 跳转至商家店铺详情主页 */ diff --git a/uniapp/pages/favorite/follows.vue b/uniapp/pages/favorite/follows.vue new file mode 100644 index 0000000..7d1d379 --- /dev/null +++ b/uniapp/pages/favorite/follows.vue @@ -0,0 +1,357 @@ + + + + + diff --git a/uniapp/pages/member/index.vue b/uniapp/pages/member/index.vue index 7c6a63b..e2c1e80 100644 --- a/uniapp/pages/member/index.vue +++ b/uniapp/pages/member/index.vue @@ -1,2641 +1,1369 @@ - - - - - - - - - - + + + + + diff --git a/uniapp/pages/merchant/detail.vue b/uniapp/pages/merchant/detail.vue index fc46377..40a5621 100644 --- a/uniapp/pages/merchant/detail.vue +++ b/uniapp/pages/merchant/detail.vue @@ -1,13 +1,7 @@