dsh-share-chat 0.40.0 → 0.40.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client.js +60 -1
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -6125,6 +6125,19 @@ const seatAvatarEl = (s, size) => {
6125
6125
  stt.style.cssText = 'font-size:11px;color:' + (st.ready || st.bot ? '#2f8f65' : '#a184b3')
6126
6126
  info.appendChild(stt)
6127
6127
  card.appendChild(info)
6128
+ // 空位可以直接点,坐下
6129
+ if (st.empty && !(meSeat && meSeat.id)) {
6130
+ card.style.cursor = 'pointer'
6131
+ card.title = '点这里坐下'
6132
+ card.addEventListener('click', async () => {
6133
+ try {
6134
+ await api2('POST', '/api/mj/rooms/' + roomId + '/join')
6135
+ await render()
6136
+ } catch (e) {
6137
+ onToast('坐下失败:' + friendly(e))
6138
+ }
6139
+ })
6140
+ }
6128
6141
  if (st.bot && iAmOwner) {
6129
6142
  card.appendChild(
6130
6143
  btn('移除', async () => {
@@ -6143,6 +6156,23 @@ const seatAvatarEl = (s, size) => {
6143
6156
 
6144
6157
  const acts = document.createElement('div')
6145
6158
  acts.style.cssText = 'display:flex;gap:6px;flex-wrap:wrap;align-items:center'
6159
+ // 还没坐下:给一个明确的「坐下」按钮,点空位也能坐
6160
+ if (!(meSeat && meSeat.id)) {
6161
+ acts.appendChild(
6162
+ btn(
6163
+ '坐下',
6164
+ async () => {
6165
+ try {
6166
+ await api2('POST', '/api/mj/rooms/' + roomId + '/join')
6167
+ await render()
6168
+ } catch (e) {
6169
+ onToast('坐下失败:' + friendly(e))
6170
+ }
6171
+ },
6172
+ true,
6173
+ ),
6174
+ )
6175
+ }
6146
6176
  if (meSeat && meSeat.id) {
6147
6177
  acts.appendChild(
6148
6178
  btn(
@@ -6249,7 +6279,22 @@ const seatAvatarEl = (s, size) => {
6249
6279
  wrap.remove()
6250
6280
  })
6251
6281
 
6252
- renderLobby()
6282
+ // 首次渲染如果抛错,把错误写在窗口里,而不是留一个空白窗口
6283
+ Promise.resolve()
6284
+ .then(() => renderLobby())
6285
+ .catch((e) => {
6286
+ bodyEl.textContent = ''
6287
+ const box = document.createElement('div')
6288
+ box.style.cssText = 'font-size:12px;color:#c0392b;padding:12px;line-height:1.7'
6289
+ box.textContent = '麻将加载失败:' + (e && e.message ? e.message : String(e))
6290
+ const retry = document.createElement('button')
6291
+ retry.textContent = '重试'
6292
+ retry.style.cssText =
6293
+ 'display:block;margin-top:10px;padding:6px 14px;border-radius:9px;border:1.5px solid #ffd3e6;background:#fff;cursor:pointer'
6294
+ retry.addEventListener('click', () => renderLobby().catch(() => {}))
6295
+ box.appendChild(retry)
6296
+ bodyEl.appendChild(box)
6297
+ })
6253
6298
  timer = window.setInterval(tick, 1300)
6254
6299
  return { close: () => wrap.remove() }
6255
6300
  }
@@ -6275,8 +6320,22 @@ const seatAvatarEl = (s, size) => {
6275
6320
  el.style.bottom = 'auto'
6276
6321
  }
6277
6322
  const saved = readJson(SK)
6323
+ const visible = () => {
6324
+ const r = el.getBoundingClientRect()
6325
+ const vw = window.innerWidth
6326
+ const vh = window.innerHeight
6327
+ return r.right > 40 && r.left < vw - 40 && r.bottom > 40 && r.top < vh - 40
6328
+ }
6278
6329
  if (saved && typeof saved.x === 'number' && typeof saved.y === 'number') {
6279
6330
  place(saved.x, saved.y)
6331
+ // 上次保存的位置如果跑到屏幕外(换显示器 / 改了缩放),回到右下角默认位
6332
+ if (!visible()) {
6333
+ el.style.left = ''
6334
+ el.style.top = ''
6335
+ el.style.right = '18px'
6336
+ el.style.bottom = '18px'
6337
+ writeJson(SK, { x: el.offsetLeft, y: el.offsetTop })
6338
+ }
6280
6339
  } else {
6281
6340
  const r = el.getBoundingClientRect()
6282
6341
  const sc = el.__scale || 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-share-chat",
3
- "version": "0.40.0",
3
+ "version": "0.40.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "keywords": [