Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7a743ba09 | ||
|
|
751d9a34e3 | ||
|
|
6facf5d72d | ||
|
|
da68f0a582 | ||
|
|
9cb0979606 | ||
|
|
f778064aef | ||
|
|
1ac5095177 | ||
|
|
bc64ff47b2 | ||
|
|
8083c4f06d | ||
|
|
7770c763cc | ||
|
|
b4a8546ce6 | ||
|
|
3b83eac099 | ||
|
|
c623a32bb5 | ||
|
|
03f509d83e | ||
|
|
a33f130341 | ||
|
|
7ab78bd550 | ||
|
|
71da064cab | ||
|
|
569e62fef4 | ||
|
|
fcc7c70310 | ||
|
|
fdc24083cf | ||
|
|
6f725bc0ef | ||
|
|
f6b1044a17 | ||
|
|
f52575db9c | ||
|
|
7f8ae8bd74 | ||
|
|
b211c8773b | ||
|
|
b78fbbdc4e | ||
|
|
0da9f68353 | ||
|
|
d4e3a99e61 | ||
|
|
c2f6f9d226 | ||
|
|
0f6d8b37f4 | ||
|
|
5015fb2838 | ||
|
|
e9abc9840a | ||
|
|
47beece729 | ||
|
|
7ab391d48f | ||
|
|
065a0b3178 | ||
|
|
4104235546 | ||
|
|
bc2acc3eb6 | ||
|
|
2d3c590c71 | ||
|
|
cb9762b0d6 | ||
|
|
3e15cb1481 | ||
|
|
57780ae99c | ||
|
|
3dda7fcf60 | ||
|
|
bddd591d63 | ||
|
|
0d19412c96 | ||
|
|
164bb267f1 | ||
|
|
8929501be5 | ||
|
|
383d371d00 | ||
|
|
5b06034255 | ||
|
|
449fad5ed1 | ||
|
|
059ba0b565 | ||
|
|
4675a5b5e3 | ||
|
|
ff3a1cb00b | ||
|
|
29579f80d3 | ||
|
|
16ade71598 | ||
|
|
2238a34c53 | ||
|
|
ea71591557 | ||
|
|
e87ba066db | ||
|
|
bb4bcdf600 | ||
|
|
1171390996 | ||
|
|
be59cca162 | ||
|
|
444178df05 | ||
|
|
d2737a4998 | ||
|
|
866ffbf774 | ||
|
|
66807fca8d | ||
|
|
47ac13b114 | ||
|
|
e578ba521d |
@@ -0,0 +1 @@
|
||||
graphify-out/graph.json merge=graphify
|
||||
@@ -13,15 +13,21 @@ declare module 'vue' {
|
||||
ADivider: typeof import('ant-design-vue/es')['Divider']
|
||||
AForm: typeof import('ant-design-vue/es')['Form']
|
||||
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
||||
AImage: typeof import('ant-design-vue/es')['Image']
|
||||
AInput: typeof import('ant-design-vue/es')['Input']
|
||||
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
|
||||
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||
AppCreditLink: typeof import('./src/components/AppCreditLink.vue')['default']
|
||||
ARadio: typeof import('ant-design-vue/es')['Radio']
|
||||
ARadioButton: typeof import('ant-design-vue/es')['RadioButton']
|
||||
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
|
||||
ASelect: typeof import('ant-design-vue/es')['Select']
|
||||
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
||||
ASlider: typeof import('ant-design-vue/es')['Slider']
|
||||
ASpin: typeof import('ant-design-vue/es')['Spin']
|
||||
ASwitch: typeof import('ant-design-vue/es')['Switch']
|
||||
ATag: typeof import('ant-design-vue/es')['Tag']
|
||||
ATextarea: typeof import('ant-design-vue/es')['Textarea']
|
||||
ATooltip: typeof import('ant-design-vue/es')['Tooltip']
|
||||
BaseDatePicker: typeof import('./src/components/BasicPacks/BaseDatePicker/src/BaseDatePicker.vue')['default']
|
||||
Basic: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/basic.vue')['default']
|
||||
@@ -46,8 +52,10 @@ declare module 'vue' {
|
||||
Disabled: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/disabled.vue')['default']
|
||||
DisabledDate: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/disabled-date.vue')['default']
|
||||
Empty: typeof import('./src/components/empty.vue')['default']
|
||||
EnamadBadge: typeof import('./src/components/EnamadBadge.vue')['default']
|
||||
ExtraFooter: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/extra-footer.vue')['default']
|
||||
Format: typeof import('./src/components/BasicPacks/BaseDatePicker/src/datePick/demo/format.vue')['default']
|
||||
GoldDayCalculatorModal: typeof import('./src/components/GoldDayCalculatorModal.vue')['default']
|
||||
GoldLoading: typeof import('./src/components/GoldLoading.vue')['default']
|
||||
InstallButton: typeof import('./src/components/InstallButton.vue')['default']
|
||||
ListAnim: typeof import('./src/components/ListAnim.vue')['default']
|
||||
@@ -73,5 +81,6 @@ declare module 'vue' {
|
||||
TransactionSkeleton: typeof import('./src/components/TransactionSkeleton.vue')['default']
|
||||
VanActionSheet: typeof import('vant/es')['ActionSheet']
|
||||
VanDialog: typeof import('vant/es')['Dialog']
|
||||
VanField: typeof import('vant/es')['Field']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"0": "useTvMonitorPage",
|
||||
"1": "ref_utils",
|
||||
"2": "index.vue",
|
||||
"3": "productPrice.ts",
|
||||
"4": "useNewPhysicalRequestPage.ts",
|
||||
"5": "api/products.ts",
|
||||
"6": "priceSocket.ts",
|
||||
"7": "priceSocketState.ts",
|
||||
"8": "useProductsPageData.ts",
|
||||
"9": "AuthPriceStream"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"0": "d7734412cf0800ce", "1": "67d1701e4c6cea74", "2": "a1988eda2ebb6afe", "3": "18bc618fd6f328bb", "4": "b16e1aea09ac331f", "5": "8d51306eb7d0daf2", "6": "fe2bcdb916bbc9f9", "7": "ac69b3434e72782c", "8": "004ed482633014da", "9": "08b88f1fc8c91c56"}
|
||||
@@ -0,0 +1 @@
|
||||
.
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"0": "useTvMonitorPage",
|
||||
"1": "useTvMonitorPage.ts",
|
||||
"2": "index.vue",
|
||||
"3": "productPrice.ts",
|
||||
"4": "getProductBaseBuyPrice",
|
||||
"5": "ref_models",
|
||||
"6": "isTvProductPriceInactive",
|
||||
"7": "applyPriceOffsetPercent"
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
# Graph Report - ghatreh_user (2026-09-27)
|
||||
|
||||
## Corpus Check
|
||||
- 598 files · ~506,745 words
|
||||
- Verdict: corpus is large enough that graph structure adds value.
|
||||
- Unclassified: 51 file(s) not represented in the graph (top: .less 25, .eot 6, .ttf 6)
|
||||
|
||||
## Summary
|
||||
- 84 nodes · 154 edges · 8 communities
|
||||
- Extraction: 91% EXTRACTED · 9% INFERRED · 0% AMBIGUOUS · INFERRED: 14 edges (avg confidence: 0.85)
|
||||
- Token cost: 0 input · 0 output
|
||||
|
||||
## Graph Freshness
|
||||
- Built from commit: `8083c4f0`
|
||||
- Run `git rev-parse HEAD` and compare to check if the graph is stale.
|
||||
- Run `graphify update .` after code changes (no API cost).
|
||||
|
||||
## Community Hubs (Navigation)
|
||||
- useTvMonitorPage
|
||||
- useTvMonitorPage.ts
|
||||
- index.vue
|
||||
- productPrice.ts
|
||||
- getProductBaseBuyPrice
|
||||
- ref_models
|
||||
- isTvProductPriceInactive
|
||||
- applyPriceOffsetPercent
|
||||
|
||||
## God Nodes (most connected - your core abstractions)
|
||||
1. `useTvMonitorPage()` - 25 edges
|
||||
2. `getProductBaseBuyPrice()` - 10 edges
|
||||
3. `getProductBuyPrice()` - 7 edges
|
||||
4. `getProductBaseSellPrice()` - 6 edges
|
||||
5. `getProductSellPrice()` - 6 edges
|
||||
6. `productUsesLastPriceIfZero()` - 5 edges
|
||||
7. `applyPriceOffsetPercent()` - 5 edges
|
||||
8. `isProductPriceInactive()` - 5 edges
|
||||
9. `formatTvPrice()` - 5 edges
|
||||
10. `cashFeeOptions()` - 4 edges
|
||||
|
||||
## Surprising Connections (you probably didn't know these)
|
||||
- `useTvMonitorPage()` --indirect_call--> `isShowOnTv()` [INFERRED]
|
||||
src/views/tv/composables/useTvMonitorPage.ts → src/views/tv/composables/useTvMonitorPage.ts _Bridges community 1 → community 0_
|
||||
- `colleagueSideUnit()` --calls--> `getColleagueSourcedUnitPrice()` [EXTRACTED]
|
||||
src/utils/productPrice.ts → src/utils/productPrice.ts _Bridges community 4 → community 7_
|
||||
- `getProductBuyPrice()` --calls--> `getProductBaseBuyPrice()` [EXTRACTED]
|
||||
src/utils/productPrice.ts → src/utils/productPrice.ts _Bridges community 4 → community 3_
|
||||
- `getTvProductBuyPrice()` --calls--> `getProductBuyPrice()` [EXTRACTED]
|
||||
src/utils/productPrice.ts → src/utils/productPrice.ts _Bridges community 3 → community 6_
|
||||
- `isTvProductPriceInactive()` --calls--> `isProductPriceInactive()` [EXTRACTED]
|
||||
src/utils/productPrice.ts → src/utils/productPrice.ts _Bridges community 4 → community 6_
|
||||
|
||||
## Import Cycles
|
||||
- None detected.
|
||||
|
||||
## Communities (8 total, 0 thin omitted)
|
||||
|
||||
### Community 0 - "useTvMonitorPage"
|
||||
Cohesion: 0.14
|
||||
Nodes (17): floorTvToman(), formatTvPrice(), parseTvNews(), useTvMonitorPage(), hideCursorSoon(), isProductTvInactive(), liveQuoteLabel(), loadProducts() (+9 more)
|
||||
|
||||
### Community 1 - "useTvMonitorPage.ts"
|
||||
Cohesion: 0.17
|
||||
Nodes (15): ref_api, ref_assets, ref_moment, ref_moment_jalaali, ref_store, ref_utils, ref_vue, ref_vueuse_core (+7 more)
|
||||
|
||||
### Community 2 - "index.vue"
|
||||
Cohesion: 0.19
|
||||
Nodes (15): ref_components, ref_views, coinColumns, extraTickerLoop, loopNews(), loopTicker(), marqueeCopies(), newsDuration() (+7 more)
|
||||
|
||||
### Community 3 - "productPrice.ts"
|
||||
Cohesion: 0.44
|
||||
Nodes (9): buyCashFee(), cashFeeOptions(), getProductBuyPrice(), getProductSellPrice(), hasProductUnitWeight(), isProductWithoutDisplayPrice(), productPriceAmountFactor(), productUsesLiveBoardQuote() (+1 more)
|
||||
|
||||
### Community 4 - "getProductBaseBuyPrice"
|
||||
Cohesion: 0.43
|
||||
Nodes (8): colleagueSideUnit(), getProductBaseBuyPrice(), getProductBaseSellPrice(), getReferenceProductBaseBuyPrice(), hasReferenceReadingMethod(), isProductPriceInactive(), isProductVisible(), productUsesLastPriceIfZero()
|
||||
|
||||
### Community 5 - "ref_models"
|
||||
Cohesion: 0.40
|
||||
Nodes (4): ref_models, CountPInventory, PInventory, Product
|
||||
|
||||
### Community 6 - "isTvProductPriceInactive"
|
||||
Cohesion: 0.50
|
||||
Nodes (5): getTvProductBuyPrice(), getTvProductSellPrice(), isTvProductPriceInactive(), tvBuyUnitPrice(), tvSellUnitPrice()
|
||||
|
||||
### Community 7 - "applyPriceOffsetPercent"
|
||||
Cohesion: 0.67
|
||||
Nodes (3): applyPriceOffsetPercent(), getColleagueSourcedUnitPrice(), resolvePriceOffsetRatio()
|
||||
|
||||
## Knowledge Gaps
|
||||
- **6 isolated node(s):** `Product`, `PInventory`, `CountPInventory`, `{ theme, themeVars, toggleTheme }`, `{
|
||||
rootEl,
|
||||
brandName,
|
||||
brandLogo,
|
||||
nowLabel,
|
||||
dateLabel,
|
||||
parsianCoins,
|
||||
bankCoins,
|
||||
hasCoinBoard,
|
||||
hasBoardContent,
|
||||
tickerProducts,
|
||||
tickerTitle,
|
||||
extraTickerProducts,
|
||||
extraTickerTitle,
|
||||
tvNewsItems,
|
||||
newsTickerTitle,
|
||||
statusBanner,
|
||||
showMainQuote,
|
||||
mainQuoteReady,
|
||||
mainQuoteReady,
|
||||
liveBuy,
|
||||
liveSell,
|
||||
isLive,
|
||||
isFullscreen,
|
||||
cursorHidden,
|
||||
loading,
|
||||
productWeightLabel,
|
||||
tickerItemLabel,
|
||||
isProductTvInactive,
|
||||
productBuyLabel,
|
||||
productSellLabel,
|
||||
liveQuoteLabel,
|
||||
toggleFullscreen,
|
||||
}` (+1 more)
|
||||
These have ≤1 connection - possible missing edges or undocumented components. (Counts symbols only; 18 node(s) total have ≤1 connection when file, concept and rationale nodes are included.)
|
||||
|
||||
## Suggested Questions
|
||||
_Questions this graph is uniquely positioned to answer:_
|
||||
|
||||
- **Why does `useTvMonitorPage()` connect `useTvMonitorPage` to `useTvMonitorPage.ts`?**
|
||||
_High betweenness centrality (0.342) - this node is a cross-community bridge._
|
||||
- **Why does `formatTvPrice()` connect `useTvMonitorPage` to `useTvMonitorPage.ts`?**
|
||||
_High betweenness centrality (0.026) - this node is a cross-community bridge._
|
||||
- **Why does `getProductBaseBuyPrice()` connect `getProductBaseBuyPrice` to `productPrice.ts`, `applyPriceOffsetPercent`?**
|
||||
_High betweenness centrality (0.004) - this node is a cross-community bridge._
|
||||
- **Are the 13 inferred relationships involving `useTvMonitorPage()` (e.g. with `isBankCoin()` and `isGoldBar()`) actually correct?**
|
||||
_`useTvMonitorPage()` has 13 INFERRED edges - model-reasoned connections that need verification._
|
||||
- **What connects `Product`, `PInventory`, `CountPInventory` to the rest of the system?**
|
||||
_6 weakly-connected nodes found - possible documentation gaps or missing edges._
|
||||
- **Should `useTvMonitorPage` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.1380952380952381 - nodes in this community are weakly interconnected._
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"0": "useTvMonitorPage",
|
||||
"1": "ref_utils",
|
||||
"2": "index.vue",
|
||||
"3": "productPrice.ts",
|
||||
"4": "forceReconnect",
|
||||
"5": "api/products.ts",
|
||||
"6": "priceSocket.ts",
|
||||
"7": "connect",
|
||||
"8": "useProductsPageData.ts",
|
||||
"9": "AuthPriceStream",
|
||||
"10": "initPriceRealtimeChannel"
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
# Graph Report - ghatreh_user (2026-09-28)
|
||||
|
||||
## Corpus Check
|
||||
- 598 files · ~506,942 words
|
||||
- Verdict: corpus is large enough that graph structure adds value.
|
||||
- Unclassified: 51 file(s) not represented in the graph (top: .less 25, .eot 6, .ttf 6)
|
||||
|
||||
## Summary
|
||||
- 196 nodes · 413 edges · 11 communities (10 shown, 1 thin omitted)
|
||||
- Extraction: 93% EXTRACTED · 7% INFERRED · 0% AMBIGUOUS · INFERRED: 27 edges (avg confidence: 0.85)
|
||||
- Token cost: 0 input · 0 output
|
||||
|
||||
## Graph Freshness
|
||||
- Built from commit: `1ac50951`
|
||||
- Run `git rev-parse HEAD` and compare to check if the graph is stale.
|
||||
- Run `graphify update .` after code changes (no API cost).
|
||||
|
||||
## Community Hubs (Navigation)
|
||||
- useTvMonitorPage
|
||||
- ref_utils
|
||||
- index.vue
|
||||
- productPrice.ts
|
||||
- forceReconnect
|
||||
- api/products.ts
|
||||
- priceSocket.ts
|
||||
- connect
|
||||
- useProductsPageData.ts
|
||||
- AuthPriceStream
|
||||
- initPriceRealtimeChannel
|
||||
|
||||
## God Nodes (most connected - your core abstractions)
|
||||
1. `useTvMonitorPage()` - 28 edges
|
||||
2. `connect()` - 15 edges
|
||||
3. `getProductBaseBuyPrice()` - 10 edges
|
||||
4. `touchStreamActivity()` - 9 edges
|
||||
5. `runFallbackPoll()` - 9 edges
|
||||
6. `bindStreamEvents()` - 9 edges
|
||||
7. `forceReconnect()` - 9 edges
|
||||
8. `maybeShowNetworkAlert()` - 8 edges
|
||||
9. `disconnect()` - 8 edges
|
||||
10. `applyProductsList()` - 8 edges
|
||||
|
||||
## Surprising Connections (you probably didn't know these)
|
||||
- `connect()` --calls--> `AuthPriceStream` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 9 → community 7_
|
||||
- `connect()` --calls--> `resolveStreamUrl()` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 10 → community 7_
|
||||
- `forceReconnect()` --calls--> `clearReconnectTimer()` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 7 → community 4_
|
||||
- `connect()` --calls--> `touchStreamActivity()` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 1 → community 7_
|
||||
- `connect()` --calls--> `stopFallbackPolling()` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 6 → community 7_
|
||||
|
||||
## Import Cycles
|
||||
- None detected.
|
||||
|
||||
## Communities (11 total, 1 thin omitted)
|
||||
|
||||
### Community 0 - "useTvMonitorPage"
|
||||
Cohesion: 0.09
|
||||
Nodes (33): ref_api, ref_assets, ref_moment, ref_moment_jalaali, ref_vueuse_core, bankCoinRank(), floorTvToman(), formatTvPrice() (+25 more)
|
||||
|
||||
### Community 1 - "ref_utils"
|
||||
Cohesion: 0.23
|
||||
Nodes (15): ref_composables, ref_store, ref_utils, applyAppNotificationFromStream(), applyLastFromStream(), applySettingsFromStream(), applyUnreadCountFromStreamPayload(), bindStreamEvents() (+7 more)
|
||||
|
||||
### Community 2 - "index.vue"
|
||||
Cohesion: 0.19
|
||||
Nodes (15): ref_components, ref_vue, coinColumns, extraTickerLoop, loopNews(), loopTicker(), marqueeCopies(), newsDuration() (+7 more)
|
||||
|
||||
### Community 3 - "productPrice.ts"
|
||||
Cohesion: 0.19
|
||||
Nodes (25): applyPriceOffsetPercent(), buyCashFee(), cashFeeOptions(), colleagueSideUnit(), getColleagueSourcedUnitPrice(), getProductBaseBuyPrice(), getProductBaseSellPrice(), getProductBuyPrice() (+17 more)
|
||||
|
||||
### Community 4 - "forceReconnect"
|
||||
Cohesion: 0.21
|
||||
Nodes (16): bindBrowserNetworkListeners(), forceReconnect(), isPageVisible(), maybeShowNetworkAlert(), notifyPriceLastFetchFailed(), onBrowserOffline(), onBrowserOnline(), onPageShow() (+8 more)
|
||||
|
||||
### Community 5 - "api/products.ts"
|
||||
Cohesion: 0.15
|
||||
Nodes (5): ref_models, TvServerTime, CountPInventory, PInventory, Product
|
||||
|
||||
### Community 6 - "priceSocket.ts"
|
||||
Cohesion: 0.16
|
||||
Nodes (12): ref_ant_design_vue, ref_views, clearFallbackPollTimer(), clearPriceNetworkAlert(), getPriceSourceStaleMs(), isMobileDevice(), isRealPriceOutage(), onTvBoard() (+4 more)
|
||||
|
||||
### Community 7 - "connect"
|
||||
Cohesion: 0.36
|
||||
Nodes (10): clearConnectingLifecycle(), clearReconnectTimer(), connect(), disconnect(), disconnectSourceOnly(), handleStreamLost(), markConnectingLifecycle(), scheduleReconnect() (+2 more)
|
||||
|
||||
### Community 8 - "useProductsPageData.ts"
|
||||
Cohesion: 0.12
|
||||
Nodes (31): applyProductsList(), applyProductsListFromSocket(), applySocketProductList(), changeProductsTab(), flagOff(), flagOn(), initialized, initProductsPageData() (+23 more)
|
||||
|
||||
### Community 10 - "initPriceRealtimeChannel"
|
||||
Cohesion: 0.60
|
||||
Nodes (5): initPriceRealtimeChannel(), isPriceWebSocketEnabled(), isTruthySetting(), resolveStreamPath(), resolveStreamUrl()
|
||||
|
||||
## Knowledge Gaps
|
||||
- **13 isolated node(s):** `initialized`, `productsActiveKey`, `productsTypeItems`, `productsFirstItems`, `productsItems` (+8 more)
|
||||
These have ≤1 connection - possible missing edges or undocumented components. (Counts symbols only; 37 node(s) total have ≤1 connection when file, concept and rationale nodes are included.)
|
||||
- **1 thin communities (<3 nodes) omitted from report** — run `graphify query` to explore isolated nodes.
|
||||
|
||||
## Suggested Questions
|
||||
_Questions this graph is uniquely positioned to answer:_
|
||||
|
||||
- **Why does `AuthPriceStream` connect `AuthPriceStream` to `priceSocket.ts`, `connect`?**
|
||||
_High betweenness centrality (0.035) - this node is a cross-community bridge._
|
||||
- **Why does `runFallbackPoll()` connect `priceSocket.ts` to `ref_utils`, `forceReconnect`?**
|
||||
_High betweenness centrality (0.019) - this node is a cross-community bridge._
|
||||
- **Are the 13 inferred relationships involving `useTvMonitorPage()` (e.g. with `isBankCoin()` and `isGoldBar()`) actually correct?**
|
||||
_`useTvMonitorPage()` has 13 INFERRED edges - model-reasoned connections that need verification._
|
||||
- **What connects `initialized`, `productsActiveKey`, `productsTypeItems` to the rest of the system?**
|
||||
_13 weakly-connected nodes found - possible documentation gaps or missing edges._
|
||||
- **Should `useTvMonitorPage` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.09309309309309309 - nodes in this community are weakly interconnected._
|
||||
- **Should `useProductsPageData.ts` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.11931818181818182 - nodes in this community are weakly interconnected._
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"0": "useTvMonitorPage",
|
||||
"1": "ref_utils",
|
||||
"2": "index.vue",
|
||||
"3": "productPrice.ts",
|
||||
"5": "api/products.ts",
|
||||
"6": "priceSocket.ts",
|
||||
"8": "useProductsPageData.ts",
|
||||
"9": "AuthPriceStream"
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
# Graph Report - ghatreh_user (2026-09-28)
|
||||
|
||||
## Corpus Check
|
||||
- 598 files · ~506,836 words
|
||||
- Verdict: corpus is large enough that graph structure adds value.
|
||||
- Unclassified: 51 file(s) not represented in the graph (top: .less 25, .eot 6, .ttf 6)
|
||||
|
||||
## Summary
|
||||
- 198 nodes · 409 edges · 8 communities (7 shown, 1 thin omitted)
|
||||
- Extraction: 93% EXTRACTED · 7% INFERRED · 0% AMBIGUOUS · INFERRED: 28 edges (avg confidence: 0.85)
|
||||
- Token cost: 0 input · 0 output
|
||||
|
||||
## Graph Freshness
|
||||
- Built from commit: `9cb09796`
|
||||
- Run `git rev-parse HEAD` and compare to check if the graph is stale.
|
||||
- Run `graphify update .` after code changes (no API cost).
|
||||
|
||||
## Community Hubs (Navigation)
|
||||
- useTvMonitorPage
|
||||
- ref_utils
|
||||
- index.vue
|
||||
- productPrice.ts
|
||||
- api/products.ts
|
||||
- priceSocket.ts
|
||||
- useProductsPageData.ts
|
||||
- AuthPriceStream
|
||||
|
||||
## God Nodes (most connected - your core abstractions)
|
||||
1. `useTvMonitorPage()` - 25 edges
|
||||
2. `connect()` - 15 edges
|
||||
3. `getProductBaseBuyPrice()` - 10 edges
|
||||
4. `touchStreamActivity()` - 9 edges
|
||||
5. `bindStreamEvents()` - 9 edges
|
||||
6. `forceReconnect()` - 9 edges
|
||||
7. `runFallbackPoll()` - 8 edges
|
||||
8. `maybeShowNetworkAlert()` - 8 edges
|
||||
9. `disconnect()` - 8 edges
|
||||
10. `applyProductsList()` - 8 edges
|
||||
|
||||
## Surprising Connections (you probably didn't know these)
|
||||
- `connect()` --calls--> `AuthPriceStream` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 9 → community 6_
|
||||
- `connect()` --calls--> `touchStreamActivity()` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 1 → community 6_
|
||||
|
||||
## Import Cycles
|
||||
- None detected.
|
||||
|
||||
## Communities (8 total, 1 thin omitted)
|
||||
|
||||
### Community 0 - "useTvMonitorPage"
|
||||
Cohesion: 0.10
|
||||
Nodes (30): ref_api, ref_assets, ref_moment, ref_moment_jalaali, ref_vueuse_core, bankCoinRank(), floorTvToman(), formatTvPrice() (+22 more)
|
||||
|
||||
### Community 1 - "ref_utils"
|
||||
Cohesion: 0.23
|
||||
Nodes (15): ref_composables, ref_store, ref_utils, applyAppNotificationFromStream(), applyLastFromStream(), applySettingsFromStream(), applyUnreadCountFromStreamPayload(), bindStreamEvents() (+7 more)
|
||||
|
||||
### Community 2 - "index.vue"
|
||||
Cohesion: 0.10
|
||||
Nodes (23): ref_components, ref_views, ref_vue, priceSocketConnected, priceStreamConnectingSince, priceStreamLifecycle, priceStreamList, priceStreamProducts (+15 more)
|
||||
|
||||
### Community 3 - "productPrice.ts"
|
||||
Cohesion: 0.20
|
||||
Nodes (24): applyPriceOffsetPercent(), buyCashFee(), cashFeeOptions(), getColleagueSourcedUnitPrice(), getProductBaseBuyPrice(), getProductBaseSellPrice(), getProductBuyPrice(), getProductSellPrice() (+16 more)
|
||||
|
||||
### Community 5 - "api/products.ts"
|
||||
Cohesion: 0.15
|
||||
Nodes (5): ref_models, TvServerTime, CountPInventory, PInventory, Product
|
||||
|
||||
### Community 6 - "priceSocket.ts"
|
||||
Cohesion: 0.11
|
||||
Nodes (41): ref_ant_design_vue, bindBrowserNetworkListeners(), clearConnectingLifecycle(), clearFallbackPollTimer(), clearPriceNetworkAlert(), clearReconnectTimer(), connect(), disconnect() (+33 more)
|
||||
|
||||
### Community 8 - "useProductsPageData.ts"
|
||||
Cohesion: 0.12
|
||||
Nodes (31): applyProductsList(), applyProductsListFromSocket(), applySocketProductList(), changeProductsTab(), flagOff(), flagOn(), initialized, initProductsPageData() (+23 more)
|
||||
|
||||
## Knowledge Gaps
|
||||
- **20 isolated node(s):** `Product`, `PInventory`, `CountPInventory`, `priceSocketConnected`, `priceWssEnabled` (+15 more)
|
||||
These have ≤1 connection - possible missing edges or undocumented components. (Counts symbols only; 43 node(s) total have ≤1 connection when file, concept and rationale nodes are included.)
|
||||
- **1 thin communities (<3 nodes) omitted from report** — run `graphify query` to explore isolated nodes.
|
||||
|
||||
## Suggested Questions
|
||||
_Questions this graph is uniquely positioned to answer:_
|
||||
|
||||
- **Why does `AuthPriceStream` connect `AuthPriceStream` to `priceSocket.ts`?**
|
||||
_High betweenness centrality (0.035) - this node is a cross-community bridge._
|
||||
- **Why does `runFallbackPoll()` connect `priceSocket.ts` to `ref_utils`, `index.vue`?**
|
||||
_High betweenness centrality (0.016) - this node is a cross-community bridge._
|
||||
- **Are the 14 inferred relationships involving `useTvMonitorPage()` (e.g. with `isBankCoin()` and `isGoldBar()`) actually correct?**
|
||||
_`useTvMonitorPage()` has 14 INFERRED edges - model-reasoned connections that need verification._
|
||||
- **What connects `Product`, `PInventory`, `CountPInventory` to the rest of the system?**
|
||||
_20 weakly-connected nodes found - possible documentation gaps or missing edges._
|
||||
- **Should `useTvMonitorPage` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.09982174688057041 - nodes in this community are weakly interconnected._
|
||||
- **Should `index.vue` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.10153846153846154 - nodes in this community are weakly interconnected._
|
||||
- **Should `priceSocket.ts` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.10638297872340426 - nodes in this community are weakly interconnected._
|
||||
@@ -0,0 +1,110 @@
|
||||
# Graph Report - ghatreh_user (2026-09-29)
|
||||
|
||||
## Corpus Check
|
||||
- 598 files · ~506,875 words
|
||||
- Verdict: corpus is large enough that graph structure adds value.
|
||||
- Unclassified: 51 file(s) not represented in the graph (top: .less 25, .eot 6, .ttf 6)
|
||||
|
||||
## Summary
|
||||
- 208 nodes · 426 edges · 10 communities (9 shown, 1 thin omitted)
|
||||
- Extraction: 92% EXTRACTED · 8% INFERRED · 0% AMBIGUOUS · INFERRED: 33 edges (avg confidence: 0.85)
|
||||
- Token cost: 0 input · 0 output
|
||||
|
||||
## Graph Freshness
|
||||
- Built from commit: `da68f0a5`
|
||||
- Run `git rev-parse HEAD` and compare to check if the graph is stale.
|
||||
- Run `graphify update .` after code changes (no API cost).
|
||||
|
||||
## Community Hubs (Navigation)
|
||||
- useTvMonitorPage
|
||||
- ref_utils
|
||||
- index.vue
|
||||
- productPrice.ts
|
||||
- useNewPhysicalRequestPage.ts
|
||||
- api/products.ts
|
||||
- priceSocket.ts
|
||||
- priceSocketState.ts
|
||||
- useProductsPageData.ts
|
||||
- AuthPriceStream
|
||||
|
||||
## God Nodes (most connected - your core abstractions)
|
||||
1. `useTvMonitorPage()` - 25 edges
|
||||
2. `connect()` - 15 edges
|
||||
3. `getProductBaseBuyPrice()` - 10 edges
|
||||
4. `bindStreamEvents()` - 9 edges
|
||||
5. `touchStreamActivity()` - 9 edges
|
||||
6. `forceReconnect()` - 9 edges
|
||||
7. `useNewPhysicalRequestPage()` - 8 edges
|
||||
8. `applyProductsList()` - 8 edges
|
||||
9. `applySocketProductList()` - 8 edges
|
||||
10. `disconnect()` - 8 edges
|
||||
|
||||
## Surprising Connections (you probably didn't know these)
|
||||
- `connect()` --calls--> `AuthPriceStream` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 9 → community 6_
|
||||
- `connect()` --calls--> `bindStreamEvents()` [EXTRACTED]
|
||||
src/utils/priceSocket.ts → src/utils/priceSocket.ts _Bridges community 1 → community 6_
|
||||
|
||||
## Import Cycles
|
||||
- None detected.
|
||||
|
||||
## Communities (10 total, 1 thin omitted)
|
||||
|
||||
### Community 0 - "useTvMonitorPage"
|
||||
Cohesion: 0.10
|
||||
Nodes (29): ref_assets, ref_moment, ref_moment_jalaali, ref_vueuse_core, bankCoinRank(), floorTvToman(), formatTvPrice(), isBankCoin() (+21 more)
|
||||
|
||||
### Community 1 - "ref_utils"
|
||||
Cohesion: 0.23
|
||||
Nodes (15): ref_composables, ref_store, ref_utils, applyAppNotificationFromStream(), applyLastFromStream(), applySettingsFromStream(), applyUnreadCountFromStreamPayload(), bindStreamEvents() (+7 more)
|
||||
|
||||
### Community 2 - "index.vue"
|
||||
Cohesion: 0.19
|
||||
Nodes (15): ref_components, ref_views, coinColumns, extraTickerLoop, loopNews(), loopTicker(), marqueeCopies(), newsDuration() (+7 more)
|
||||
|
||||
### Community 3 - "productPrice.ts"
|
||||
Cohesion: 0.20
|
||||
Nodes (24): applyPriceOffsetPercent(), buyCashFee(), cashFeeOptions(), getColleagueSourcedUnitPrice(), getProductBaseBuyPrice(), getProductBaseSellPrice(), getProductBuyPrice(), getProductSellPrice() (+16 more)
|
||||
|
||||
### Community 4 - "useNewPhysicalRequestPage.ts"
|
||||
Cohesion: 0.12
|
||||
Nodes (13): ref_ant_design_vue, ref_api, ref_lodash, ref_router, NEW_PHYSICAL_REQUEST_KEY, NewPhysicalRequestContext, useNewPhysicalRequestPage(), getAddress() (+5 more)
|
||||
|
||||
### Community 5 - "api/products.ts"
|
||||
Cohesion: 0.15
|
||||
Nodes (5): ref_models, TvServerTime, CountPInventory, PInventory, Product
|
||||
|
||||
### Community 6 - "priceSocket.ts"
|
||||
Cohesion: 0.14
|
||||
Nodes (40): bindBrowserNetworkListeners(), clearConnectingLifecycle(), clearFallbackPollTimer(), clearPriceNetworkAlert(), clearReconnectTimer(), connect(), disconnect(), disconnectSourceOnly() (+32 more)
|
||||
|
||||
### Community 7 - "priceSocketState.ts"
|
||||
Cohesion: 0.20
|
||||
Nodes (8): ref_vue, priceSocketConnected, priceStreamConnectingSince, priceStreamLifecycle, priceStreamList, priceStreamProducts, priceStreamServerUnix, priceWssEnabled
|
||||
|
||||
### Community 8 - "useProductsPageData.ts"
|
||||
Cohesion: 0.12
|
||||
Nodes (31): applyProductsList(), applyProductsListFromSocket(), applySocketProductList(), changeProductsTab(), flagOff(), flagOn(), initialized, initProductsPageData() (+23 more)
|
||||
|
||||
## Knowledge Gaps
|
||||
- **22 isolated node(s):** `NewPhysicalRequestContext`, `NEW_PHYSICAL_REQUEST_KEY`, `initialized`, `productsActiveKey`, `productsTypeItems` (+17 more)
|
||||
These have ≤1 connection - possible missing edges or undocumented components. (Counts symbols only; 45 node(s) total have ≤1 connection when file, concept and rationale nodes are included.)
|
||||
- **1 thin communities (<3 nodes) omitted from report** — run `graphify query` to explore isolated nodes.
|
||||
|
||||
## Suggested Questions
|
||||
_Questions this graph is uniquely positioned to answer:_
|
||||
|
||||
- **Why does `AuthPriceStream` connect `AuthPriceStream` to `priceSocket.ts`?**
|
||||
_High betweenness centrality (0.033) - this node is a cross-community bridge._
|
||||
- **Are the 14 inferred relationships involving `useTvMonitorPage()` (e.g. with `isBankCoin()` and `isGoldBar()`) actually correct?**
|
||||
_`useTvMonitorPage()` has 14 INFERRED edges - model-reasoned connections that need verification._
|
||||
- **What connects `NewPhysicalRequestContext`, `NEW_PHYSICAL_REQUEST_KEY`, `initialized` to the rest of the system?**
|
||||
_22 weakly-connected nodes found - possible documentation gaps or missing edges._
|
||||
- **Should `useTvMonitorPage` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.10416666666666667 - nodes in this community are weakly interconnected._
|
||||
- **Should `useNewPhysicalRequestPage.ts` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.12418300653594772 - nodes in this community are weakly interconnected._
|
||||
- **Should `priceSocket.ts` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.1378048780487805 - nodes in this community are weakly interconnected._
|
||||
- **Should `useProductsPageData.ts` be split into smaller, more focused modules?**
|
||||
_Cohesion score 0.125 - nodes in this community are weakly interconnected._
|
||||
@@ -41,8 +41,14 @@
|
||||
}
|
||||
|
||||
.boot-loader {
|
||||
min-height: 100vh;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 2147483646;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
min-height: 100dvh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
direction: rtl;
|
||||
@@ -53,71 +59,36 @@
|
||||
"Segoe UI",
|
||||
sans-serif;
|
||||
background:
|
||||
radial-gradient(circle at top, var(--boot-orb), transparent 38%),
|
||||
linear-gradient(
|
||||
135deg,
|
||||
var(--boot-bg) 0%,
|
||||
var(--boot-bg-soft) 100%
|
||||
);
|
||||
radial-gradient(ellipse 70% 45% at 50% 28%, var(--boot-orb), transparent 70%),
|
||||
linear-gradient(180deg, var(--boot-bg) 0%, var(--boot-bg-soft) 100%);
|
||||
color: var(--boot-text);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.boot-loader__card {
|
||||
position: relative;
|
||||
width: min(340px, calc(100vw - 48px));
|
||||
padding: 30px 22px 28px;
|
||||
border-radius: 24px;
|
||||
text-align: center;
|
||||
background: var(--boot-card);
|
||||
border: 1px solid var(--boot-border);
|
||||
box-shadow: 0 18px 48px var(--boot-shadow);
|
||||
backdrop-filter: blur(10px);
|
||||
.boot-loader__logo {
|
||||
height: min(20vh, 160px);
|
||||
width: auto;
|
||||
max-width: min(70vw, 280px);
|
||||
object-fit: contain;
|
||||
opacity: 0;
|
||||
transition: opacity 0.28s ease;
|
||||
}
|
||||
|
||||
.boot-loader__orb {
|
||||
position: absolute;
|
||||
top: -72px;
|
||||
left: 50%;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
transform: translateX(-50%);
|
||||
border-radius: 999px;
|
||||
background: var(--boot-orb);
|
||||
filter: blur(8px);
|
||||
pointer-events: none;
|
||||
.boot-loader__logo.is-ready {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.boot-loader__spinner {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
margin: 0 auto 20px;
|
||||
position: absolute;
|
||||
bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 999px;
|
||||
border: 4px solid var(--boot-spinner-track);
|
||||
border: 3px solid var(--boot-spinner-track);
|
||||
border-top-color: var(--boot-accent);
|
||||
animation: boot-spin 0.9s linear infinite;
|
||||
}
|
||||
|
||||
.boot-loader__title {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
margin: 0;
|
||||
font-size: 19px;
|
||||
font-weight: 800;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.boot-loader__text {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
margin: 10px 0 0;
|
||||
color: var(--boot-muted);
|
||||
font-size: 14px;
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
@keyframes boot-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
@@ -143,16 +114,25 @@
|
||||
try {
|
||||
var rawCookie = getCookie(CONFIG_COOKIE_NAME)
|
||||
|
||||
if (!rawCookie) return null
|
||||
|
||||
var decoded = decodeURIComponent(rawCookie)
|
||||
var payload = JSON.parse(decoded)
|
||||
|
||||
return payload && payload.config ? payload.config : null
|
||||
if (rawCookie) {
|
||||
var decoded = decodeURIComponent(rawCookie)
|
||||
var payload = JSON.parse(decoded)
|
||||
if (payload && payload.config) return payload.config
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Boot theme: failed to read cached config', error)
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
var rawLs = localStorage.getItem('APP_CONFIG_LS_CACHE')
|
||||
if (!rawLs) return null
|
||||
var lsPayload = JSON.parse(rawLs)
|
||||
if (lsPayload && lsPayload.config) return lsPayload.config
|
||||
} catch (error) {
|
||||
console.warn('Boot theme: failed to read LS config cache', error)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function normalizeHex(hex) {
|
||||
@@ -238,6 +218,146 @@
|
||||
document.documentElement.style.setProperty(name, value)
|
||||
}
|
||||
|
||||
var BOOT_LOGO_KEY = 'BOOT_LOGO_URL'
|
||||
var BOOT_LOGO_VERSION_KEY = 'BOOT_LOGO_VERSION'
|
||||
|
||||
function rewriteLegacyBootLogoUrl(url) {
|
||||
var value = String(url || '').trim()
|
||||
if (!value) return ''
|
||||
if (value.indexOf('/uploads/') === 0) {
|
||||
var base = 'https://adm.montzar.ir'
|
||||
try {
|
||||
var last = localStorage.getItem('CONFIG_Success_URL')
|
||||
if (last) {
|
||||
var sa = new URL(last)
|
||||
var path = sa.pathname.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
base = path && path !== '/' ? sa.origin + path : sa.origin
|
||||
}
|
||||
} catch (e) {}
|
||||
return base + value
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
function pickAvatarRaw(value) {
|
||||
if (value == null) return ''
|
||||
if (typeof value === 'string') return String(value).trim()
|
||||
if (typeof value === 'object') {
|
||||
return String(value.full_src || value.url || value.src || value.avatar || '').trim()
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function logoCacheValid() {
|
||||
try {
|
||||
var v = String(localStorage.getItem('version') || '').trim()
|
||||
var lv = String(localStorage.getItem(BOOT_LOGO_VERSION_KEY) || '').trim()
|
||||
if (v && lv && v !== lv) return false
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function readCachedLogoUrl() {
|
||||
if (!logoCacheValid()) return ''
|
||||
try {
|
||||
return String(localStorage.getItem(BOOT_LOGO_KEY) || '').trim()
|
||||
} catch (e) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function resolveAbsoluteLogoUrl(raw) {
|
||||
if (!raw) return ''
|
||||
if (/^(https?:\/\/|data:|blob:)/i.test(raw)) {
|
||||
var abs = window.location.protocol === 'https:' ? raw.replace(/^http:\/\//i, 'https://') : raw
|
||||
return rewriteLegacyBootLogoUrl(abs)
|
||||
}
|
||||
var path = raw.replace(/^\/+/, '')
|
||||
return window.location.origin + '/server/' + path
|
||||
}
|
||||
|
||||
function resolveBootLogoUrl(config) {
|
||||
var nested = config && config.user && typeof config.user === 'object' ? config.user : {}
|
||||
var fromUser = rewriteLegacyBootLogoUrl(pickAvatarRaw(nested.avatar))
|
||||
if (fromUser) return resolveAbsoluteLogoUrl(fromUser)
|
||||
|
||||
var cached = readCachedLogoUrl()
|
||||
if (cached && /^(data:|blob:)/i.test(cached)) return cached
|
||||
return resolveAbsoluteLogoUrl(cached)
|
||||
}
|
||||
|
||||
function persistLogoCache(logoUrl) {
|
||||
try {
|
||||
var v = String(localStorage.getItem('version') || '').trim()
|
||||
if (v) localStorage.setItem(BOOT_LOGO_VERSION_KEY, v)
|
||||
if (!logoUrl) return
|
||||
localStorage.setItem(BOOT_LOGO_KEY, logoUrl)
|
||||
if (logoUrl.indexOf('data:') === 0 || typeof fetch !== 'function') return
|
||||
try {
|
||||
if (new URL(logoUrl, window.location.href).origin !== window.location.origin) return
|
||||
} catch (e) {
|
||||
return
|
||||
}
|
||||
fetch(logoUrl, { mode: 'cors', credentials: 'omit' })
|
||||
.then(function (res) {
|
||||
return res && res.ok ? res.blob() : Promise.reject()
|
||||
})
|
||||
.then(function (blob) {
|
||||
if (!blob || blob.size > 450000) return
|
||||
var reader = new FileReader()
|
||||
reader.onloadend = function () {
|
||||
try {
|
||||
if (typeof reader.result === 'string' && reader.result.indexOf('data:') === 0) {
|
||||
localStorage.setItem(BOOT_LOGO_KEY, reader.result)
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
reader.readAsDataURL(blob)
|
||||
})
|
||||
.catch(function () {})
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function applyBootLogo(config) {
|
||||
var img = document.getElementById('boot-logo')
|
||||
if (!img) return
|
||||
|
||||
var logoUrl = resolveBootLogoUrl(config || {})
|
||||
if (!logoUrl) {
|
||||
img.hidden = true
|
||||
img.removeAttribute('src')
|
||||
img.classList.remove('is-ready')
|
||||
return
|
||||
}
|
||||
|
||||
function markReady() {
|
||||
img.hidden = false
|
||||
img.removeAttribute('hidden')
|
||||
img.classList.add('is-ready')
|
||||
persistLogoCache(logoUrl)
|
||||
}
|
||||
|
||||
img.onload = markReady
|
||||
img.onerror = function () {
|
||||
img.hidden = true
|
||||
img.classList.remove('is-ready')
|
||||
}
|
||||
|
||||
if (img.getAttribute('src') === logoUrl && img.complete && img.naturalWidth > 0) {
|
||||
markReady()
|
||||
return
|
||||
}
|
||||
|
||||
img.hidden = false
|
||||
img.removeAttribute('hidden')
|
||||
img.src = logoUrl
|
||||
if (logoUrl.indexOf('data:') === 0) markReady()
|
||||
}
|
||||
|
||||
window.__APPLY_BOOT_BRANDING__ = applyBootLogo
|
||||
|
||||
function applyBootTheme() {
|
||||
var config = readCachedConfig()
|
||||
var user = config && config.user ? config.user : null
|
||||
@@ -289,6 +409,7 @@
|
||||
}
|
||||
|
||||
applyBootTheme()
|
||||
applyBootLogo(readCachedConfig())
|
||||
})()
|
||||
</script>
|
||||
</head>
|
||||
@@ -296,15 +417,15 @@
|
||||
<body>
|
||||
<div id="app">
|
||||
<div class="boot-loader">
|
||||
<div class="boot-loader__card">
|
||||
<div class="boot-loader__orb"></div>
|
||||
<div class="boot-loader__spinner"></div>
|
||||
|
||||
<h1 class="boot-loader__title">در حال هدایت به سامانه</h1>
|
||||
<p class="boot-loader__text">لطفاً چند لحظه صبر کنید...</p>
|
||||
</div>
|
||||
<img id="boot-logo" class="boot-loader__logo" alt="" decoding="async" hidden />
|
||||
<div class="boot-loader__spinner" aria-hidden="true"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (typeof window.__APPLY_BOOT_BRANDING__ === 'function') {
|
||||
window.__APPLY_BOOT_BRANDING__()
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
;(function () {
|
||||
@@ -571,6 +692,10 @@
|
||||
CONFIG_COOKIE_MAX_AGE_SECONDS +
|
||||
'; SameSite=Lax' +
|
||||
secure
|
||||
|
||||
if (typeof window.__APPLY_BOOT_BRANDING__ === 'function') {
|
||||
window.__APPLY_BOOT_BRANDING__(config)
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to write config cookie:', error)
|
||||
}
|
||||
|
||||
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 583 KiB |
@@ -0,0 +1 @@
|
||||
{"nm":"Pre-comp 1","ddd":0,"h":1200,"w":1200,"meta":{"g":"LottieFiles AE 0.1.21"},"layers":[{"ty":4,"nm":"arrow down Outlines","sr":1,"st":0,"op":1020,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[256,256,0],"ix":1},"s":{"a":0,"k":[46.875,46.875,100],"ix":6},"sk":{"a":0,"k":0},"p":{"a":1,"k":[{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[600,528,0],"t":0,"ti":[0,0,0],"to":[0,-15.333,0]},{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[600,436,0],"t":13,"ti":[0,-15.333,0],"to":[0,0,0]},{"s":[600,528,0],"t":27}],"ix":2,"x":"var $bm_rt;\n$bm_rt = loopOut('cycle');"},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":0,"k":100,"ix":11}},"ef":[],"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Group 1","ix":1,"cix":2,"np":4,"it":[{"ty":"sh","bm":0,"hd":false,"mn":"ADBE Vector Shape - Group","nm":"Path 1","ix":1,"d":1,"ks":{"a":0,"k":{"c":true,"i":[[7.831,7.793],[7.792,-7.828],[0,0],[0,0],[11.045,0],[0,-11.046],[0,0],[0,0],[7.829,-7.792],[-7.791,-7.829],[0,0],[-0.005,-0.006],[-7.819,7.833],[-0.005,0.006],[0,0]],"o":[[-7.829,-7.792],[0,0],[0,0],[0,-11.046],[-11.046,0],[0,0],[0,0],[-7.792,-7.828],[-7.83,7.793],[0,0],[0.006,0.007],[7.792,7.809],[0.006,-0.007],[0,0],[7.79,-7.828]],"v":[[118.109,117.328],[89.825,117.394],[20.001,187.557],[20.001,-236],[0.001,-256],[-19.999,-236],[-19.999,187.557],[-89.824,117.393],[-118.107,117.327],[-118.175,145.612],[-14.175,250.116],[-14.157,250.134],[14.158,250.135],[14.176,250.117],[118.176,145.613]]},"ix":2}},{"ty":"fl","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Fill","nm":"Fill 1","c":{"a":0,"k":[0.1608,0.1608,0.3843],"ix":4},"r":1,"o":{"a":0,"k":100,"ix":5}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[255.999,256],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":1},{"ty":4,"nm":"Shape Layer 1","sr":1,"st":0,"op":1020,"ip":0,"hd":false,"ddd":0,"bm":0,"hasMask":false,"ao":0,"ks":{"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[141,141,100],"ix":6},"sk":{"a":0,"k":0},"p":{"a":1,"k":[{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[622.56,380.04,0],"t":0,"ti":[0,0,0],"to":[0,-15.333,0]},{"o":{"x":0.333,"y":0},"i":{"x":0.667,"y":1},"s":[622.56,288.04,0],"t":13,"ti":[0,-15.333,0],"to":[0,0,0]},{"s":[622.56,380.04,0],"t":27}],"ix":2,"x":"var $bm_rt;\n$bm_rt = loopOut('cycle');"},"r":{"a":0,"k":0,"ix":10},"sa":{"a":0,"k":0},"o":{"a":0,"k":100,"ix":11}},"ef":[],"shapes":[{"ty":"gr","bm":0,"hd":false,"mn":"ADBE Vector Group","nm":"Ellipse 1","ix":1,"cix":2,"np":3,"it":[{"ty":"el","bm":0,"hd":false,"mn":"ADBE Vector Shape - Ellipse","nm":"Ellipse Path 1","d":1,"p":{"a":0,"k":[0,0],"ix":3},"s":{"a":0,"k":[144,144],"ix":2}},{"ty":"fl","bm":0,"hd":false,"mn":"ADBE Vector Graphic - Fill","nm":"Fill 1","c":{"a":0,"k":[1,1,1],"ix":4},"r":1,"o":{"a":0,"k":100,"ix":5}},{"ty":"tr","a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"sk":{"a":0,"k":0,"ix":4},"p":{"a":0,"k":[-16,156],"ix":2},"r":{"a":0,"k":0,"ix":6},"sa":{"a":0,"k":0,"ix":5},"o":{"a":0,"k":100,"ix":7}}]}],"ind":2}],"v":"5.5.7","fr":30,"op":1020,"ip":0,"assets":[]}
|
||||
|
Before Width: | Height: | Size: 30 KiB |
@@ -2,7 +2,6 @@
|
||||
<div class="desktopConfig w-full right-0 left-0">
|
||||
<transition mode="out-in" name="fade">
|
||||
<AConfigProvider
|
||||
v-if="!showSplash"
|
||||
:theme="{
|
||||
token: {
|
||||
colorPrimary: colors.primary,
|
||||
@@ -19,34 +18,10 @@
|
||||
</transition>
|
||||
</router-view>
|
||||
</AConfigProvider>
|
||||
|
||||
<div v-else class="app-splash-screen flex items-center justify-center bg-white">
|
||||
<div class="app-splash-screen__gradient app-splash-screen__gradient--top h-1/3 flex">
|
||||
<img :src="img_topGradiant" alt="" class="absolute z-10 w-full h-full object-cover" />
|
||||
<img :src="img_pattern" alt="" class="absolute w-full h-full object-none" />
|
||||
</div>
|
||||
<div class="app-splash-screen__gradient app-splash-screen__gradient--bottom h-1/3">
|
||||
<img
|
||||
:src="img_bottomGradiant"
|
||||
alt=""
|
||||
class="absolute z-10 w-full h-full object-cover"
|
||||
/>
|
||||
<img :src="img_pattern" alt="" class="absolute w-full h-full object-none" />
|
||||
</div>
|
||||
<div class="splash_appear_fade_in relative z-10">
|
||||
<img :src="logoFull" class="h-[20vh] max-h-[180px] w-auto object-contain" alt="" />
|
||||
</div>
|
||||
<div class="app-splash-screen__version home_appear_fade_in_up">
|
||||
<div class="text-center text-xs">نسخه: {{ displayVersion }}</div>
|
||||
</div>
|
||||
<div class="app-splash-screen__spinner">
|
||||
<a-spin :indicator="indicator" size="small" />
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<div
|
||||
v-if="showSupportButton && !showSplash && route.name !== 'support'"
|
||||
v-if="showSupportButton && route.name !== 'support' && !hideAppChrome"
|
||||
id="support-button"
|
||||
ref="supportButtonEl"
|
||||
class="draggable-support-button"
|
||||
@@ -80,56 +55,74 @@
|
||||
<VersionUpdateModal />
|
||||
|
||||
<PwaInstallGuideModal
|
||||
v-if="!hideAppChrome"
|
||||
v-model:open="guideOpen"
|
||||
:platform="platform"
|
||||
@complete="completeGuide()"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="!hideAppChrome && !isDesktop"
|
||||
class="app-credit-footer app-credit-footer--mobile"
|
||||
:class="{ 'app-credit-footer--login': isLoginRoute }"
|
||||
>
|
||||
<EnamadBadge v-if="isLoginRoute" size="sm" />
|
||||
<AppCreditLink variant="mobile" />
|
||||
</div>
|
||||
<div
|
||||
v-if="!hideAppChrome && showDesktopFloatingCredit"
|
||||
class="app-credit-footer app-credit-footer--desktop-float"
|
||||
:class="{ 'app-credit-footer--login': isLoginRoute }"
|
||||
>
|
||||
<EnamadBadge v-if="isLoginRoute" size="sm" />
|
||||
<AppCreditLink variant="float" />
|
||||
</div>
|
||||
|
||||
<GoldDayCalculatorModal />
|
||||
<GoldLoading v-model:show="colleagueOrderWaiting" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { colors } from './themeConfig'
|
||||
import pkg from '../package.json'
|
||||
import { getDisplayAppVersion } from '@/config/config-cache'
|
||||
import { computed, defineAsyncComponent, h, onMounted, ref, watch } from 'vue'
|
||||
import { computed, defineAsyncComponent, onMounted, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { showBrowserNotification } from '@/utils/browserNotification'
|
||||
import img_topGradiant from '@/views/login/assets/img/gr_top_white.svg'
|
||||
import img_pattern from '@/views/login/assets/img/pattern.svg'
|
||||
import { LoadingOutlined } from '@ant-design/icons-vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { useSupportMessenger } from '@/composables/useSupportMessenger'
|
||||
import { loadSupportMessengerFromSettings } from '@/utils/supportMessenger'
|
||||
import SupportMessengerPicker from '@/components/SupportMessengerPicker.vue'
|
||||
import { useDraggableFloatingButton } from '@/utils/useDraggableFloatingButton'
|
||||
import { useApplyDesktopLayoutClass } from '@/layouts/composables/useAppLayout'
|
||||
import { useApplyDesktopLayoutClass, useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
||||
import AppCreditLink from '@/components/AppCreditLink.vue'
|
||||
import EnamadBadge from '@/components/EnamadBadge.vue'
|
||||
import { usePwaInstall } from '@/composables/usePwaInstall'
|
||||
import PwaInstallGuideModal from '@/components/pwa/PwaInstallGuideModal.vue'
|
||||
import GoldDayCalculatorModal from '@/components/GoldDayCalculatorModal.vue'
|
||||
import GoldLoading from '@/components/GoldLoading.vue'
|
||||
import { colleagueOrderWaiting, resumeColleagueOrderIfPending } from '@/composables/useColleagueOrderWait'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { connectChatIfExists, disconnectChat, isSettingFlagOn, unreadSupportCount, useChatService } from '@/utils/chat'
|
||||
import { getToken } from '@/utils'
|
||||
|
||||
import img_bottomGradiant from '@/views/login/assets/img/gr_bottom_white.svg'
|
||||
import logoFull from '@/assets/img/logo_full_.png'
|
||||
|
||||
const VersionUpdateModal = defineAsyncComponent(
|
||||
() => import('@/modules/version/VersionUpdateModal.vue')
|
||||
)
|
||||
|
||||
const indicator = h(LoadingOutlined, {
|
||||
style: {
|
||||
fontSize: '24px'
|
||||
},
|
||||
spin: true
|
||||
})
|
||||
const displayVersion = getDisplayAppVersion(pkg.version)
|
||||
const showSplash = ref(true)
|
||||
const route = useRoute()
|
||||
const hideAppChrome = computed(() => route.meta.hideChrome === true || route.name === 'tvMonitor')
|
||||
|
||||
useApplyDesktopLayoutClass()
|
||||
|
||||
const isDesktop = useDesktopBreakpoint()
|
||||
const showDesktopFloatingCredit = computed(() => {
|
||||
if (!isDesktop.value) return false
|
||||
return route.name === 'login' || !!route.meta.hideMenu
|
||||
})
|
||||
const isLoginRoute = computed(() => route.name === 'login')
|
||||
|
||||
const {
|
||||
guideOpen,
|
||||
platform,
|
||||
@@ -185,9 +178,6 @@ function handleSupportPointerUp(event: PointerEvent) {
|
||||
|
||||
onMounted(async () => {
|
||||
await loadSupportMessengerFromSettings()
|
||||
setTimeout(() => {
|
||||
showSplash.value = false
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
const userStore = useUserStore()
|
||||
@@ -228,6 +218,14 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(
|
||||
() => getToken(),
|
||||
(token) => {
|
||||
if (token) void resumeColleagueOrderIfPending()
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
watch(latestIncomingNotification, (payload) => {
|
||||
if (!payload) return
|
||||
if (payload.at === lastSupportToastAt) return
|
||||
@@ -252,6 +250,122 @@ watch(latestIncomingNotification, (payload) => {
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.app-credit-footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 1000000;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
.app-credit-footer--mobile {
|
||||
width: 100%;
|
||||
max-width: 426px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
min-height: var(--app-credit-bar-inner);
|
||||
padding: 4px 0 var(--app-safe-bottom);
|
||||
background: #fff;
|
||||
box-shadow: 0 -2px 4px -2px #0000001a;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
.app-credit-footer--login.app-credit-footer--mobile {
|
||||
min-height: 72px;
|
||||
}
|
||||
|
||||
:root:has(.app-credit-footer--login) {
|
||||
--app-credit-bar-inner: 72px;
|
||||
}
|
||||
|
||||
.app-credit-footer--desktop-float {
|
||||
left: auto;
|
||||
right: 20px;
|
||||
bottom: 16px;
|
||||
width: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.app-credit-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
&__text {
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__logo {
|
||||
width: auto;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
&--mobile {
|
||||
gap: 4px;
|
||||
padding: 4px 0;
|
||||
color: inherit;
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
&--sidebar {
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 4px;
|
||||
color: #9ca3af;
|
||||
font-size: 10px;
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 15px;
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
&--float {
|
||||
gap: 6px;
|
||||
padding: 7px 14px;
|
||||
font-size: 10px;
|
||||
color: #6b7280;
|
||||
background: #fff;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(15, 23, 42, 0.08);
|
||||
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
&--tv {
|
||||
gap: 8px;
|
||||
padding: 6px 0;
|
||||
font-size: 12px;
|
||||
color: #6b7280;
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.updateButton .van-dialog__confirm .van-button__text {
|
||||
color: @primary-color !important;
|
||||
font-weight: 600;
|
||||
@@ -328,12 +442,4 @@ watch(latestIncomingNotification, (payload) => {
|
||||
transform: scale(0.94);
|
||||
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
|
||||
}
|
||||
|
||||
/* در دسکتاپ، دکمه پشتیبانی کنار سایدبار و پایین صفحه قرار میگیرد (مانند khaneghi_user) */
|
||||
html.app-layout--desktop {
|
||||
#support-button {
|
||||
bottom: 12px;
|
||||
right: calc(var(--app-desktop-sidebar-width, 260px) + 20px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import useAxios from "@/utils/useAxios";
|
||||
import type {PInventory, Product} from "@/models/products";
|
||||
import type {PWallet, Wallet} from '@/models/wallet'
|
||||
import type {Order} from "@/models/order";
|
||||
import {useUserStore} from "@/store/userStore";
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
export const checkoutCart = async (orders: Order[]): Promise<any> => {
|
||||
return await useAxios.post<Order[]>(`/customer/cart/checkout`, orders)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,23 @@ import type {Ref, UnwrapRef} from "vue";
|
||||
import type {Transaction} from "@/models/transaction";
|
||||
import {useUserStore} from "@/store/userStore";
|
||||
|
||||
const userStore = useUserStore()
|
||||
function customerOrderPrefix() {
|
||||
// lazy: این ماژول ممکن است قبل از app.use(pinia) لود شود
|
||||
return `/customer${!useUserStore().isSingle ? '' : '/single'}`
|
||||
}
|
||||
|
||||
export const createOrder = async (obj: Order): Promise<any> => {
|
||||
return await useAxios.post<Order>(`/customer${!userStore.isSingle ? '' : '/single'}/order`, obj)
|
||||
return await useAxios.post<Order>(`${customerOrderPrefix()}/order`, obj)
|
||||
}
|
||||
|
||||
export const getPendingColleagueOrder = async (): Promise<any> => {
|
||||
return await useAxios.get(`${customerOrderPrefix()}/order/pending`)
|
||||
}
|
||||
|
||||
export const getColleagueOrderStatus = async (id: number): Promise<any> => {
|
||||
return await useAxios.get(`${customerOrderPrefix()}/order/${id}/status`)
|
||||
}
|
||||
|
||||
export const getOrders = async (tbl: Ref<UnwrapRef<TableInput>>): Promise<TableOutput<Transaction>> => {
|
||||
return await useAxios.post<TableOutput<Order>>(`/customer${!userStore.isSingle ? '' : '/single'}/order/table`, tbl)
|
||||
return await useAxios.post<TableOutput<Order>>(`${customerOrderPrefix()}/order/table`, tbl)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,39 @@
|
||||
import useAxios from "@/utils/useAxios";
|
||||
import type {PInventory, Product} from "@/models/products";
|
||||
import type { PWallet, Wallet } from '@/models/wallet'
|
||||
import { priceStreamList } from "@/utils/priceSocketState";
|
||||
|
||||
|
||||
export const getProducts = async (): Promise<any> => {
|
||||
return await useAxios.get<Product[]>(`/customer/product/list`, { timeout: 15000 })
|
||||
export const getProducts = async (force = false): Promise<Product[]> => {
|
||||
if (!force && Array.isArray(priceStreamList.value) && priceStreamList.value.length > 0) {
|
||||
return priceStreamList.value as unknown as Product[]
|
||||
}
|
||||
const response = await useAxios.get<Product[]>(`/customer/product/list`, { timeout: 15000 })
|
||||
return Array.isArray(response) ? response : []
|
||||
}
|
||||
export const getTvProducts = async (): Promise<Product[]> => {
|
||||
const response = await useAxios.get<unknown>(`/customer/tv/products`, { timeout: 15000 })
|
||||
return Array.isArray(response) ? (response as Product[]) : []
|
||||
}
|
||||
|
||||
export type TvServerTime = {
|
||||
unix: number
|
||||
iso: string
|
||||
timezone: string
|
||||
stream_key?: string
|
||||
}
|
||||
|
||||
export const getTvServerTime = async (): Promise<TvServerTime | null> => {
|
||||
try {
|
||||
const response = await useAxios.get<TvServerTime>(`/customer/tv/time`, { timeout: 10000 })
|
||||
if (response && typeof (response as TvServerTime).unix === 'number') {
|
||||
return response as TvServerTime
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export const getProductById = async ( id:number|null): Promise<any> => {
|
||||
return await useAxios.get<Product[]>(`/customer/product/list/${id}`, { timeout: 15000 })
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
import {
|
||||
fetchSuperAdminJson,
|
||||
resolveTenantDomain,
|
||||
SA_PROGRAM_SETTINGS_PATH,
|
||||
} from '@/config/superadmin'
|
||||
|
||||
export type SuperAdminSettingRow = {
|
||||
id?: number
|
||||
key?: string
|
||||
value?: string | number
|
||||
title_fa?: string
|
||||
description?: string
|
||||
is_active?: boolean | number | string
|
||||
type?: string
|
||||
can_edit?: number | boolean | string
|
||||
}
|
||||
|
||||
function parseSettingsPayload(data: unknown): SuperAdminSettingRow[] {
|
||||
if (Array.isArray(data)) return data as SuperAdminSettingRow[]
|
||||
if (data && typeof data === 'object') {
|
||||
const obj = data as Record<string, unknown>
|
||||
if (Array.isArray(obj.settings)) return obj.settings as SuperAdminSettingRow[]
|
||||
if (Array.isArray(obj.items)) return obj.items as SuperAdminSettingRow[]
|
||||
if (Array.isArray(obj.data)) return obj.data as SuperAdminSettingRow[]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/** کلید قفلشده در get_settings محلی — باید از سوپرادمین بیاید */
|
||||
export function isLockedCanEdit(canEdit: unknown): boolean {
|
||||
return canEdit === 0 || canEdit === false || canEdit === '0'
|
||||
}
|
||||
|
||||
/** تنظیمات پیشرفته نسخه از سوپرادمین — فقط GET /api/public/program-settings?domain= */
|
||||
export async function fetchSuperAdminProgramSettings(): Promise<SuperAdminSettingRow[]> {
|
||||
const domain = encodeURIComponent(resolveTenantDomain())
|
||||
const data = await fetchSuperAdminJson(
|
||||
(base) => `${base}${SA_PROGRAM_SETTINGS_PATH}?domain=${domain}`,
|
||||
)
|
||||
return parseSettingsPayload(data)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { setupRouterGuards } from '@/app/setupRouter'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { initPriceRealtimeChannel } from '@/utils/priceSocket'
|
||||
import { initMobileScrollRestoration } from '@/layouts/composables/useMobileScrollReset'
|
||||
import { initMobileInputKeyboardScroll } from '@/utils/mobileInputKeyboardScroll'
|
||||
|
||||
type BootWindow = Window & {
|
||||
__BOOT_TIMEOUT__?: number
|
||||
@@ -76,6 +77,7 @@ export async function bootstrapApp() {
|
||||
initPriceRealtimeChannel((key) => settingsStore.getSettingByKey(key))
|
||||
|
||||
initMobileScrollRestoration()
|
||||
initMobileInputKeyboardScroll()
|
||||
setupRouterGuards()
|
||||
|
||||
app.mount('#app')
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import VueLazyLoad from 'vue3-lazyload'
|
||||
import VueApexCharts from 'vue3-apexcharts'
|
||||
import App from '@/App.vue'
|
||||
import router from '@/router'
|
||||
|
||||
export function createVueApp() {
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(pinia)
|
||||
app.use(VueLazyLoad, {})
|
||||
app.use(router)
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
setFingerTimeOut,
|
||||
setHasFingerPrint
|
||||
} from '@/app/authBoot'
|
||||
import { recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
||||
import { clearVantOverlays, recoverMobileViewportAfterAuth } from '@/layouts/composables/useMobileScrollReset'
|
||||
|
||||
export function setupRouterGuards() {
|
||||
const userStore = useUserStore()
|
||||
@@ -33,8 +33,17 @@ export function setupRouterGuards() {
|
||||
}
|
||||
}
|
||||
|
||||
function isGuestAllowed(to: RouteLocationNormalized) {
|
||||
if (to.meta?.public) {
|
||||
return true
|
||||
}
|
||||
return ['login', '404', 'buyProduct', 'productDetail', 'about', 'aboutSoftware', 'cart', 'tvMonitor'].includes(
|
||||
to.name as string,
|
||||
)
|
||||
}
|
||||
|
||||
function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) {
|
||||
if (to.name === 'buyProduct' || to.name === 'productDetail' || to.name === 'about' || to.name === 'cart' || to.name === 'tv') {
|
||||
if (isGuestAllowed(to)) {
|
||||
return next()
|
||||
}
|
||||
if (to.name !== 'login') {
|
||||
@@ -53,7 +62,9 @@ export function setupRouterGuards() {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
authStore.setLoading(true)
|
||||
clearFingerTimeout()
|
||||
setFingerTimeOut(to)
|
||||
if (to.name !== 'tvMonitor' && !to.meta?.hideChrome) {
|
||||
setFingerTimeOut(to)
|
||||
}
|
||||
|
||||
if (to.name === 'notifyTrigger' && getToken()) {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
@@ -88,6 +99,34 @@ export function setupRouterGuards() {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
getToken() &&
|
||||
(to.name === 'piggy' ||
|
||||
to.name === 'fund' ||
|
||||
to.name === 'fund_info' ||
|
||||
to.name === 'fund_add')
|
||||
) {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const settingsStore = useSettingsStore()
|
||||
if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
if (!settingsStore.isSettingTruthy('enable_product_funds')) {
|
||||
return next({ name: (from.name as string) || 'home' })
|
||||
}
|
||||
}
|
||||
|
||||
if (to.name === 'earnMoney' && getToken()) {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const settingsStore = useSettingsStore()
|
||||
if (!settingsStore.loaded) {
|
||||
await settingsStore.fetchSettings()
|
||||
}
|
||||
if (!settingsStore.isSettingTruthy('has_page_earn_money')) {
|
||||
return next({ name: (from.name as string) || 'user' })
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
isFirst = false
|
||||
|
||||
@@ -112,7 +151,7 @@ export function setupRouterGuards() {
|
||||
return next()
|
||||
}
|
||||
} else {
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart', 'tv'].includes(to.name as string)) {
|
||||
if (isGuestAllowed(to)) {
|
||||
return next()
|
||||
}
|
||||
goToLogin(to, next)
|
||||
@@ -126,7 +165,7 @@ export function setupRouterGuards() {
|
||||
return next()
|
||||
}
|
||||
|
||||
if (['login', '404', 'buyProduct', 'productDetail', 'about', 'cart', 'tv'].includes(to.name as string)) {
|
||||
if (isGuestAllowed(to)) {
|
||||
return next()
|
||||
}
|
||||
return next({ name: 'login' })
|
||||
@@ -141,6 +180,9 @@ export function setupRouterGuards() {
|
||||
})
|
||||
|
||||
router.afterEach((to, from) => {
|
||||
if (to.name === 'login') {
|
||||
clearVantOverlays()
|
||||
}
|
||||
if (document.documentElement.classList.contains('app-layout--desktop')) return
|
||||
if (from.name === 'login') {
|
||||
recoverMobileViewportAfterAuth()
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
@import (less) '../../views/base/gold/desktop/styles/desktop-gold.less';
|
||||
@import (less) '../../views/login/desktop/styles/desktop-login.less';
|
||||
@import (less) '../../layouts/desktop/styles/desktop-inner-pages.less';
|
||||
@import (less) './mobile-keyboard-scroll.less';
|
||||
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
@@ -65,11 +66,11 @@ body {
|
||||
color-scheme: only light;
|
||||
--app-safe-top: env(safe-area-inset-top, 0px);
|
||||
--app-safe-bottom: env(safe-area-inset-bottom, 0px);
|
||||
--app-credit-bar-inner: 0px;
|
||||
--app-credit-bar-inner: 28px;
|
||||
--app-home-header-offset: calc(4.25rem + var(--app-safe-top));
|
||||
--app-credit-footer-offset: var(--app-safe-bottom);
|
||||
--app-credit-footer-offset: calc(var(--app-credit-bar-inner) + var(--app-safe-bottom));
|
||||
--app-nav-height: 80px;
|
||||
--app-bottom-chrome-height: calc(var(--app-nav-height) + var(--app-safe-bottom));
|
||||
--app-bottom-chrome-height: calc(var(--app-nav-height) + var(--app-credit-footer-offset));
|
||||
--app-add-card-height: 88px;
|
||||
--wallet-card-dock-overlap: 52px;
|
||||
--app-z-nav: 5000;
|
||||
@@ -92,6 +93,13 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 500px) {
|
||||
.login-vip-page__body{
|
||||
height: 20vh !important;
|
||||
overflow: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s ease;
|
||||
@@ -106,9 +114,24 @@ body {
|
||||
z-index: 5001 !important;
|
||||
}
|
||||
|
||||
//.van-overlay{
|
||||
// z-index: 2000 !important;
|
||||
//}
|
||||
.van-overlay{
|
||||
z-index: 5000 !important;
|
||||
background: rgba(0, 0, 0, 0.55) !important;
|
||||
pointer-events: auto !important;
|
||||
}
|
||||
|
||||
.van-dialog {
|
||||
z-index: var(--app-z-dialog, 5300) !important;
|
||||
}
|
||||
|
||||
body.van-overflow-hidden {
|
||||
.bottom-appbar,
|
||||
.app-credit-footer,
|
||||
#support-button {
|
||||
visibility: hidden !important;
|
||||
pointer-events: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.color-transition {
|
||||
transition: color 0.3s ease;
|
||||
@@ -160,10 +183,16 @@ body {
|
||||
border: 1px solid #d1d5db;
|
||||
border-radius: 4px;
|
||||
background-color: white;
|
||||
color: #111827;
|
||||
caret-color: #111827;
|
||||
-webkit-text-fill-color: #111827;
|
||||
color-scheme: light;
|
||||
//@apply bg-gray-50;
|
||||
|
||||
&:focus-visible {
|
||||
background-color: #fff;
|
||||
color: #111827;
|
||||
-webkit-text-fill-color: #111827;
|
||||
//display: none;
|
||||
outline: none;
|
||||
border: 1px solid #a72b77 !important;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
:root {
|
||||
--app-keyboard-inset: 0px;
|
||||
--app-visual-viewport-height: 100dvh;
|
||||
--app-visual-viewport-offset-top: 0px;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 767.98px) {
|
||||
input,
|
||||
textarea,
|
||||
select,
|
||||
.ant-input,
|
||||
.ant-input-affix-wrapper,
|
||||
.ant-select-selection-search-input {
|
||||
scroll-margin-bottom: calc(var(--app-keyboard-inset) + 16px);
|
||||
}
|
||||
|
||||
html[data-keyboard-open='true'] {
|
||||
.main-with-bottom-chrome,
|
||||
.login-vip-page__body,
|
||||
.login-page,
|
||||
.login-page-root,
|
||||
.ant-modal-body,
|
||||
.ant-drawer-body,
|
||||
.van-action-sheet__content,
|
||||
.basic-action-sheet__body {
|
||||
scroll-padding-bottom: calc(var(--app-keyboard-inset) + 16px);
|
||||
}
|
||||
|
||||
.main-with-bottom-chrome,
|
||||
.login-vip-page__body,
|
||||
.login-page {
|
||||
padding-bottom: var(--app-keyboard-inset);
|
||||
}
|
||||
|
||||
.login-mobile {
|
||||
height: var(--app-visual-viewport-height, 100dvh);
|
||||
max-height: var(--app-visual-viewport-height, 100dvh);
|
||||
}
|
||||
|
||||
.login-page.flex {
|
||||
height: var(--app-visual-viewport-height, 92vh) !important;
|
||||
max-height: var(--app-visual-viewport-height, 92vh) !important;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
align-items: flex-start !important;
|
||||
justify-content: flex-start !important;
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,98 @@
|
||||
<template>
|
||||
<a
|
||||
href="https://montzar.ir"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="app-credit-link"
|
||||
:class="`app-credit-link--${variant}`"
|
||||
>
|
||||
<span class="app-credit-link__text">توسعه و طراحی توسط</span>
|
||||
<img :src="logoMontzarUrl" alt="montzar" class="app-credit-link__logo" />
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import logoMontzarUrl from '@/assets/img/logo-montzar.png'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
variant?: 'mobile' | 'sidebar' | 'float' | 'tv'
|
||||
}>(),
|
||||
{ variant: 'mobile' },
|
||||
)
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.app-credit-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
&__text {
|
||||
font-weight: 500;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__logo {
|
||||
width: auto;
|
||||
max-width: 140px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
&--mobile {
|
||||
gap: 4px;
|
||||
padding: 4px 0;
|
||||
color: inherit;
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
&--sidebar {
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
padding: 4px;
|
||||
color: #9ca3af;
|
||||
font-size: 10px;
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 15px;
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
&--float {
|
||||
gap: 6px;
|
||||
padding: 7px 14px;
|
||||
font-size: 10px;
|
||||
color: #6b7280;
|
||||
background: #fff;
|
||||
border-radius: 999px;
|
||||
border: 1px solid rgba(15, 23, 42, 0.08);
|
||||
box-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
&--tv {
|
||||
gap: 8px;
|
||||
padding: 6px 0;
|
||||
font-size: 12px;
|
||||
color: #6b7280;
|
||||
|
||||
.app-credit-link__logo {
|
||||
height: 16px;
|
||||
max-width: 120px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
</style>-->
|
||||
<template>
|
||||
<VanActionSheet :show="show" @update:show="$emit('update:show', $event)" :placement="placement" teleport="body">
|
||||
<VanActionSheet :show="show" overlay lock-scroll close-on-click-overlay teleport="body" :placement="placement" @update:show="$emit('update:show', $event)">
|
||||
<div class="justify-center cursor-pointer flex mt-1" @click="$emit('update:show', false)">
|
||||
<span class="rounded-sm w-12 border-t-2 border-t-solid border-t-gray-500 mt-2"></span>
|
||||
</div>
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
class=""
|
||||
@change="handlerChange"
|
||||
@input="handlerChange"
|
||||
@blur="emits('blur', $event)"
|
||||
@focus="emits('focus', $event)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -42,7 +44,6 @@ import {
|
||||
normalizeDecimalInput,
|
||||
persianToEnglishDigits,
|
||||
shouldNormalizeDecimalSeparators,
|
||||
shouldNormalizeInputDigits,
|
||||
} from '@/utils/persianDigits';
|
||||
|
||||
//Props
|
||||
@@ -68,7 +69,7 @@ const addonTextColor = computed(() => props.addonTextColor)
|
||||
const props = withDefaults(defineProps<Prop>(), {
|
||||
isPassword: false
|
||||
})
|
||||
const emits = defineEmits(['update:value', 'onchange'])
|
||||
const emits = defineEmits(['update:value', 'onchange', 'blur', 'focus'])
|
||||
|
||||
const localValue = computed({
|
||||
set(value) {
|
||||
@@ -93,11 +94,7 @@ function normalizeValue(value: unknown) {
|
||||
})
|
||||
}
|
||||
|
||||
let normalized = String(value)
|
||||
if (shouldNormalizeInputDigits(props)) {
|
||||
normalized = persianToEnglishDigits(normalized)
|
||||
}
|
||||
return normalized
|
||||
return persianToEnglishDigits(String(value))
|
||||
}
|
||||
|
||||
const handlerChange = (e: Event | string) => {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div>
|
||||
<a-modal
|
||||
v-model:visible="localValue"
|
||||
:title="props.title"
|
||||
:title="slots.title ? undefined : props.title"
|
||||
centered
|
||||
@ok="emits('ok')"
|
||||
@cancel="emits('close')"
|
||||
@@ -11,9 +11,13 @@
|
||||
:width="props.width"
|
||||
:ok-text="props.okText"
|
||||
:cancel-text="props.cancelText"
|
||||
:confirm-loading="props.loading"
|
||||
:closable="props.closable"
|
||||
:wrapClassName="props.wrapClassName"
|
||||
>
|
||||
<template v-if="slots.title" #title>
|
||||
<slot name="title" />
|
||||
</template>
|
||||
<template v-if="props.customFooter" #footer> <slot name="footer" /></template>
|
||||
<a-spin :spinning="props.loading">
|
||||
<div class="overflow-y-auto py-2 px-1 relative max-h-[83vh]" id="body">
|
||||
@@ -25,8 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
//define emit
|
||||
import { computed } from 'vue'
|
||||
import { computed, useSlots } from 'vue'
|
||||
|
||||
const emits = defineEmits(['ok', 'close', 'update:visible'])
|
||||
|
||||
@@ -53,6 +56,8 @@ const props = withDefaults(defineProps<Prop>(), {
|
||||
closable: true
|
||||
})
|
||||
|
||||
const slots = useSlots()
|
||||
|
||||
const localValue = computed({
|
||||
get() {
|
||||
return props.visible
|
||||
|
||||
@@ -0,0 +1,861 @@
|
||||
<template>
|
||||
<div
|
||||
ref="containerRef"
|
||||
class="product-picker-root"
|
||||
:class="{
|
||||
'product-picker-root--compact': compact,
|
||||
'product-picker-root--open': isOpen,
|
||||
}"
|
||||
>
|
||||
<label v-if="label" class="product-picker__label">{{ label }}</label>
|
||||
|
||||
<!-- سلکتور جمعوجور -->
|
||||
<div
|
||||
class="product-picker__control"
|
||||
:class="{
|
||||
'product-picker__control--clickable': !disabled && !isEdit,
|
||||
'product-picker__control--disabled': disabled,
|
||||
'product-picker__control--locked': isEdit,
|
||||
'product-picker__control--active': isOpen,
|
||||
}"
|
||||
role="button"
|
||||
:tabindex="disabled ? -1 : 0"
|
||||
:aria-label="label || placeholder"
|
||||
@click="toggleOpen"
|
||||
@keydown.enter.prevent="toggleOpen"
|
||||
>
|
||||
<div class="product-picker__value">
|
||||
<span class="product-picker__icon" aria-hidden="true">
|
||||
<BasicIcon
|
||||
:icon="isEdit ? 'vuesax-linear:lock' : 'vuesax-linear:box-1'"
|
||||
:size="compact ? 16 : 18"
|
||||
:color="selectedItem ? 'var(--App-secondary-color, #e0be7f)' : 'var(--app-text-soft, #9ca3af)'"
|
||||
/>
|
||||
</span>
|
||||
<span
|
||||
class="product-picker__text"
|
||||
:class="{ 'product-picker__text--placeholder': !selectedItem && !lockedTitle }"
|
||||
>
|
||||
{{ displayTitle }}
|
||||
</span>
|
||||
<span v-if="displayUnit" class="product-picker__unit">({{ displayUnit }})</span>
|
||||
<span v-if="displaySubtitle" class="product-picker__subtitle">{{ displaySubtitle }}</span>
|
||||
</div>
|
||||
|
||||
<div class="product-picker__trailing">
|
||||
<button
|
||||
v-if="allowClear && selectedItem && !disabled && !isEdit"
|
||||
type="button"
|
||||
class="product-picker__clear-btn"
|
||||
aria-label="پاک کردن"
|
||||
@click.stop="handleClear"
|
||||
>
|
||||
<BasicIcon icon="vuesax-linear:close-circle" size="16" color="var(--app-text-soft, #9ca3af)" />
|
||||
</button>
|
||||
<span class="product-picker__arrow" aria-hidden="true">
|
||||
<BasicIcon
|
||||
v-if="!isEdit"
|
||||
:icon="isOpen ? 'vuesax-linear:arrow-up-1' : 'vuesax-linear:arrow-down-1'"
|
||||
size="16"
|
||||
color="var(--app-text-soft, #9ca3af)"
|
||||
/>
|
||||
<BasicIcon v-else icon="vuesax-linear:lock" size="14" color="var(--app-text-soft, #9ca3af)" />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- دراپداون دسکتاپ -->
|
||||
<div
|
||||
v-if="isDesktop && isOpen && !disabled && !isEdit"
|
||||
class="product-picker__dropdown"
|
||||
:style="dropdownStyle"
|
||||
>
|
||||
<div class="product-picker__search">
|
||||
<span class="product-picker__search-icon" aria-hidden="true">
|
||||
<BasicIcon icon="vuesax-linear:search-normal" size="16" color="var(--app-text-soft, #9ca3af)" />
|
||||
</span>
|
||||
<input
|
||||
ref="desktopSearchInputRef"
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
class="product-picker__search-input"
|
||||
placeholder="جستجوی محصول..."
|
||||
autocomplete="off"
|
||||
/>
|
||||
<button
|
||||
v-if="searchQuery"
|
||||
type="button"
|
||||
class="product-picker__clear-query-btn"
|
||||
aria-label="پاک کردن جستجو"
|
||||
@click="searchQuery = ''"
|
||||
>
|
||||
<BasicIcon icon="vuesax-linear:close-circle" size="15" color="var(--app-text-soft, #9ca3af)" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="product-picker__list" role="listbox">
|
||||
<button
|
||||
v-for="p in filteredList"
|
||||
:key="getItemKey(p)"
|
||||
type="button"
|
||||
role="option"
|
||||
class="product-picker__item"
|
||||
:class="{ 'product-picker__item--selected': isSelected(p) }"
|
||||
:aria-selected="isSelected(p)"
|
||||
@click="selectItem(p)"
|
||||
>
|
||||
<div class="product-picker__item-info">
|
||||
<span class="product-picker__item-icon">
|
||||
<BasicIcon
|
||||
icon="vuesax-linear:box-1"
|
||||
size="16"
|
||||
:color="isSelected(p) ? 'var(--App-secondary-color, #e0be7f)' : 'inherit'"
|
||||
/>
|
||||
</span>
|
||||
<span class="product-picker__item-title">{{ getItemTitle(p) }}</span>
|
||||
<span v-if="getItemUnit(p)" class="product-picker__item-unit">({{ getItemUnit(p) }})</span>
|
||||
<span v-if="getItemSubtitle(p)" class="product-picker__item-subtitle">{{ getItemSubtitle(p) }}</span>
|
||||
</div>
|
||||
|
||||
<span v-if="isSelected(p)" class="product-picker__item-check">
|
||||
<BasicIcon icon="vuesax-linear:tick-circle" size="18" color="var(--App-secondary-color, #e0be7f)" />
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div v-if="loading" class="product-picker__loading">
|
||||
<BasicIcon icon="vuesax-linear:box-time" size="20" class="animate-spin" color="var(--App-secondary-color, #e0be7f)" />
|
||||
<span>در حال دریافت محصولات...</span>
|
||||
</div>
|
||||
<div v-else-if="filteredList.length === 0" class="product-picker__empty">
|
||||
<BasicIcon icon="vuesax-linear:info-circle" size="20" color="var(--app-text-soft, #9ca3af)" />
|
||||
<span>{{ emptyText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- اکشنشیت موبایل -->
|
||||
<BasicActionSheet
|
||||
v-if="!isDesktop"
|
||||
v-model:show="isSheetOpen"
|
||||
:title="sheetTitle"
|
||||
:closable="true"
|
||||
@closed="onSheetClosed"
|
||||
>
|
||||
<div class="product-picker-sheet">
|
||||
<div class="product-picker-sheet__search">
|
||||
<span class="product-picker-sheet__search-icon" aria-hidden="true">
|
||||
<BasicIcon icon="vuesax-linear:search-normal" size="18" color="var(--app-text-soft, #9ca3af)" />
|
||||
</span>
|
||||
<input
|
||||
ref="mobileSearchInputRef"
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
class="product-picker-sheet__search-input"
|
||||
placeholder="جستجوی نام یا کد محصول..."
|
||||
autocomplete="off"
|
||||
/>
|
||||
<button
|
||||
v-if="searchQuery"
|
||||
type="button"
|
||||
class="product-picker-sheet__clear-btn"
|
||||
aria-label="پاک کردن جستجو"
|
||||
@click="searchQuery = ''"
|
||||
>
|
||||
<BasicIcon icon="vuesax-linear:close-circle" size="18" color="var(--app-text-soft, #9ca3af)" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="product-picker-sheet__list" role="listbox">
|
||||
<button
|
||||
v-for="p in filteredList"
|
||||
:key="getItemKey(p)"
|
||||
type="button"
|
||||
role="option"
|
||||
class="product-picker-sheet__item"
|
||||
:class="{ 'product-picker-sheet__item--selected': isSelected(p) }"
|
||||
:aria-selected="isSelected(p)"
|
||||
@click="selectItem(p)"
|
||||
>
|
||||
<div class="product-picker-sheet__item-info">
|
||||
<span class="product-picker-sheet__item-icon">
|
||||
<BasicIcon
|
||||
icon="vuesax-linear:box-1"
|
||||
size="18"
|
||||
:color="isSelected(p) ? 'var(--App-secondary-color, #e0be7f)' : 'inherit'"
|
||||
/>
|
||||
</span>
|
||||
<div class="product-picker-sheet__item-texts">
|
||||
<span class="product-picker-sheet__item-title">{{ getItemTitle(p) }}</span>
|
||||
<span
|
||||
v-if="getItemSubtitle(p) || getItemUnit(p)"
|
||||
class="product-picker-sheet__item-meta"
|
||||
>
|
||||
{{ getItemSubtitle(p) || `واحد: ${getItemUnit(p)}` }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span v-if="isSelected(p)" class="product-picker-sheet__item-check">
|
||||
<BasicIcon icon="vuesax-linear:tick-circle" size="20" color="var(--App-secondary-color, #e0be7f)" />
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div v-if="loading" class="product-picker-sheet__loading">
|
||||
<BasicIcon icon="vuesax-linear:box-time" size="26" class="animate-spin" color="var(--App-secondary-color, #e0be7f)" />
|
||||
<span class="mt-2 text-sm text-gray-400">در حال دریافت محصولات...</span>
|
||||
</div>
|
||||
<div v-else-if="filteredList.length === 0" class="product-picker-sheet__empty">
|
||||
<BasicIcon icon="vuesax-linear:info-circle" size="24" color="var(--app-text-soft, #9ca3af)" />
|
||||
<span>{{ emptyText }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</BasicActionSheet>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import BasicActionSheet from '@/components/BasicPacks/BasicActionSheet.vue'
|
||||
import { useDesktopBreakpoint } from '@/layouts/composables/useAppLayout'
|
||||
|
||||
interface Props {
|
||||
modelValue?: number | string | null
|
||||
value?: number | string | null
|
||||
items?: any[]
|
||||
products?: any[]
|
||||
keyName?: string
|
||||
valueName?: string
|
||||
unitName?: string
|
||||
subtitleName?: string
|
||||
placeholder?: string
|
||||
sheetTitle?: string
|
||||
label?: string
|
||||
disabled?: boolean
|
||||
loading?: boolean
|
||||
isEdit?: boolean
|
||||
lockedTitle?: string
|
||||
allowClear?: boolean
|
||||
compact?: boolean
|
||||
emptyText?: string
|
||||
dropdownStyle?: Record<string, any>
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: undefined,
|
||||
value: undefined,
|
||||
items: undefined,
|
||||
products: undefined,
|
||||
keyName: 'id',
|
||||
valueName: 'title',
|
||||
unitName: 'unit',
|
||||
subtitleName: 'subtitle',
|
||||
placeholder: 'انتخاب محصول...',
|
||||
sheetTitle: 'انتخاب محصول',
|
||||
label: '',
|
||||
disabled: false,
|
||||
loading: false,
|
||||
isEdit: false,
|
||||
lockedTitle: '',
|
||||
allowClear: false,
|
||||
compact: false,
|
||||
emptyText: 'محصولی یافت نشد',
|
||||
dropdownStyle: undefined,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [val: any]
|
||||
'update:value': [val: any]
|
||||
'change': [item: any]
|
||||
'clear': []
|
||||
}>()
|
||||
|
||||
const isDesktop = useDesktopBreakpoint()
|
||||
const containerRef = ref<HTMLElement>()
|
||||
const desktopSearchInputRef = ref<HTMLInputElement>()
|
||||
const mobileSearchInputRef = ref<HTMLInputElement>()
|
||||
|
||||
const isOpen = ref(false)
|
||||
const isSheetOpen = ref(false)
|
||||
const searchQuery = ref('')
|
||||
|
||||
const effectiveList = computed(() => {
|
||||
if (Array.isArray(props.items)) return props.items
|
||||
if (Array.isArray(props.products)) return props.products
|
||||
return []
|
||||
})
|
||||
|
||||
const currentValue = computed(() => {
|
||||
if (props.modelValue !== undefined) return props.modelValue
|
||||
return props.value
|
||||
})
|
||||
|
||||
function getItemKey(item: any): any {
|
||||
if (!item) return ''
|
||||
return item[props.keyName] !== undefined ? item[props.keyName] : item.id
|
||||
}
|
||||
|
||||
function getItemTitle(item: any): string {
|
||||
if (!item) return ''
|
||||
return String(item[props.valueName] || item.title || item.name || `محصول ${getItemKey(item)}`)
|
||||
}
|
||||
|
||||
function getItemUnit(item: any): string {
|
||||
if (!item) return ''
|
||||
return item[props.unitName] || item.unit || ''
|
||||
}
|
||||
|
||||
function getItemSubtitle(item: any): string {
|
||||
if (!item) return ''
|
||||
return item[props.subtitleName] || item.subtitle || ''
|
||||
}
|
||||
|
||||
const selectedItem = computed(() => {
|
||||
const val = currentValue.value
|
||||
if (val === undefined || val === null || val === '') return null
|
||||
return effectiveList.value.find((p) => String(getItemKey(p)) === String(val)) ?? null
|
||||
})
|
||||
|
||||
const displayTitle = computed(() => {
|
||||
if (props.isEdit && props.lockedTitle) return props.lockedTitle
|
||||
if (selectedItem.value) return getItemTitle(selectedItem.value)
|
||||
const val = currentValue.value
|
||||
if (val !== undefined && val !== null && val !== '') return `محصول ${val}`
|
||||
return props.placeholder
|
||||
})
|
||||
|
||||
const displayUnit = computed(() => {
|
||||
if (props.isEdit) return ''
|
||||
return selectedItem.value ? getItemUnit(selectedItem.value) : ''
|
||||
})
|
||||
|
||||
const displaySubtitle = computed(() => {
|
||||
if (props.isEdit) return ''
|
||||
return selectedItem.value ? getItemSubtitle(selectedItem.value) : ''
|
||||
})
|
||||
|
||||
function isSelected(item: any): boolean {
|
||||
const val = currentValue.value
|
||||
if (val === undefined || val === null || val === '') return false
|
||||
return String(getItemKey(item)) === String(val)
|
||||
}
|
||||
|
||||
function normalizeText(text: string): string {
|
||||
return (text || '')
|
||||
.toLowerCase()
|
||||
.replace(/ي/g, 'ی')
|
||||
.replace(/ك/g, 'ک')
|
||||
.replace(/[\u200B-\u200D\uFEFF]/g, '')
|
||||
.trim()
|
||||
}
|
||||
|
||||
const filteredList = computed(() => {
|
||||
const q = normalizeText(searchQuery.value)
|
||||
if (!q) return effectiveList.value
|
||||
return effectiveList.value.filter((p) => {
|
||||
const title = normalizeText(getItemTitle(p))
|
||||
const unit = normalizeText(getItemUnit(p))
|
||||
const subtitle = normalizeText(getItemSubtitle(p))
|
||||
const key = String(getItemKey(p))
|
||||
return title.includes(q) || unit.includes(q) || subtitle.includes(q) || key.includes(q)
|
||||
})
|
||||
})
|
||||
|
||||
function toggleOpen() {
|
||||
if (props.disabled || props.isEdit) return
|
||||
if (isDesktop.value) {
|
||||
isOpen.value = !isOpen.value
|
||||
if (isOpen.value) {
|
||||
nextTick(() => {
|
||||
desktopSearchInputRef.value?.focus()
|
||||
})
|
||||
} else {
|
||||
searchQuery.value = ''
|
||||
}
|
||||
} else {
|
||||
isSheetOpen.value = true
|
||||
nextTick(() => {
|
||||
mobileSearchInputRef.value?.focus()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function selectItem(item: any) {
|
||||
const key = getItemKey(item)
|
||||
emit('update:modelValue', key)
|
||||
emit('update:value', key)
|
||||
emit('change', item)
|
||||
isOpen.value = false
|
||||
isSheetOpen.value = false
|
||||
searchQuery.value = ''
|
||||
}
|
||||
|
||||
function handleClear() {
|
||||
emit('update:modelValue', undefined)
|
||||
emit('update:value', undefined)
|
||||
emit('change', undefined)
|
||||
emit('clear')
|
||||
}
|
||||
|
||||
function onSheetClosed() {
|
||||
searchQuery.value = ''
|
||||
}
|
||||
|
||||
function handleClickOutside(e: MouseEvent) {
|
||||
if (containerRef.value && !containerRef.value.contains(e.target as Node)) {
|
||||
isOpen.value = false
|
||||
searchQuery.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('click', handleClickOutside)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('click', handleClickOutside)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.product-picker-root {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
width: 100%;
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
z-index: 1;
|
||||
|
||||
&--open {
|
||||
z-index: 50;
|
||||
}
|
||||
--picker-bg: var(--app-surface, var(--admin-bg-surface, #ffffff));
|
||||
--picker-border: var(--app-border, var(--admin-border, #e2e8f0));
|
||||
--picker-border-focus: var(--app-border-strong, var(--App-secondary-color, #e0be7f));
|
||||
--picker-text: var(--app-text-primary, var(--admin-text, #0f172a));
|
||||
--picker-text-soft: var(--app-text-muted, var(--admin-text-secondary, #64748b));
|
||||
--picker-inset: var(--app-surface-inset, rgba(15, 23, 42, 0.03));
|
||||
}
|
||||
|
||||
:global(html[data-theme='dark']) .product-picker-root,
|
||||
:global(html.dark) .product-picker-root {
|
||||
--picker-bg: var(--app-surface, #1e2026);
|
||||
--picker-border: var(--app-border, rgba(255, 255, 255, 0.12));
|
||||
--picker-border-focus: var(--app-border-strong, rgba(255, 255, 255, 0.28));
|
||||
--picker-text: var(--app-text-primary, #ffffff);
|
||||
--picker-text-soft: var(--app-text-muted, rgba(255, 255, 255, 0.55));
|
||||
--picker-inset: var(--app-surface-inset, rgba(255, 255, 255, 0.04));
|
||||
}
|
||||
|
||||
.product-picker__label {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 700;
|
||||
color: var(--picker-text);
|
||||
}
|
||||
|
||||
.product-picker__control {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 2.65rem;
|
||||
padding: 0 0.75rem;
|
||||
border-radius: 0.65rem;
|
||||
border: 1px solid var(--picker-border);
|
||||
background: var(--picker-bg);
|
||||
color: var(--picker-text);
|
||||
direction: rtl;
|
||||
transition: all 0.18s ease;
|
||||
user-select: none;
|
||||
|
||||
.product-picker-root--compact & {
|
||||
min-height: 2.35rem;
|
||||
padding: 0 0.6rem;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
&--clickable {
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
border-color: var(--picker-border-focus);
|
||||
}
|
||||
}
|
||||
|
||||
&--active {
|
||||
border-color: var(--picker-border-focus);
|
||||
box-shadow: 0 0 0 2px rgba(227, 176, 86, 0.15);
|
||||
}
|
||||
|
||||
&--disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
background: var(--picker-inset);
|
||||
}
|
||||
|
||||
&--locked {
|
||||
background: var(--picker-inset);
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker__value {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-picker__icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__text {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--picker-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
.product-picker-root--compact & {
|
||||
font-size: 0.8125rem;
|
||||
}
|
||||
|
||||
&--placeholder {
|
||||
color: var(--picker-text-soft);
|
||||
font-weight: 400;
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker__unit {
|
||||
font-size: 0.75rem;
|
||||
color: var(--picker-text-soft);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__subtitle {
|
||||
font-size: 0.72rem;
|
||||
color: var(--App-secondary-color, #e0be7f);
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__trailing {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__clear-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 2px;
|
||||
cursor: pointer;
|
||||
border-radius: 9999px;
|
||||
transition: opacity 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker__arrow {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* دراپداون دسکتاپ */
|
||||
.product-picker__dropdown {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 1050;
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.75rem;
|
||||
border: 1px solid var(--picker-border);
|
||||
background: var(--picker-bg);
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.product-picker__search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
height: 2.25rem;
|
||||
padding: 0 0.6rem;
|
||||
border-radius: 0.5rem;
|
||||
background: var(--picker-inset);
|
||||
border: 1px solid var(--picker-border);
|
||||
}
|
||||
|
||||
.product-picker__search-icon {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__search-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
color: var(--picker-text);
|
||||
font-size: 0.8125rem;
|
||||
text-align: right;
|
||||
direction: rtl;
|
||||
|
||||
&::placeholder {
|
||||
color: var(--picker-text-soft);
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker__clear-query-btn {
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.product-picker__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
max-height: 14rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.product-picker__item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
padding: 0.5rem 0.65rem;
|
||||
border-radius: 0.5rem;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
outline: none;
|
||||
text-align: right;
|
||||
|
||||
&:hover {
|
||||
background: var(--picker-inset);
|
||||
border-color: var(--picker-border);
|
||||
}
|
||||
|
||||
&--selected {
|
||||
background: rgba(224, 190, 127, 0.12);
|
||||
border-color: var(--App-secondary-color, #e0be7f);
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker__item-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.product-picker__item-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__item-title {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: var(--picker-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.product-picker__item-unit {
|
||||
font-size: 0.72rem;
|
||||
color: var(--picker-text-soft);
|
||||
}
|
||||
|
||||
.product-picker__item-subtitle {
|
||||
font-size: 0.72rem;
|
||||
color: var(--App-secondary-color, #e0be7f);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.product-picker__item-check {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker__empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.35rem;
|
||||
padding: 1.25rem 0.5rem;
|
||||
color: var(--picker-text-soft);
|
||||
font-size: 0.8125rem;
|
||||
}
|
||||
|
||||
/* شیت موبایل */
|
||||
.product-picker-sheet {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding-bottom: 1.5rem;
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.product-picker-sheet__search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
height: 2.75rem;
|
||||
padding: 0 0.85rem;
|
||||
border-radius: 0.75rem;
|
||||
background: var(--picker-inset);
|
||||
border: 1px solid var(--picker-border);
|
||||
}
|
||||
|
||||
.product-picker-sheet__search-icon {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker-sheet__search-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: none;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
color: var(--picker-text);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
text-align: right;
|
||||
direction: rtl;
|
||||
|
||||
&::placeholder {
|
||||
color: var(--picker-text-soft);
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker-sheet__clear-btn {
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.product-picker-sheet__list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
max-height: 55vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.product-picker-sheet__item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
padding: 0.65rem 0.75rem;
|
||||
border-radius: 0.65rem;
|
||||
border: 1px solid var(--picker-border);
|
||||
background: var(--picker-bg);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
outline: none;
|
||||
text-align: right;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--App-secondary-color, #e0be7f);
|
||||
}
|
||||
|
||||
&--selected {
|
||||
border-color: var(--App-secondary-color, #e0be7f);
|
||||
background: rgba(224, 190, 127, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker-sheet__item-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.65rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.product-picker-sheet__item-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2.1rem;
|
||||
height: 2.1rem;
|
||||
border-radius: 0.5rem;
|
||||
background: var(--picker-inset);
|
||||
flex-shrink: 0;
|
||||
|
||||
.product-picker-sheet__item--selected & {
|
||||
background: var(--App-secondary-color, #e0be7f);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.product-picker-sheet__item-texts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.product-picker-sheet__item-title {
|
||||
font-size: 0.85rem;
|
||||
font-weight: 700;
|
||||
color: var(--picker-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.product-picker-sheet__item-meta {
|
||||
font-size: 0.7rem;
|
||||
color: var(--picker-text-soft);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.product-picker-sheet__item-check {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-picker-sheet__empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.4rem;
|
||||
padding: 2rem 1rem;
|
||||
color: var(--picker-text-soft);
|
||||
font-size: 0.8125rem;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<a
|
||||
v-if="href && src"
|
||||
referrerpolicy="origin"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
:href="href"
|
||||
class="enamad-badge"
|
||||
:class="`enamad-badge--${size}`"
|
||||
>
|
||||
<img
|
||||
referrerpolicy="origin"
|
||||
:src="src"
|
||||
alt="enamad"
|
||||
class="enamad-badge__img"
|
||||
:code="code || undefined"
|
||||
/>
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
size?: 'sm' | 'lg'
|
||||
}>(),
|
||||
{ size: 'sm' },
|
||||
)
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
const href = computed(() =>
|
||||
String(settingsStore.getSettingByKey('enamad_url') ?? '').trim(),
|
||||
)
|
||||
const src = computed(() =>
|
||||
String(settingsStore.getSettingByKey('enamad_logo') ?? '').trim(),
|
||||
)
|
||||
const code = computed(() => {
|
||||
try {
|
||||
const u = new URL(href.value || src.value)
|
||||
return u.searchParams.get('Code') || u.searchParams.get('code') || ''
|
||||
} catch {
|
||||
return ''
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.enamad-badge {
|
||||
display: inline-flex;
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.enamad-badge__img {
|
||||
width: auto;
|
||||
cursor: pointer;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.enamad-badge--sm .enamad-badge__img {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.enamad-badge--lg .enamad-badge__img {
|
||||
height: 120px;
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,307 @@
|
||||
<template>
|
||||
<BasicModal
|
||||
v-model:visible="visible"
|
||||
width="400px"
|
||||
destroy-on-close
|
||||
custom-footer
|
||||
wrap-class-name="gold-day-calc-modal"
|
||||
>
|
||||
<template #title>
|
||||
<div class="gold-day-calc-modal__title">
|
||||
<BasicIcon icon="vuesax-linear:chart-2" size="20" class="gold-day-calc-modal__title-icon" />
|
||||
<span>محاسبهگر طلای شما</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="gold-day-calc" dir="rtl">
|
||||
<BasicInput
|
||||
v-model:value="weight"
|
||||
title="وزن طلا (گرم)"
|
||||
type="tel"
|
||||
place-holder="مثلاً ۱۰.۵"
|
||||
inputmode="decimal"
|
||||
/>
|
||||
|
||||
<BasicInput
|
||||
:value="unitPriceInput"
|
||||
title="قیمت روز طلا"
|
||||
type="tel"
|
||||
disabled
|
||||
addon-before="ریال"
|
||||
place-holder="قیمت صفحه اصلی"
|
||||
/>
|
||||
|
||||
<BasicInput
|
||||
v-model:value="feePercent"
|
||||
title="اجرت ساخت (%)"
|
||||
type="tel"
|
||||
place-holder="مثلاً ۷"
|
||||
inputmode="decimal"
|
||||
/>
|
||||
|
||||
<BasicInput
|
||||
v-model:value="taxPercent"
|
||||
title="سود و مالیات (%)"
|
||||
type="tel"
|
||||
place-holder="مثلاً ۹"
|
||||
inputmode="decimal"
|
||||
/>
|
||||
|
||||
<div class="gold-day-calc__result rounded-xl border border-solid border-gray-200 bg-gray-50 p-3">
|
||||
<div class="text-xs text-gray-500 mb-1">کل نهایی</div>
|
||||
<div class="gold-day-calc__total text-lg font-bold text-primary">
|
||||
<span class="gold-day-calc__num">{{ formattedTotal }}</span>
|
||||
<span class="text-sm font-medium text-gray-600">ریال</span>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-col gap-1 text-xs text-gray-600">
|
||||
<div class="flex justify-between gap-2">
|
||||
<span>هزینه طلا</span>
|
||||
<span class="gold-day-calc__num">{{ formatRial(breakdown.goldCost) }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between gap-2">
|
||||
<span>اجرت</span>
|
||||
<span class="gold-day-calc__num">{{ formatRial(breakdown.feeCost) }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between gap-2">
|
||||
<span>سود و مالیات</span>
|
||||
<span class="gold-day-calc__num">{{ formatRial(breakdown.taxCost) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<BasicButton type="primary" class="!w-full" size="middle" @click="recalculate">
|
||||
محاسبه مجدد
|
||||
</BasicButton>
|
||||
</template>
|
||||
</BasicModal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
|
||||
import BasicInput from '@/components/BasicPacks/BasicInput.vue'
|
||||
import BasicButton from '@/components/BasicPacks/BasicButton.vue'
|
||||
import BasicIcon from '@/components/BasicPacks/BasicIcon.vue'
|
||||
import { goldDayCalculatorVisible } from '@/composables/useGoldDayCalculator'
|
||||
import {
|
||||
getLastPrices,
|
||||
getTradeBuyPrice,
|
||||
lastPrice,
|
||||
startLastPricePolling,
|
||||
stopLastPricePolling,
|
||||
} from '@/utils/price'
|
||||
import { getPriceDisplayState, NO_QUOTE_MESSAGE } from '@/utils/storeHours'
|
||||
import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { persianToEnglishDigits } from '@/utils/persianDigits'
|
||||
|
||||
const visible = goldDayCalculatorVisible
|
||||
|
||||
const weight = ref<string | number>('')
|
||||
const feePercent = ref<string | number>('')
|
||||
const taxPercent = ref<string | number>('')
|
||||
const tick = ref(0)
|
||||
|
||||
function parseNum(raw: string | number | undefined): number {
|
||||
const s = persianToEnglishDigits(String(raw ?? ''))
|
||||
.replace(/,/g, '')
|
||||
.replace(/[^\d.]/g, '')
|
||||
const n = Number.parseFloat(s)
|
||||
return Number.isFinite(n) ? n : 0
|
||||
}
|
||||
|
||||
const liveUnitPrice = computed(() => {
|
||||
void tick.value
|
||||
if (getPriceDisplayState() !== 'open') return 0
|
||||
return getTradeBuyPrice(lastPrice.value) || 0
|
||||
})
|
||||
|
||||
const unitPriceInput = computed(() => {
|
||||
void tick.value
|
||||
const state = getPriceDisplayState()
|
||||
if (state === 'closed') return 'فروشگاه بسته است'
|
||||
if (state === 'no_quote') return NO_QUOTE_MESSAGE
|
||||
const p = liveUnitPrice.value
|
||||
return p > 0 ? usePriceWithoutType(p) : ''
|
||||
})
|
||||
|
||||
const breakdown = computed(() => {
|
||||
void tick.value
|
||||
const w = parseNum(weight.value)
|
||||
const fee = parseNum(feePercent.value)
|
||||
const tax = parseNum(taxPercent.value)
|
||||
const unit = liveUnitPrice.value
|
||||
const goldCost = w * unit
|
||||
const feeCost = goldCost * (fee / 100)
|
||||
const taxCost = (goldCost + feeCost) * (tax / 100)
|
||||
const total = goldCost + feeCost + taxCost
|
||||
return { goldCost, feeCost, taxCost, total }
|
||||
})
|
||||
|
||||
const formattedTotal = computed(() => formatRial(breakdown.value.total))
|
||||
|
||||
function formatRial(n: number) {
|
||||
if (!Number.isFinite(n) || n <= 0) return '۰'
|
||||
return usePriceWithoutType(Math.round(n))
|
||||
}
|
||||
|
||||
function recalculate() {
|
||||
tick.value += 1
|
||||
void getLastPrices()
|
||||
}
|
||||
|
||||
watch(visible, async (open) => {
|
||||
if (open) {
|
||||
startLastPricePolling()
|
||||
await getLastPrices()
|
||||
tick.value += 1
|
||||
} else {
|
||||
stopLastPricePolling()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.gold-day-calc {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* فقط متن لیبل RTL — گروه اینپوت LTR بماند تا addon ریال نشکند */
|
||||
.gold-day-calc :deep(.ant-input-group) {
|
||||
direction: ltr;
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gold-day-calc :deep(.ant-input-group > .ant-input) {
|
||||
direction: ltr;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.gold-day-calc :deep(.ant-input:not(.ant-input-group *)) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.gold-day-calc__result {
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.gold-day-calc__total {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
justify-content: flex-start;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.gold-day-calc__num {
|
||||
direction: ltr;
|
||||
unicode-bidi: isolate;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
.gold-day-calc-modal {
|
||||
.ant-modal-content {
|
||||
direction: rtl;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-height: min(88dvh, 640px);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ant-modal-header {
|
||||
flex-shrink: 0;
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
/* ضربدر فیزیکی چپ — پدینگ راست کم تا عنوان نزدیک لبه راست بماند */
|
||||
padding-left: 2.75rem;
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.ant-modal-title {
|
||||
text-align: right;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gold-day-calc-modal__title {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: 0.5rem;
|
||||
direction: rtl;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gold-day-calc-modal__title-icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--App-secondary-color, #c9a062);
|
||||
}
|
||||
|
||||
/* ضربدر سمت چپ — عنوان سمت راست */
|
||||
.ant-modal-close {
|
||||
inset-inline-start: 0 !important;
|
||||
inset-inline-end: auto !important;
|
||||
right: auto !important;
|
||||
left: 0 !important;
|
||||
}
|
||||
|
||||
.ant-modal-body {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
padding-bottom: 0.25rem;
|
||||
max-height: none;
|
||||
}
|
||||
|
||||
#body {
|
||||
max-height: min(48dvh, 360px) !important;
|
||||
overflow-y: auto !important;
|
||||
overscroll-behavior: contain;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.ant-modal-footer {
|
||||
flex-shrink: 0;
|
||||
margin-top: 0;
|
||||
padding-top: 0.75rem;
|
||||
border-top: 1px solid rgba(148, 163, 184, 0.25);
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 767.98px) {
|
||||
.gold-day-calc-modal {
|
||||
.ant-modal {
|
||||
max-width: calc(100vw - 1.5rem);
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.ant-modal-content {
|
||||
max-height: min(86dvh, 100%);
|
||||
}
|
||||
|
||||
/* بین هدر و دکمه — ارتفاع کمتر تا اسکرول بخورد */
|
||||
#body {
|
||||
max-height: min(42dvh, 280px) !important;
|
||||
}
|
||||
|
||||
.ant-modal-body {
|
||||
padding-top: 0.25rem;
|
||||
padding-bottom: 0.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 400px) {
|
||||
.gold-day-calc-modal #body {
|
||||
max-height: min(38dvh, 240px) !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -29,16 +29,26 @@ const props = withDefaults(
|
||||
}
|
||||
)
|
||||
|
||||
function productImageKey(product?: ProductImageSource): string {
|
||||
return [
|
||||
product?.file_id ?? '',
|
||||
product?.file?.id ?? '',
|
||||
product?.file?.full_src ?? '',
|
||||
product?.file?.src ?? '',
|
||||
product?.file?.url ?? '',
|
||||
product?.img ?? '',
|
||||
].join('|')
|
||||
}
|
||||
|
||||
const currentSrc = ref(resolveProductImageSrc(props.product))
|
||||
const usingFallback = ref(false)
|
||||
|
||||
watch(
|
||||
() => props.product,
|
||||
(product) => {
|
||||
() => productImageKey(props.product),
|
||||
() => {
|
||||
usingFallback.value = false
|
||||
currentSrc.value = resolveProductImageSrc(product)
|
||||
currentSrc.value = resolveProductImageSrc(props.product)
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
function handleError() {
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
import { ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import router from '@/router'
|
||||
import { getColleagueOrderStatus, getPendingColleagueOrder } from '@/api/order'
|
||||
import { useUserStore } from '@/store/userStore'
|
||||
import { useWalletStore } from '@/store/walletStore'
|
||||
import { useFundUserStore } from '@/store/fundStore'
|
||||
import { getToken } from '@/utils'
|
||||
|
||||
export const colleagueOrderWaiting = ref(false)
|
||||
|
||||
const CLIENT_POLL_MS = 10000
|
||||
const MAX_WAIT_MS = 15 * 60 * 1000
|
||||
const STREAM_EVENT = 'colleague-order'
|
||||
|
||||
type WaitResult = 'success' | 'failed' | 'none'
|
||||
|
||||
let inflight: Promise<WaitResult> | null = null
|
||||
|
||||
export function emitColleagueOrderFromStream(payload: unknown) {
|
||||
window.dispatchEvent(new CustomEvent(STREAM_EVENT, { detail: payload }))
|
||||
}
|
||||
|
||||
export function isColleagueOrderPending(res: unknown): boolean {
|
||||
if (!res || typeof res !== 'object') return false
|
||||
const row = res as Record<string, any>
|
||||
if (row.pending === true) return true
|
||||
if (Array.isArray(row) && row[0]?.pending === true) return true
|
||||
const sts = Number(
|
||||
row[0]?.sts ?? row.sts ?? row[1]?.order?.sts ?? row.order?.sts ?? NaN
|
||||
)
|
||||
return sts === 4
|
||||
}
|
||||
|
||||
export function colleagueOrderIdFromResponse(res: unknown): number | null {
|
||||
if (!res || typeof res !== 'object') return null
|
||||
const row = res as Record<string, any>
|
||||
const id = Number(
|
||||
row[0]?.order_id ?? row.order_id ?? row[1]?.order?.id ?? row.order?.id ?? NaN
|
||||
)
|
||||
return id > 0 ? id : null
|
||||
}
|
||||
|
||||
async function finishSuccess() {
|
||||
try {
|
||||
await useUserStore().getMyInfo()
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
try {
|
||||
await useWalletStore().getMyWallet()
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
try {
|
||||
await useFundUserStore().getMyFund()
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
message.success('سفارش شما با موفقیت انجام شد')
|
||||
if (router.currentRoute.value.name !== 'transactions') {
|
||||
await router.push({ name: 'transactions' })
|
||||
}
|
||||
}
|
||||
|
||||
function stsFromPayload(payload: Record<string, any> | null | undefined): number | null {
|
||||
if (!payload) return null
|
||||
const sts = Number(payload.sts ?? payload.order?.sts)
|
||||
return Number.isFinite(sts) ? sts : null
|
||||
}
|
||||
|
||||
/** نتیجه قطعی از پاسخ status/pending — null یعنی هنوز باید صبر کرد */
|
||||
function settleFromPayload(payload: Record<string, any> | null | undefined): WaitResult | null {
|
||||
if (!payload || typeof payload !== 'object') return null
|
||||
|
||||
const pending = payload.pending
|
||||
const sts = stsFromPayload(payload)
|
||||
|
||||
if (sts === 2) return 'success'
|
||||
if (sts === 3) return 'failed'
|
||||
if (sts !== null && sts !== 4) return 'failed'
|
||||
if (pending === false) {
|
||||
if (sts === 2) return 'success'
|
||||
return 'failed'
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async function readSettle(orderId: number | null): Promise<WaitResult | null> {
|
||||
try {
|
||||
if (orderId && orderId > 0) {
|
||||
const row = (await getColleagueOrderStatus(orderId)) as Record<string, any>
|
||||
return settleFromPayload(row)
|
||||
}
|
||||
const row = (await getPendingColleagueOrder()) as Record<string, any>
|
||||
return settleFromPayload(row)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function waitForColleagueOrder(orderId?: number | null): Promise<WaitResult> {
|
||||
if (inflight) return inflight
|
||||
|
||||
inflight = (async () => {
|
||||
colleagueOrderWaiting.value = true
|
||||
let settled: WaitResult | null = null
|
||||
const startedAt = Date.now()
|
||||
|
||||
const finish = (result: WaitResult) => {
|
||||
if (settled) return
|
||||
settled = result
|
||||
}
|
||||
|
||||
const onStream = (event: Event) => {
|
||||
const detail = (event as CustomEvent).detail as Record<string, any> | undefined
|
||||
if (orderId && Number(detail?.order_id) > 0 && Number(detail.order_id) !== orderId) {
|
||||
return
|
||||
}
|
||||
const result = settleFromPayload(detail ?? null)
|
||||
if (result) finish(result)
|
||||
}
|
||||
|
||||
window.addEventListener(STREAM_EVENT, onStream)
|
||||
|
||||
try {
|
||||
while (!settled) {
|
||||
if (Date.now() - startedAt > MAX_WAIT_MS) {
|
||||
finish('failed')
|
||||
break
|
||||
}
|
||||
const result = await readSettle(orderId ?? null)
|
||||
if (result) {
|
||||
finish(result)
|
||||
break
|
||||
}
|
||||
await new Promise<void>((resolve) => {
|
||||
const timer = window.setTimeout(resolve, CLIENT_POLL_MS)
|
||||
const once = () => {
|
||||
window.clearTimeout(timer)
|
||||
resolve()
|
||||
}
|
||||
window.addEventListener(STREAM_EVENT, once, { once: true })
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
window.removeEventListener(STREAM_EVENT, onStream)
|
||||
colleagueOrderWaiting.value = false
|
||||
}
|
||||
|
||||
if (settled === 'success') {
|
||||
await finishSuccess()
|
||||
return 'success'
|
||||
}
|
||||
|
||||
message.error('سفارش توسط همکار رد شد')
|
||||
return 'failed'
|
||||
})().finally(() => {
|
||||
inflight = null
|
||||
})
|
||||
|
||||
return inflight
|
||||
}
|
||||
|
||||
export async function afterCreateOrder(res: unknown): Promise<WaitResult> {
|
||||
if (isColleagueOrderPending(res)) {
|
||||
return waitForColleagueOrder(colleagueOrderIdFromResponse(res))
|
||||
}
|
||||
await finishSuccess()
|
||||
return 'success'
|
||||
}
|
||||
|
||||
export async function resumeColleagueOrderIfPending(): Promise<WaitResult> {
|
||||
if (!getToken()) return 'none'
|
||||
try {
|
||||
const row = (await getPendingColleagueOrder()) as Record<string, any>
|
||||
if (!row?.pending) return 'none'
|
||||
const id = Number(row.order_id ?? row.order?.id ?? 0)
|
||||
return waitForColleagueOrder(id > 0 ? id : null)
|
||||
} catch {
|
||||
return 'none'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
/** باز/بسته بودن مدال محاسبهگر طلا — مشترک بین منوی کاربر و همبرگر */
|
||||
export const goldDayCalculatorVisible = ref(false)
|
||||
|
||||
export function openGoldDayCalculator() {
|
||||
goldDayCalculatorVisible.value = true
|
||||
}
|
||||
|
||||
export function closeGoldDayCalculator() {
|
||||
goldDayCalculatorVisible.value = false
|
||||
}
|
||||
@@ -1,47 +1,75 @@
|
||||
import { ref } from 'vue'
|
||||
import { getProducts } from '@/api/products'
|
||||
import type { Product } from '@/models/products'
|
||||
import { getLastStreamProductsList } from '@/utils/productStreamBridge'
|
||||
import { priceStreamList } from '@/utils/priceSocketState'
|
||||
|
||||
/** کش مشترک لیست محصولات — dedupe درخواستهای polling */
|
||||
const catalogProducts = ref<Product[]>([])
|
||||
let catalogPromise: Promise<Product[]> | null = null
|
||||
|
||||
export function getProductsCatalogRef() {
|
||||
if (catalogProducts.value.length === 0 && Array.isArray(priceStreamList.value) && priceStreamList.value.length > 0) {
|
||||
catalogProducts.value = priceStreamList.value as unknown as Product[]
|
||||
}
|
||||
return catalogProducts
|
||||
}
|
||||
|
||||
export function findProductInCatalog(id: number): Product | undefined {
|
||||
const cached = catalogProducts.value.find((p) => p.id === id)
|
||||
if (cached) {
|
||||
return cached
|
||||
export function syncCatalogFromStream(streamProducts: Product[]) {
|
||||
if (!Array.isArray(streamProducts) || streamProducts.length === 0) return
|
||||
if (catalogProducts.value.length === 0) {
|
||||
catalogProducts.value = streamProducts
|
||||
} else {
|
||||
const map = new Map(streamProducts.map((p) => [p.id, p]))
|
||||
catalogProducts.value.forEach((p) => {
|
||||
const incoming = map.get(p.id)
|
||||
if (incoming) {
|
||||
if (incoming.price !== undefined) p.price = incoming.price
|
||||
if (incoming.price_buy !== undefined) p.price_buy = incoming.price_buy
|
||||
if (incoming.price_sell !== undefined) p.price_sell = incoming.price_sell
|
||||
if (incoming.trade_open !== undefined) p.trade_open = incoming.trade_open
|
||||
if (incoming.show !== undefined) p.show = incoming.show
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return getLastStreamProductsList()?.find((p) => p.id === id)
|
||||
export function findProductInCatalog(id: number): Product | undefined {
|
||||
return catalogProducts.value.find((p) => p.id === id)
|
||||
}
|
||||
|
||||
export function getProductsCatalog(force = false): Promise<Product[]> {
|
||||
if (!force) {
|
||||
const streamed = getLastStreamProductsList()
|
||||
if (streamed?.length) {
|
||||
catalogProducts.value = streamed
|
||||
return Promise.resolve(streamed)
|
||||
}
|
||||
|
||||
if (catalogProducts.value.length > 0) {
|
||||
return Promise.resolve(catalogProducts.value)
|
||||
}
|
||||
if (Array.isArray(priceStreamList.value) && priceStreamList.value.length > 0) {
|
||||
catalogProducts.value = priceStreamList.value as unknown as Product[]
|
||||
return Promise.resolve(catalogProducts.value)
|
||||
}
|
||||
}
|
||||
|
||||
if (!force && catalogPromise) {
|
||||
return catalogPromise
|
||||
}
|
||||
|
||||
catalogPromise = getProducts()
|
||||
catalogPromise = getProducts(force)
|
||||
.then((products) => {
|
||||
catalogProducts.value = products ?? []
|
||||
const list = Array.isArray(products) ? products : []
|
||||
if (list.length > 0) {
|
||||
catalogProducts.value = list
|
||||
}
|
||||
return catalogProducts.value
|
||||
})
|
||||
.catch((err) => {
|
||||
if (catalogProducts.value.length > 0) {
|
||||
return catalogProducts.value
|
||||
}
|
||||
if (Array.isArray(priceStreamList.value) && priceStreamList.value.length > 0) {
|
||||
catalogProducts.value = priceStreamList.value as unknown as Product[]
|
||||
return catalogProducts.value
|
||||
}
|
||||
throw err
|
||||
})
|
||||
.finally(() => {
|
||||
catalogPromise = null
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AppConfig } from './types'
|
||||
import { rewriteLegacyUploadUrl } from './rewrite-legacy-upload-url'
|
||||
|
||||
type RawAppConfig = AppConfig & {
|
||||
user?: Record<string, any>
|
||||
@@ -32,6 +33,10 @@ function normalizeUserConfig(user?: Record<string, any>) {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof normalized.avatar === 'string') {
|
||||
normalized.avatar = rewriteLegacyUploadUrl(normalized.avatar)
|
||||
}
|
||||
|
||||
return normalized
|
||||
}
|
||||
|
||||
@@ -40,14 +45,17 @@ export function normalizeAppConfig(config: RawAppConfig): RawAppConfig {
|
||||
return {}
|
||||
}
|
||||
|
||||
if (!config.user || typeof config.user !== 'object') {
|
||||
return config
|
||||
const next: RawAppConfig = { ...config }
|
||||
|
||||
if (typeof next.avatar === 'string') {
|
||||
next.avatar = rewriteLegacyUploadUrl(next.avatar)
|
||||
}
|
||||
|
||||
return {
|
||||
...config,
|
||||
user: normalizeUserConfig(config.user),
|
||||
if (next.user && typeof next.user === 'object') {
|
||||
next.user = normalizeUserConfig(next.user)
|
||||
}
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
let appConfig: RawAppConfig | null = null
|
||||
@@ -55,6 +63,13 @@ let appConfig: RawAppConfig | null = null
|
||||
export function setAppConfig(config: RawAppConfig) {
|
||||
appConfig = normalizeAppConfig(config || {})
|
||||
window.__APP_CONFIG__ = appConfig
|
||||
try {
|
||||
const apply = (window as Window & {__APPLY_BOOT_BRANDING__?: (c: unknown) => void})
|
||||
.__APPLY_BOOT_BRANDING__
|
||||
if (typeof apply === 'function') apply(appConfig)
|
||||
} catch {
|
||||
/* boot DOM ممکن است هنوز نباشد */
|
||||
}
|
||||
}
|
||||
|
||||
export function getRawAppConfig() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getConfig } from '@/config/app-config'
|
||||
import { rewriteLegacyUploadUrl } from '@/config/rewrite-legacy-upload-url'
|
||||
import { isPwaManifestReady } from '@/modules/pwa/manifest'
|
||||
|
||||
export function applyAppConfig() {
|
||||
@@ -14,7 +15,7 @@ function setTitle() {
|
||||
}
|
||||
|
||||
function getLogoUrl() {
|
||||
return getConfig<string>('avatar') || '/favicon.png'
|
||||
return rewriteLegacyUploadUrl(getConfig<string>('avatar') || '/favicon.png')
|
||||
}
|
||||
|
||||
function setFavicon() {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AppConfig } from '@/config/types'
|
||||
import { rewriteLegacyUploadUrl } from '@/config/rewrite-legacy-upload-url'
|
||||
import { resetVersionCheckCache } from '@/config/load-version'
|
||||
import { clearCachedPwaManifest } from '@/modules/pwa/manifest-cache'
|
||||
import { tokenName } from '@/themeConfig'
|
||||
@@ -62,8 +63,28 @@ export function readCachedAppConfig(): AppConfig | null {
|
||||
}
|
||||
}
|
||||
|
||||
function persistBootLogo(config: AppConfig) {
|
||||
try {
|
||||
const nested = (config as {user?: Record<string, unknown>})?.user
|
||||
const avatar = rewriteLegacyUploadUrl(String(nested?.avatar || '').trim())
|
||||
const version = String(localStorage.getItem(VERSION_STORAGE_KEY) || '').trim()
|
||||
const cachedUrl = localStorage.getItem('BOOT_LOGO_URL') || ''
|
||||
const cachedVer = localStorage.getItem('BOOT_LOGO_VERSION') || ''
|
||||
const cacheFresh = !!(cachedUrl && version && cachedVer && version === cachedVer)
|
||||
if (avatar && (!cacheFresh || cachedUrl !== avatar)) localStorage.setItem('BOOT_LOGO_URL', avatar)
|
||||
if (version) localStorage.setItem('BOOT_LOGO_VERSION', version)
|
||||
const apply = (window as Window & {__APPLY_BOOT_BRANDING__?: (c: unknown) => void})
|
||||
.__APPLY_BOOT_BRANDING__
|
||||
if (typeof apply === 'function') apply(config)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
export function writeCachedAppConfig(config: AppConfig) {
|
||||
try {
|
||||
persistBootLogo(config)
|
||||
|
||||
const payload: CachedConfigPayload = {
|
||||
cached_at: Date.now(),
|
||||
config
|
||||
@@ -206,12 +227,22 @@ export async function clearBrowserRuntimeCaches() {
|
||||
|
||||
function clearLocalStorageExceptToken() {
|
||||
const token = localStorage.getItem(tokenName)
|
||||
let bootLogo = ''
|
||||
let bootLogoVer = ''
|
||||
try {
|
||||
bootLogo = localStorage.getItem('BOOT_LOGO_URL') || ''
|
||||
bootLogoVer = localStorage.getItem('BOOT_LOGO_VERSION') || ''
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
localStorage.clear()
|
||||
|
||||
if (token) {
|
||||
localStorage.setItem(tokenName, token)
|
||||
}
|
||||
if (bootLogo) localStorage.setItem('BOOT_LOGO_URL', bootLogo)
|
||||
if (bootLogoVer) localStorage.setItem('BOOT_LOGO_VERSION', bootLogoVer)
|
||||
}
|
||||
|
||||
export function clearAppStorageExceptToken() {
|
||||
@@ -254,6 +285,11 @@ export async function refreshConfigCacheForVersion(
|
||||
|
||||
writeCachedAppConfig(freshConfig)
|
||||
finishVersionUpdateBeforeReload(normalizedVersion)
|
||||
try {
|
||||
localStorage.setItem('BOOT_LOGO_VERSION', normalizedVersion)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
return freshConfig
|
||||
}
|
||||
@@ -275,6 +311,11 @@ export async function resetAppAndRefreshConfig(
|
||||
|
||||
if (normalizedVersion) {
|
||||
writeStoredAppVersion(normalizedVersion)
|
||||
try {
|
||||
localStorage.setItem('BOOT_LOGO_VERSION', normalizedVersion)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
return freshConfig
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
function resolveSaBase(): string {
|
||||
try {
|
||||
const last = localStorage.getItem('CONFIG_Success_URL')
|
||||
if (last) {
|
||||
const parsed = new URL(last)
|
||||
const path = parsed.pathname.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
return path && path !== '/' ? `${parsed.origin}${path}` : parsed.origin
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return 'https://adm.montzar.ir'
|
||||
}
|
||||
|
||||
/** فقط /uploads/ نسبی؛ URL مطلق (نرخ و …) دست نخورده */
|
||||
export function rewriteLegacyUploadUrl(raw: unknown): string {
|
||||
const value = String(raw || '').trim()
|
||||
if (!value) return ''
|
||||
if (value.startsWith('/uploads/')) return `${resolveSaBase()}${value}`
|
||||
return value
|
||||
}
|
||||
@@ -8,9 +8,6 @@ export const SUPERADMIN_BASES = [
|
||||
/** هر API: سه دامنه × سه دور */
|
||||
export const SA_RETRY_ROUNDS = 3
|
||||
|
||||
/** تنظیمات پیشرفته نسخه — همان دادهٔ /get_settings بدون نیاز به nginx جدا */
|
||||
export const SA_PROGRAM_SETTINGS_PATH = '/api/public/program-settings'
|
||||
|
||||
function normalizeBase(url: string) {
|
||||
return String(url || '').trim().replace(/\/$/, '')
|
||||
}
|
||||
|
||||
@@ -41,6 +41,12 @@ function clearBodyScrollLock() {
|
||||
}
|
||||
}
|
||||
|
||||
/** leftover van-dialog overlay after logout/navigation — blocks all clicks */
|
||||
export function clearVantOverlays() {
|
||||
document.querySelectorAll('body > .van-overlay').forEach((el) => el.remove())
|
||||
clearBodyScrollLock()
|
||||
}
|
||||
|
||||
function resetAllScrollPositions() {
|
||||
window.scrollTo(0, 0)
|
||||
document.documentElement.scrollTop = 0
|
||||
|
||||
@@ -34,6 +34,10 @@
|
||||
@click="navigateTo(item.routeName)"
|
||||
/>
|
||||
</nav>
|
||||
|
||||
<div class="desktop-sidebar__credit">
|
||||
<AppCreditLink variant="sidebar" />
|
||||
</div>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
@@ -46,14 +50,22 @@ import { useTrackingSystemsFeature } from '@/composables/useTrackingSystemsFeatu
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getPrimaryNavItems, getSecondaryNavItems } from '../config/navigation'
|
||||
import { useAppNavigation } from '../composables/useAppNavigation'
|
||||
import { featureSettingForRoute } from '@/utils/superAdminMenuGates'
|
||||
import DesktopNavItem from './DesktopNavItem.vue'
|
||||
import AppCreditLink from '@/components/AppCreditLink.vue'
|
||||
|
||||
const cartStore = useCartStore()
|
||||
const authenticated = computed(() => isToken())
|
||||
const navLogo = logoFull
|
||||
const { trackingSystemsEnabled } = useTrackingSystemsFeature()
|
||||
const settingsStore = useSettingsStore()
|
||||
const primaryItems = computed(() => getPrimaryNavItems(authenticated.value))
|
||||
const primaryItems = computed(() =>
|
||||
getPrimaryNavItems(authenticated.value).filter((item) => {
|
||||
const featureKey = featureSettingForRoute(item.routeName)
|
||||
if (featureKey) return settingsStore.isSettingTruthy(featureKey)
|
||||
return true
|
||||
}),
|
||||
)
|
||||
/** «لیست دریافتیها» فقط در موبایل نمایش داده میشود */
|
||||
const DESKTOP_HIDDEN_NAV_IDS = ['list']
|
||||
const secondaryItems = computed(() =>
|
||||
@@ -61,12 +73,8 @@ const secondaryItems = computed(() =>
|
||||
includeRecoverySites: trackingSystemsEnabled.value,
|
||||
}).filter((item) => {
|
||||
if (DESKTOP_HIDDEN_NAV_IDS.includes(item.id)) return false
|
||||
if (item.id === 'notifyTrigger') {
|
||||
return settingsStore.isSettingTruthy('has_page_price_trigger')
|
||||
}
|
||||
if (item.id === 'giftCard') {
|
||||
return settingsStore.isSettingTruthy('has_page_gift_card')
|
||||
}
|
||||
const featureKey = featureSettingForRoute(item.routeName)
|
||||
if (featureKey) return settingsStore.isSettingTruthy(featureKey)
|
||||
return true
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -85,6 +85,13 @@
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.desktop-sidebar__credit {
|
||||
margin-top: 12px;
|
||||
padding: 12px 8px 4px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.desktop-sidebar__divider {
|
||||
height: 1px;
|
||||
background: rgba(0, 0, 0, 0.08);
|
||||
|
||||
@@ -111,13 +111,17 @@ html.app-layout--desktop {
|
||||
}
|
||||
|
||||
.dhome-topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
margin-bottom: 28px;
|
||||
padding-bottom: 24px;
|
||||
margin: -4px 0 20px;
|
||||
padding: 12px 0 20px;
|
||||
border-bottom: 1px solid rgba(15, 23, 42, 0.06);
|
||||
background: #f6f7f9;
|
||||
|
||||
&__eyebrow {
|
||||
font-size: 12px;
|
||||
|
||||
@@ -47,6 +47,7 @@ const {
|
||||
watch(
|
||||
() => route.fullPath,
|
||||
() => {
|
||||
closeOverflowMenu()
|
||||
resetMobileAppScroll()
|
||||
},
|
||||
{ flush: 'post' },
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
<Transition>
|
||||
<div
|
||||
v-if="show"
|
||||
class="top-0 bottom-0 bg-black wrap-fix z-5000 opacity-60"
|
||||
class="top-0 bottom-0 bg-black wrap-fix z-5200 opacity-60"
|
||||
@click="$emit('close')"
|
||||
/>
|
||||
</Transition>
|
||||
<Transition name="slide-fade">
|
||||
<div v-if="show" class="wrap-fix bottom-11vh z-5000 flex justify-center items-end">
|
||||
<div
|
||||
v-if="show"
|
||||
class="wrap-fix z-5200 flex justify-center items-end bottom-[calc(var(--app-bottom-chrome-height)+1.5rem)]"
|
||||
>
|
||||
<div class="relative flex flex-col items-center">
|
||||
<div
|
||||
class="flex items-center justify-center bg-white rounded-full w-[30px] h-[30px] mb-2"
|
||||
@@ -34,18 +37,7 @@
|
||||
>
|
||||
<div class="flex gap-2 items-center">
|
||||
<BasicIcon icon="vuesax-linear:direct-inbox" size="16" class="absolute right-2" />
|
||||
<div>دریافت طلای فیزیکی</div>
|
||||
</div>
|
||||
</BasicButton>
|
||||
<BasicButton
|
||||
v-if="authenticated && priceTriggerEnabled"
|
||||
icon-size="16"
|
||||
class="!font-bold w-15rem"
|
||||
@click="go('notifyTrigger')"
|
||||
>
|
||||
<div class="flex gap-2 items-center">
|
||||
<BasicIcon icon="vuesax-linear:bill" size="16" class="absolute right-2" />
|
||||
<div>هشدار قیمت</div>
|
||||
<div>تحویل فیزیکی</div>
|
||||
</div>
|
||||
</BasicButton>
|
||||
<BasicButton
|
||||
@@ -135,9 +127,6 @@ const emit = defineEmits<{
|
||||
const authenticated = computed(() => isToken())
|
||||
const { trackingSystemsEnabled } = useTrackingSystemsFeature()
|
||||
const settingsStore = useSettingsStore()
|
||||
const priceTriggerEnabled = computed(() =>
|
||||
settingsStore.isSettingTruthy('has_page_price_trigger'),
|
||||
)
|
||||
const giftCardEnabled = computed(() =>
|
||||
settingsStore.isSettingTruthy('has_page_gift_card'),
|
||||
)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
.bottom-appbar {
|
||||
z-index: var(--app-z-nav, 5000);
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
bottom: var(--app-credit-footer-offset, 28px);
|
||||
right: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
max-width: 100vw;
|
||||
height: calc(var(--app-nav-height, 80px) + var(--app-safe-bottom, env(safe-area-inset-bottom, 0px)));
|
||||
padding-bottom: var(--app-safe-bottom, env(safe-area-inset-bottom, 0px));
|
||||
height: var(--app-nav-height, 80px);
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
justify-content: space-evenly;
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
.bottom-appbar {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
:root {
|
||||
--app-credit-bar-inner: 0px;
|
||||
--app-credit-footer-offset: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
html.app-layout--desktop {
|
||||
|
||||
@@ -53,6 +53,9 @@
|
||||
&__title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__trailing {
|
||||
|
||||
@@ -3,6 +3,7 @@ import './assets/css/main.less'
|
||||
import 'virtual:uno.css'
|
||||
|
||||
import { initPwaInstallCapture } from '@/modules/pwa/manifest'
|
||||
import { preloadLottieAssets } from '@/utils/lottieAssets'
|
||||
import { bootstrapApp } from '@/app/bootstrap'
|
||||
|
||||
export {
|
||||
@@ -15,4 +16,5 @@ export {
|
||||
import '@unocss/reset/tailwind-compat.css'
|
||||
|
||||
initPwaInstallCapture()
|
||||
void preloadLottieAssets()
|
||||
bootstrapApp()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
export interface PriceTrigger {
|
||||
id?: number
|
||||
product_id?: number
|
||||
product?: { id: number; title?: string }
|
||||
target_price: string
|
||||
price_condition: string
|
||||
action: string
|
||||
|
||||
@@ -31,4 +31,14 @@ export interface Price {
|
||||
time?: string
|
||||
main_product?: number
|
||||
montzar?: number
|
||||
zaarbox?: number
|
||||
/** montzar | zaarbox | main_product | store = مظنه زنده، database_last = آخرین قیمت ذخیرهشده */
|
||||
price_source?: string | null
|
||||
last_historical?: number
|
||||
special_pricing?: {
|
||||
package_id?: number
|
||||
title?: string
|
||||
profit_buy?: number
|
||||
profit_sell?: number
|
||||
} | null
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type {Wallet} from "@/models/wallet";
|
||||
export interface Product {
|
||||
id: number
|
||||
img: string | undefined
|
||||
image?: string | null
|
||||
title: string
|
||||
amount: any
|
||||
metal_id: any
|
||||
@@ -10,6 +11,7 @@ export interface Product {
|
||||
unit: string
|
||||
active: boolean
|
||||
show: boolean
|
||||
trade_open?: boolean
|
||||
show_in_assets?: boolean
|
||||
show_on_tv?: boolean
|
||||
open_sell: boolean
|
||||
@@ -21,6 +23,8 @@ export interface Product {
|
||||
cash_fee_sell: number | undefined
|
||||
cash_fee_buy_is_percent?: boolean | null
|
||||
cash_fee_sell_is_percent?: boolean | null
|
||||
special_profit_buy?: number | null
|
||||
special_profit_sell?: number | null
|
||||
order_limit_enabled?: boolean
|
||||
min_order_cash?: number | null
|
||||
max_order_cash?: number | null
|
||||
@@ -39,6 +43,10 @@ export interface Product {
|
||||
similar?:Product[]
|
||||
inventory:number
|
||||
app_price?: boolean | number | null
|
||||
colleague_price?: boolean | number | null
|
||||
colleague_price_product_id?: string | number | null
|
||||
tv_price?: number | null
|
||||
tv_sell_price?: number | null
|
||||
direct_price?: number | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
use_last_price_if_zero?: boolean | null
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface Transaction {
|
||||
unit: string
|
||||
hash?: string
|
||||
id?: number
|
||||
note?: null
|
||||
note?: string | null
|
||||
title: string
|
||||
order_id?: number
|
||||
transaction_type?: string
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import type { AppConfig } from '@/config/types'
|
||||
import { getConfig, getRawAppConfig } from '@/config/app-config'
|
||||
import { getConfigUrls, sortConfigUrls } from '@/config/load-config'
|
||||
import {
|
||||
getSuperAdminBase,
|
||||
isSuperAdminUrl,
|
||||
resolveTenantDomain,
|
||||
} from '@/config/superadmin'
|
||||
import {
|
||||
clearCachedPwaManifest,
|
||||
readCachedPwaManifest,
|
||||
@@ -23,7 +28,24 @@ function sleep(ms: number) {
|
||||
}
|
||||
|
||||
function normalizeBaseUrl(url: string) {
|
||||
return url.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
try {
|
||||
const parsed = new URL(url)
|
||||
parsed.search = ''
|
||||
parsed.hash = ''
|
||||
parsed.pathname = parsed.pathname
|
||||
.replace(/\/get_user\/?$/i, '')
|
||||
.replace(/\/manifest\.json$/i, '')
|
||||
if (!parsed.pathname || parsed.pathname === '/') {
|
||||
return parsed.origin
|
||||
}
|
||||
return `${parsed.origin}${parsed.pathname.replace(/\/+$/, '')}`
|
||||
} catch {
|
||||
return url
|
||||
.replace(/[?#].*$/, '')
|
||||
.replace(/\/get_user\/?$/i, '')
|
||||
.replace(/\/manifest\.json$/i, '')
|
||||
.replace(/\/+$/, '')
|
||||
}
|
||||
}
|
||||
|
||||
/** همان baseای که get_user از آن لود شده (کش شده در localStorage) */
|
||||
@@ -33,15 +55,28 @@ export function getConfigBaseFromStorage() {
|
||||
return normalizeBaseUrl(lastSuccess)
|
||||
}
|
||||
|
||||
function getSuperAdminManifestUrl(): string | null {
|
||||
const saBase = getSuperAdminBase()
|
||||
if (!saBase) return null
|
||||
return `${saBase}/manifest.json?domain=${encodeURIComponent(resolveTenantDomain())}`
|
||||
}
|
||||
|
||||
function configUrlToManifestUrl(configUrl: string) {
|
||||
return `${configUrl.replace(/\/+$/, '')}/manifest.json`
|
||||
if (isSuperAdminUrl(configUrl)) {
|
||||
return getSuperAdminManifestUrl() || `${normalizeBaseUrl(configUrl)}/manifest.json`
|
||||
}
|
||||
return `${normalizeBaseUrl(configUrl)}/manifest.json`
|
||||
}
|
||||
|
||||
/** همان ۵ URL پایهٔ get_user — اولویت با CONFIG_Success_URL */
|
||||
export function resolveManifestUrls(config?: AppConfig | null): string[] {
|
||||
const explicit = getConfig<string>('manifest_url')
|
||||
if (explicit) return [explicit]
|
||||
|
||||
const saManifest = getSuperAdminManifestUrl()
|
||||
if (saManifest) {
|
||||
return [saManifest]
|
||||
}
|
||||
|
||||
return sortConfigUrls(getConfigUrls()).map(configUrlToManifestUrl)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,16 @@ const router = createRouter({
|
||||
name: 'login',
|
||||
component: () => import('../views/login/index.vue')
|
||||
},
|
||||
{
|
||||
path: `/tv`,
|
||||
name: 'tvMonitor',
|
||||
alias: ['/monitor'],
|
||||
meta: {
|
||||
public: true,
|
||||
hideChrome: true,
|
||||
},
|
||||
component: () => import('../views/tv/index.vue')
|
||||
},
|
||||
/* {
|
||||
path: '/',
|
||||
name: 'null',
|
||||
@@ -187,6 +197,12 @@ const router = createRouter({
|
||||
name: '404',
|
||||
component: () => import('../views/base/404.vue')
|
||||
},
|
||||
{
|
||||
path: '/about-software',
|
||||
name: 'aboutSoftware',
|
||||
meta: { public: true },
|
||||
component: () => import('@/views/base/aboutSoftware/index.vue')
|
||||
},
|
||||
|
||||
/* {
|
||||
path: `/single/login`,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getSettings } from '@/api/configuration'
|
||||
import { fetchSuperAdminProgramSettings, isLockedCanEdit } from '@/api/superadminSettings'
|
||||
import { resolveMeltedGoldLabel, resolveMetalTypeLabel } from '@/utils/metalLabels'
|
||||
import { resolveTradeWeightUnit } from '@/utils/weightUnit'
|
||||
|
||||
@@ -13,12 +12,12 @@ export interface AppSetting {
|
||||
description?: string
|
||||
is_active?: boolean
|
||||
type?: string
|
||||
can_edit?: number | boolean | string
|
||||
}
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
const settings = ref<AppSetting[]>([])
|
||||
const loaded = ref(false)
|
||||
const settingsRevision = ref(0)
|
||||
let fetchPromise: Promise<AppSetting[]> | null = null
|
||||
|
||||
function getSettingByKey(key: string) {
|
||||
@@ -44,6 +43,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
}
|
||||
|
||||
const merged = [...settings.value]
|
||||
let changed = false
|
||||
items.forEach((item) => {
|
||||
if (!item?.key) {
|
||||
return
|
||||
@@ -51,13 +51,25 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
|
||||
const index = merged.findIndex((setting) => setting.key === item.key)
|
||||
if (index >= 0) {
|
||||
merged[index] = { ...merged[index], ...item }
|
||||
} else {
|
||||
merged.push(item)
|
||||
const current = merged[index]
|
||||
if (current.value === item.value && current.is_active === item.is_active) {
|
||||
return
|
||||
}
|
||||
merged[index] = { ...current, ...item }
|
||||
changed = true
|
||||
return
|
||||
}
|
||||
|
||||
merged.push(item)
|
||||
changed = true
|
||||
})
|
||||
|
||||
if (!changed) {
|
||||
return
|
||||
}
|
||||
|
||||
settings.value = merged
|
||||
settingsRevision.value += 1
|
||||
}
|
||||
|
||||
async function fetchSettings(force = false) {
|
||||
@@ -67,19 +79,17 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
|
||||
fetchPromise = (async () => {
|
||||
try {
|
||||
const localRaw = await getSettings().catch(() => [])
|
||||
const remote = await fetchSuperAdminProgramSettings()
|
||||
const local = Array.isArray(localRaw) ? localRaw : []
|
||||
const editable = local.filter((row) => !isLockedCanEdit(row?.can_edit))
|
||||
settings.value = []
|
||||
mergeSettings(remote as AppSetting[])
|
||||
mergeSettings(editable)
|
||||
loaded.value = true
|
||||
return settings.value
|
||||
const data = await getSettings()
|
||||
if (Array.isArray(data)) {
|
||||
mergeSettings(data)
|
||||
}
|
||||
} catch (error) {
|
||||
fetchPromise = null
|
||||
throw error
|
||||
console.log(error)
|
||||
} finally {
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
return settings.value
|
||||
})()
|
||||
|
||||
return fetchPromise
|
||||
@@ -89,14 +99,27 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
const metalTypeLabel = computed(() => resolveMetalTypeLabel(metalTypeSettingValue.value))
|
||||
const meltedGoldLabel = computed(() => resolveMeltedGoldLabel(metalTypeSettingValue.value))
|
||||
const tradeWeightUnit = computed(() => resolveTradeWeightUnit(getSettingByKey('unit')))
|
||||
const isReferralFieldVisible = computed(() => {
|
||||
if (!settings.value?.some((s) => s?.key === 'referral_show')) return true
|
||||
return isSettingTruthy('referral_show')
|
||||
})
|
||||
|
||||
const isReferralRequired = computed(() => {
|
||||
if (!isReferralFieldVisible.value) return false
|
||||
const value = String(getSettingByKey('referral_id') ?? '').trim().toLowerCase()
|
||||
return value === 'required' || value === 'true' || value === '1' || value === 'yes'
|
||||
})
|
||||
|
||||
return {
|
||||
settings,
|
||||
loaded,
|
||||
settingsRevision,
|
||||
fetchSettings,
|
||||
mergeSettings,
|
||||
getSettingByKey,
|
||||
isSettingTruthy,
|
||||
isReferralRequired,
|
||||
isReferralFieldVisible,
|
||||
metalTypeSettingValue,
|
||||
metalTypeLabel,
|
||||
meltedGoldLabel,
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { rewriteLegacyUploadUrl } from '@/config/rewrite-legacy-upload-url'
|
||||
|
||||
export function getConfigApp(key: string) {
|
||||
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
|
||||
|
||||
if (config) {
|
||||
return config[key]
|
||||
if (!config) return null
|
||||
const value = config[key]
|
||||
if (key === 'avatar') {
|
||||
return rewriteLegacyUploadUrl(value) || value || null
|
||||
}
|
||||
return null
|
||||
return value ?? null
|
||||
}
|
||||
|
||||
export function isBoursecuProject() {
|
||||
|
||||
@@ -144,7 +144,6 @@ export const justNumber = () => {
|
||||
message: 'لطفا اطلاعات را به صورت عدد و نقطه وارد کنید'
|
||||
}
|
||||
}
|
||||
const walletCash = useWalletStore()
|
||||
let priceP = 0
|
||||
let methodP = 'cash'
|
||||
let amountP = 0
|
||||
@@ -152,6 +151,7 @@ let isBuyP = true
|
||||
let NumP = 0
|
||||
let gatewayP = false
|
||||
const checkNumber = async (_rule: Rule, value: number) => {
|
||||
const walletCash = useWalletStore()
|
||||
if (!value) {
|
||||
return Promise.reject('تعداد محصول را مشخص کنید')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
export const LANDING_SETTING_PREFIXES = [
|
||||
'landing_site',
|
||||
'landing_header',
|
||||
'landing_hero',
|
||||
'landing_live_price',
|
||||
'landing_calculator',
|
||||
'landing_feature',
|
||||
'landing_steps',
|
||||
'landing_trust',
|
||||
'landing_faq',
|
||||
'landing_buttom_cta',
|
||||
'landing_footer'
|
||||
] as const
|
||||
|
||||
export type LandingSettingPrefix = (typeof LANDING_SETTING_PREFIXES)[number]
|
||||
|
||||
function isFlagOn(value: unknown): boolean {
|
||||
const v = String(value ?? '').trim().toLowerCase()
|
||||
return v === 'true' || v === '1' || v === 'yes' || v === 'activate'
|
||||
}
|
||||
|
||||
export function isLandingEnabled(getByKey: (key: string) => unknown): boolean {
|
||||
return isFlagOn(getByKey('has_landing'))
|
||||
}
|
||||
|
||||
export function getLandingSetting(getByKey: (key: string) => unknown, key: string): string {
|
||||
return String(getByKey(key) ?? '')
|
||||
}
|
||||
|
||||
export function matchesLandingPrefix(key: string, prefix: string): boolean {
|
||||
return key === prefix || key.startsWith(`${prefix}_`)
|
||||
}
|
||||
|
||||
export function pickLandingSettings(
|
||||
settings: Array<{ key?: string | number; value?: unknown }>,
|
||||
prefix: string
|
||||
): Record<string, string> {
|
||||
const out: Record<string, string> = {}
|
||||
for (const row of settings) {
|
||||
const key = String(row.key ?? '')
|
||||
if (!matchesLandingPrefix(key, prefix)) continue
|
||||
out[key] = String(row.value ?? '')
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/** Lottieهای لوکال (`public/lottie`) — پیشدانلود تا مودال/لیست خالی نماند */
|
||||
|
||||
const LOTTIE_FILES = {
|
||||
logoutConfirm: 'lottie/logoutConfirm.json',
|
||||
emptyList: 'lottie/emptyList.json',
|
||||
goldBars: 'lottie/goldBars.json',
|
||||
} as const
|
||||
|
||||
export type LottieAssetKey = keyof typeof LOTTIE_FILES
|
||||
|
||||
const cache = new Map<LottieAssetKey, string>()
|
||||
|
||||
export function lottieSrc(key: LottieAssetKey): string {
|
||||
const base = import.meta.env.BASE_URL || '/'
|
||||
const path = `${base}${LOTTIE_FILES[key]}`
|
||||
return path.replace(/([^:]\/)\/+/g, '$1')
|
||||
}
|
||||
|
||||
export function getLottieData(key: LottieAssetKey): string | undefined {
|
||||
return cache.get(key)
|
||||
}
|
||||
|
||||
export async function preloadLottieAssets(): Promise<void> {
|
||||
const keys = Object.keys(LOTTIE_FILES) as LottieAssetKey[]
|
||||
await Promise.all(
|
||||
keys.map(async (key) => {
|
||||
if (cache.has(key)) return
|
||||
try {
|
||||
const res = await fetch(lottieSrc(key))
|
||||
if (!res.ok) return
|
||||
cache.set(key, await res.text())
|
||||
} catch {
|
||||
/* شبکه/آفلاین — بعداً از src لوکال میخواند */
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
const MOBILE_MEDIA = '(max-width: 767.98px)'
|
||||
const KEYBOARD_GAP_PX = 16
|
||||
const SCROLL_RETRY_MS = [0, 90, 220, 420, 640]
|
||||
|
||||
let started = false
|
||||
let activeField: HTMLElement | null = null
|
||||
let blurTimer = 0
|
||||
|
||||
function isMobileLayout(): boolean {
|
||||
return window.matchMedia(MOBILE_MEDIA).matches
|
||||
}
|
||||
|
||||
function getKeyboardInset(): number {
|
||||
const vv = window.visualViewport
|
||||
if (!vv) return 0
|
||||
return Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop))
|
||||
}
|
||||
|
||||
function getVisibleViewportBottom(): number {
|
||||
const vv = window.visualViewport
|
||||
return vv ? vv.offsetTop + vv.height : window.innerHeight
|
||||
}
|
||||
|
||||
function syncViewportVars(hasFocusedField: boolean) {
|
||||
const vv = window.visualViewport
|
||||
const inset = getKeyboardInset()
|
||||
|
||||
document.documentElement.style.setProperty('--app-keyboard-inset', `${inset}px`)
|
||||
|
||||
if (vv) {
|
||||
document.documentElement.style.setProperty('--app-visual-viewport-height', `${Math.round(vv.height)}px`)
|
||||
document.documentElement.style.setProperty('--app-visual-viewport-offset-top', `${Math.round(vv.offsetTop)}px`)
|
||||
}
|
||||
|
||||
if (hasFocusedField && inset > 0) {
|
||||
document.documentElement.dataset.keyboardOpen = 'true'
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasFocusedField) {
|
||||
delete document.documentElement.dataset.keyboardOpen
|
||||
document.documentElement.style.setProperty('--app-keyboard-inset', '0px')
|
||||
}
|
||||
}
|
||||
|
||||
function resolveEditableTarget(node: EventTarget | null): HTMLElement | null {
|
||||
if (!(node instanceof HTMLElement)) return null
|
||||
|
||||
const field = node.closest('input, textarea, select, [contenteditable="true"]')
|
||||
if (!(field instanceof HTMLElement)) return null
|
||||
|
||||
if (field instanceof HTMLInputElement) {
|
||||
if (field.disabled || field.readOnly || field.type === 'hidden') return null
|
||||
}
|
||||
|
||||
if (field instanceof HTMLTextAreaElement) {
|
||||
if (field.disabled || field.readOnly) return null
|
||||
}
|
||||
|
||||
if (field instanceof HTMLSelectElement && field.disabled) return null
|
||||
|
||||
return field
|
||||
}
|
||||
|
||||
function findScrollableAncestor(el: HTMLElement): HTMLElement | null {
|
||||
let node: HTMLElement | null = el.parentElement
|
||||
|
||||
while (node && node !== document.body && node !== document.documentElement) {
|
||||
const style = window.getComputedStyle(node)
|
||||
const overflowY = style.overflowY
|
||||
const scrollable = overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay'
|
||||
|
||||
if (scrollable && node.scrollHeight > node.clientHeight + 1) {
|
||||
return node
|
||||
}
|
||||
|
||||
node = node.parentElement
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function ensureFieldVisible(field: HTMLElement) {
|
||||
if (!isMobileLayout()) return
|
||||
|
||||
syncViewportVars(true)
|
||||
|
||||
const rect = field.getBoundingClientRect()
|
||||
const visibleBottom = getVisibleViewportBottom() - KEYBOARD_GAP_PX
|
||||
const scrollParent = findScrollableAncestor(field)
|
||||
|
||||
if (rect.bottom > visibleBottom) {
|
||||
const delta = rect.bottom - visibleBottom
|
||||
if (scrollParent) {
|
||||
scrollParent.scrollTop += delta
|
||||
} else {
|
||||
window.scrollBy({top: delta, left: 0, behavior: 'auto'})
|
||||
}
|
||||
}
|
||||
|
||||
if (rect.top < KEYBOARD_GAP_PX && scrollParent) {
|
||||
scrollParent.scrollTop += rect.top - KEYBOARD_GAP_PX
|
||||
}
|
||||
|
||||
field.scrollIntoView({block: 'nearest', inline: 'nearest', behavior: 'auto'})
|
||||
}
|
||||
|
||||
function scheduleEnsureVisible(field: HTMLElement) {
|
||||
SCROLL_RETRY_MS.forEach((delay) => {
|
||||
window.setTimeout(() => {
|
||||
const active = resolveEditableTarget(document.activeElement)
|
||||
if (!active || active !== field) return
|
||||
ensureFieldVisible(field)
|
||||
}, delay)
|
||||
})
|
||||
}
|
||||
|
||||
function onFocusIn(event: FocusEvent) {
|
||||
if (!isMobileLayout()) return
|
||||
|
||||
const field = resolveEditableTarget(event.target)
|
||||
if (!field) return
|
||||
|
||||
activeField = field
|
||||
window.clearTimeout(blurTimer)
|
||||
scheduleEnsureVisible(field)
|
||||
}
|
||||
|
||||
function onFocusOut() {
|
||||
window.clearTimeout(blurTimer)
|
||||
blurTimer = window.setTimeout(() => {
|
||||
const next = resolveEditableTarget(document.activeElement)
|
||||
activeField = next
|
||||
|
||||
if (!next) {
|
||||
syncViewportVars(false)
|
||||
return
|
||||
}
|
||||
|
||||
syncViewportVars(true)
|
||||
scheduleEnsureVisible(next)
|
||||
}, 120)
|
||||
}
|
||||
|
||||
function onViewportChange() {
|
||||
if (!isMobileLayout()) return
|
||||
|
||||
syncViewportVars(Boolean(activeField))
|
||||
|
||||
const active = resolveEditableTarget(document.activeElement) ?? activeField
|
||||
if (!active) return
|
||||
|
||||
activeField = active
|
||||
ensureFieldVisible(active)
|
||||
}
|
||||
|
||||
/** موبایل: با باز شدن کیبورد، فیلد فوکوسشده بالای کیبورد دیده شود. */
|
||||
export function initMobileInputKeyboardScroll() {
|
||||
if (typeof window === 'undefined' || started) return
|
||||
started = true
|
||||
|
||||
document.addEventListener('focusin', onFocusIn, true)
|
||||
document.addEventListener('focusout', onFocusOut, true)
|
||||
window.visualViewport?.addEventListener('resize', onViewportChange, {passive: true})
|
||||
window.visualViewport?.addEventListener('scroll', onViewportChange, {passive: true})
|
||||
|
||||
if (import.meta.hot) {
|
||||
import.meta.hot.dispose(() => {
|
||||
started = false
|
||||
document.removeEventListener('focusin', onFocusIn, true)
|
||||
document.removeEventListener('focusout', onFocusOut, true)
|
||||
window.visualViewport?.removeEventListener('resize', onViewportChange)
|
||||
window.visualViewport?.removeEventListener('scroll', onViewportChange)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -56,19 +56,13 @@ export function parseDecimalInput(
|
||||
return Number(normalized)
|
||||
}
|
||||
|
||||
export function shouldNormalizeInputDigits(options: {
|
||||
export function shouldNormalizeInputDigits(_options?: {
|
||||
isPassword?: boolean
|
||||
type?: string
|
||||
inputmode?: string
|
||||
}): boolean {
|
||||
if (options.isPassword) {
|
||||
return false
|
||||
}
|
||||
if (options.type === 'price' || options.type === 'number') {
|
||||
return true
|
||||
}
|
||||
const mode = String(options.inputmode ?? '').trim().toLowerCase()
|
||||
return mode === 'numeric' || mode === 'decimal' || mode === 'number'
|
||||
// همیشه ارقام فارسی/عربی → انگلیسی (لاگین، گرم، تعداد، مظنه، …)
|
||||
return true
|
||||
}
|
||||
|
||||
/** فیلدهای وزن/مبلغ/عدد اعشاری که باید `/` را ممیز بگیرند */
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
shouldUsePricePolling,
|
||||
} from '@/utils/priceSocketState'
|
||||
import { applyBoardSpecialToLastPayload } from '@/utils/specialPricing'
|
||||
import { useSettingsStore, type AppSetting } from '@/store/settingsStore'
|
||||
|
||||
const LAST_INTERVAL_MS = 10000
|
||||
|
||||
@@ -16,10 +17,21 @@ let lastSubscribers = 0
|
||||
|
||||
export const price = ref<Price>()
|
||||
export const lastPrice = ref<Price>()
|
||||
/** حداقل یک بار تلاش برای گرفتن مظنه تمام شده (موفق یا ناموفق) */
|
||||
export const lastPriceReady = ref(false)
|
||||
/**
|
||||
* بعد از اولین پاسخ خالی/no_quote، چند لحظه صبر میکنیم تا تیک SSE/زنده برسد
|
||||
* و «مظنه در دسترس نیست» زودهنگام نشان داده نشود.
|
||||
*/
|
||||
export const lastPriceSettleGeneration = ref(0)
|
||||
export const olderPrice = ref<number | null>(null)
|
||||
|
||||
const QUOTE_ABSENCE_SETTLE_MS = 2500
|
||||
|
||||
let lastPriceSourceAt = 0
|
||||
let consecutivePriceFetchFailures = 0
|
||||
let lastPriceReadyAt = 0
|
||||
let quoteSettleTimer: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
/** buy/sell نمایش و معامله — همان buy/sell/price_last از /api/price/last */
|
||||
export function getTradeBuyPrice(p?: Price | null) {
|
||||
@@ -47,13 +59,77 @@ function hasValidPricePayload(data?: Price | null): boolean {
|
||||
)
|
||||
}
|
||||
|
||||
function clearQuoteSettleTimer() {
|
||||
if (quoteSettleTimer) {
|
||||
clearTimeout(quoteSettleTimer)
|
||||
quoteSettleTimer = undefined
|
||||
}
|
||||
}
|
||||
|
||||
function bumpQuoteSettle() {
|
||||
lastPriceSettleGeneration.value += 1
|
||||
}
|
||||
|
||||
function scheduleQuoteAbsenceSettle() {
|
||||
clearQuoteSettleTimer()
|
||||
if (hasValidPricePayload(lastPrice.value) || lastPrice.value?.status === 'closed') {
|
||||
bumpQuoteSettle()
|
||||
return
|
||||
}
|
||||
const elapsed = lastPriceReadyAt > 0 ? Date.now() - lastPriceReadyAt : 0
|
||||
const wait = Math.max(0, QUOTE_ABSENCE_SETTLE_MS - elapsed)
|
||||
quoteSettleTimer = setTimeout(() => {
|
||||
quoteSettleTimer = undefined
|
||||
bumpQuoteSettle()
|
||||
}, wait)
|
||||
}
|
||||
|
||||
function markLastPriceReady() {
|
||||
if (!lastPriceReady.value) {
|
||||
lastPriceReadyAt = Date.now()
|
||||
}
|
||||
lastPriceReady.value = true
|
||||
scheduleQuoteAbsenceSettle()
|
||||
}
|
||||
|
||||
/** قیمت آمده، بسته قطعی است، یا پنجرهٔ انتظارِ مظنه خالی تمام شده */
|
||||
export function isLastPriceAbsenceSettled(): boolean {
|
||||
void lastPriceSettleGeneration.value
|
||||
if (!lastPriceReady.value) return false
|
||||
if (hasValidPricePayload(lastPrice.value)) return true
|
||||
if (lastPrice.value?.status === 'closed') return true
|
||||
if (lastPriceReadyAt <= 0) return false
|
||||
return Date.now() - lastPriceReadyAt >= QUOTE_ABSENCE_SETTLE_MS
|
||||
}
|
||||
|
||||
function applyTradingHoursSettingsPatch(data: unknown) {
|
||||
if (!data || typeof data !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
const patch = (data as { settings_patch?: unknown }).settings_patch
|
||||
if (!Array.isArray(patch) || patch.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
useSettingsStore().mergeSettings(patch as AppSetting[])
|
||||
}
|
||||
|
||||
export function markPriceSourceReceived() {
|
||||
lastPriceSourceAt = Date.now()
|
||||
consecutivePriceFetchFailures = 0
|
||||
void import('@/utils/priceSocket').then(({ clearPriceNetworkAlert }) => {
|
||||
clearPriceNetworkAlert()
|
||||
})
|
||||
}
|
||||
|
||||
export function markPriceSourceFetchFailed() {
|
||||
consecutivePriceFetchFailures += 1
|
||||
if (consecutivePriceFetchFailures >= 2) {
|
||||
void import('@/utils/priceSocket').then(({ notifyPriceLastFetchFailed }) => {
|
||||
notifyPriceLastFetchFailed()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function hasRecentPriceFromSource(maxAgeMs = 45000): boolean {
|
||||
@@ -158,19 +234,31 @@ export async function getLastPrices(): Promise<boolean> {
|
||||
console.log(error)
|
||||
markPriceSourceFetchFailed()
|
||||
return false
|
||||
} finally {
|
||||
markLastPriceReady()
|
||||
}
|
||||
}
|
||||
|
||||
export function applyLastPricePayload(dataLast: Price) {
|
||||
applyTradingHoursSettingsPatch(dataLast)
|
||||
const normalized = normalizePriceResponse(applyBoardSpecialToLastPayload(dataLast as any) as Price)
|
||||
const nextBuy = getTradeBuyPrice(normalized)
|
||||
const prevBuy = getTradeBuyPrice(lastPrice.value)
|
||||
const nextValid = hasValidPricePayload(normalized)
|
||||
const prevValid = hasValidPricePayload(lastPrice.value)
|
||||
|
||||
// قطع فید / no_quote خالی — قیمت فعلی را پاک نکن؛ فقط closed قطعی اجازهٔ صفر شدن دارد
|
||||
if (!nextValid && prevValid && normalized.status !== 'closed') {
|
||||
markLastPriceReady()
|
||||
return
|
||||
}
|
||||
|
||||
if (prevBuy > 0 && nextBuy > 0 && prevBuy !== nextBuy) {
|
||||
olderPrice.value = prevBuy
|
||||
}
|
||||
|
||||
lastPrice.value = normalized
|
||||
markLastPriceReady()
|
||||
price.value = {
|
||||
...normalized,
|
||||
buy: nextBuy,
|
||||
|
||||
@@ -3,10 +3,14 @@ import type { Product } from '@/models/products'
|
||||
import { Modal } from 'ant-design-vue'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
import { applyProductsListFromStream } from '@/utils/productStreamBridge'
|
||||
import { syncCatalogFromStream } from '@/composables/useProductsCatalog'
|
||||
import {
|
||||
priceSocketConnected,
|
||||
priceStreamConnectingSince,
|
||||
priceStreamLifecycle,
|
||||
priceStreamList,
|
||||
priceStreamProducts,
|
||||
priceStreamServerUnix,
|
||||
priceWssEnabled,
|
||||
} from '@/utils/priceSocketState'
|
||||
import {
|
||||
@@ -24,16 +28,104 @@ export {
|
||||
|
||||
const RECONNECT_BASE_MS = 3000
|
||||
const RECONNECT_MAX_MS = 30000
|
||||
const FAILURES_BEFORE_ALERT = 4
|
||||
/** چند بار خطای پشتسرهم /api/price/last قبل از نمایش مدال */
|
||||
const LAST_FETCH_FAILURES_BEFORE_ALERT = 2
|
||||
const ALERT_COOLDOWN_MS = 5 * 60 * 1000
|
||||
const FALLBACK_POLL_INTERVAL_MS = 10000
|
||||
const PRICE_SOURCE_STALE_MS_MOBILE = 50000
|
||||
const PRICE_SOURCE_STALE_MS_DESKTOP = 35000
|
||||
/** بدون event قیمت؛ ping هر ۲۰ث از سرور activity را تازه میکند */
|
||||
const STALE_STREAM_MS = 120000
|
||||
const FALLBACK_POLL_DELAY_MS = 2500
|
||||
const STREAM_CONNECTING = 0
|
||||
const STREAM_OPEN = 1
|
||||
const STREAM_CLOSED = 2
|
||||
|
||||
let eventSource: EventSource | null = null
|
||||
class AuthPriceStream extends EventTarget {
|
||||
readyState = STREAM_CONNECTING
|
||||
onopen: (() => void) | null = null
|
||||
onerror: (() => void) | null = null
|
||||
onmessage: (() => void) | null = null
|
||||
private abort = new AbortController()
|
||||
|
||||
constructor(url: string, tvKey = '') {
|
||||
super()
|
||||
void this.start(url, tvKey)
|
||||
}
|
||||
|
||||
close() {
|
||||
this.readyState = STREAM_CLOSED
|
||||
this.abort.abort()
|
||||
}
|
||||
|
||||
private async start(url: string, tvKey = '') {
|
||||
try {
|
||||
const headers: Record<string, string> = { Accept: 'text/event-stream' }
|
||||
if (tvKey) headers['X-Tv-Key'] = tvKey
|
||||
const response = await fetch(url, {
|
||||
headers,
|
||||
cache: 'no-store',
|
||||
signal: this.abort.signal,
|
||||
})
|
||||
|
||||
if (!response.ok || !response.body) {
|
||||
this.readyState = STREAM_CLOSED
|
||||
this.onerror?.()
|
||||
return
|
||||
}
|
||||
|
||||
this.readyState = STREAM_OPEN
|
||||
this.onopen?.()
|
||||
|
||||
const reader = response.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
let buffer = ''
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) {
|
||||
break
|
||||
}
|
||||
buffer += decoder.decode(value, { stream: true })
|
||||
buffer = this.flushSse(buffer)
|
||||
}
|
||||
|
||||
this.readyState = STREAM_CLOSED
|
||||
this.onerror?.()
|
||||
} catch {
|
||||
if (this.abort.signal.aborted) {
|
||||
return
|
||||
}
|
||||
this.readyState = STREAM_CLOSED
|
||||
this.onerror?.()
|
||||
}
|
||||
}
|
||||
|
||||
private flushSse(buffer: string): string {
|
||||
const blocks = buffer.split('\n\n')
|
||||
const rest = blocks.pop() ?? ''
|
||||
|
||||
for (const block of blocks) {
|
||||
let event = 'message'
|
||||
const data: string[] = []
|
||||
for (const line of block.split('\n')) {
|
||||
if (line.startsWith('event:')) {
|
||||
event = line.slice(6).trim()
|
||||
} else if (line.startsWith('data:')) {
|
||||
data.push(line.slice(5).trimStart())
|
||||
}
|
||||
}
|
||||
this.dispatchEvent(new MessageEvent(event, { data: data.join('\n') }))
|
||||
this.onmessage?.()
|
||||
}
|
||||
|
||||
return rest
|
||||
}
|
||||
}
|
||||
|
||||
let eventSource: AuthPriceStream | null = null
|
||||
let subscribers = 0
|
||||
let tvStreamKey: string | null = null
|
||||
let stopped = false
|
||||
let getSetting: ((key: string) => unknown) | null = null
|
||||
let reconnectTimer: ReturnType<typeof setTimeout> | undefined
|
||||
@@ -131,7 +223,7 @@ function startStaleCheck() {
|
||||
stopped
|
||||
|| subscribers <= 0
|
||||
|| !eventSource
|
||||
|| eventSource.readyState !== EventSource.OPEN
|
||||
|| eventSource.readyState !== STREAM_OPEN
|
||||
) {
|
||||
return
|
||||
}
|
||||
@@ -184,31 +276,40 @@ function scheduleFallbackPoll() {
|
||||
}, FALLBACK_POLL_DELAY_MS)
|
||||
}
|
||||
|
||||
export function clearPriceNetworkAlert() {
|
||||
networkAlertOpen = false
|
||||
pendingPriceAlert = false
|
||||
}
|
||||
|
||||
/** وقتی /api/price/last خطا میدهد (از polling عادی یا fallback) */
|
||||
export function notifyPriceLastFetchFailed() {
|
||||
void maybeShowNetworkAlert()
|
||||
}
|
||||
|
||||
async function runFallbackPoll() {
|
||||
if (!priceWssEnabled.value || priceSocketConnected.value) {
|
||||
if (tvStreamKey || !priceWssEnabled.value || priceSocketConnected.value) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { getLastPrices, hasRecentPriceFromSource, markPriceSourceFetchFailed } = await import(
|
||||
'@/utils/price'
|
||||
)
|
||||
const { getLastPrices, hasRecentPriceFromSource } = await import('@/utils/price')
|
||||
const { refreshProductsPageData } = await import(
|
||||
'@/views/base/products/composables/useProductsPageData'
|
||||
)
|
||||
|
||||
const [lastResult] = await Promise.allSettled([
|
||||
const [priceResult] = await Promise.allSettled([
|
||||
getLastPrices(),
|
||||
refreshProductsPageData(),
|
||||
])
|
||||
|
||||
const priceOk =
|
||||
lastResult.status === 'fulfilled'
|
||||
&& lastResult.value === true
|
||||
priceResult.status === 'fulfilled'
|
||||
&& priceResult.value === true
|
||||
&& hasRecentPriceFromSource(getPriceSourceStaleMs())
|
||||
|
||||
if (!priceOk) {
|
||||
markPriceSourceFetchFailed()
|
||||
if (priceOk) {
|
||||
clearPriceNetworkAlert()
|
||||
return
|
||||
}
|
||||
|
||||
void maybeShowNetworkAlert()
|
||||
@@ -237,25 +338,7 @@ async function isRealPriceOutage(): Promise<boolean> {
|
||||
return false
|
||||
}
|
||||
|
||||
const fetchFailures = consecutivePriceSourceFailures()
|
||||
|
||||
if (fetchFailures >= 2) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!priceSocketConnected.value && fetchFailures >= 1 && reconnectAttempt >= 2) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!isMobileDevice() && !navigator.onLine && fetchFailures >= 1) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!isMobileDevice() && reconnectAttempt >= FAILURES_BEFORE_ALERT) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return consecutivePriceSourceFailures() >= LAST_FETCH_FAILURES_BEFORE_ALERT
|
||||
}
|
||||
|
||||
function showNetworkAlert() {
|
||||
@@ -316,7 +399,6 @@ function scheduleReconnect() {
|
||||
reconnectTimer = setTimeout(() => {
|
||||
reconnectAttempt += 1
|
||||
connect()
|
||||
maybeShowNetworkAlert()
|
||||
}, delay)
|
||||
}
|
||||
|
||||
@@ -325,13 +407,61 @@ async function applyLastFromStream(last: Price) {
|
||||
applyLastPricePayload(last)
|
||||
}
|
||||
|
||||
async function applySettingsFromStream(payload: unknown) {
|
||||
const items = Array.isArray(payload)
|
||||
? payload
|
||||
: payload && typeof payload === 'object' && Array.isArray((payload as { items?: unknown }).items)
|
||||
? (payload as { items: unknown[] }).items
|
||||
: null
|
||||
if (!items?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const { touchStoreHoursSettings } = await import('@/utils/storeHours')
|
||||
useSettingsStore().mergeSettings(items as Array<{ key?: string; value?: unknown }>)
|
||||
touchStoreHoursSettings()
|
||||
} catch (error) {
|
||||
console.warn('Settings SSE apply failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
function handleLastPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
const last = applyBoardSpecialToLastPayload(payload as Price)
|
||||
if (last.price_last == null && last.price == null && last.buy == null) {
|
||||
const raw = payload as Price & { settings_patch?: unknown }
|
||||
const last = applyBoardSpecialToLastPayload(raw)
|
||||
const hasDisplayable =
|
||||
Number(last.buy ?? 0) > 0
|
||||
|| Number(last.sell ?? 0) > 0
|
||||
|| Number(last.price_last ?? 0) > 0
|
||||
|| Number(last.price ?? 0) > 0
|
||||
const hasStatus = last.status != null || typeof last.closed === 'boolean'
|
||||
|
||||
if (!hasDisplayable && !hasStatus) {
|
||||
if (Array.isArray(raw.settings_patch) && raw.settings_patch.length) {
|
||||
touchStreamActivity()
|
||||
void applySettingsFromStream(raw.settings_patch)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SSE گاهی last خالی/no_quote میفرستد؛ قیمت معتبر فعلی را پاک نکن
|
||||
if (!hasDisplayable) {
|
||||
if (Array.isArray(raw.settings_patch) && raw.settings_patch.length) {
|
||||
touchStreamActivity()
|
||||
void applySettingsFromStream(raw.settings_patch)
|
||||
}
|
||||
void import('@/utils/price').then(({ getTradeBuyPrice, lastPrice }) => {
|
||||
const keepCurrent =
|
||||
getTradeBuyPrice(lastPrice.value) > 0 && last.status !== 'closed'
|
||||
touchStreamActivity()
|
||||
if (keepCurrent) return
|
||||
void applyLastFromStream(last)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -339,13 +469,45 @@ function handleLastPayload(payload: unknown) {
|
||||
void applyLastFromStream(last)
|
||||
}
|
||||
|
||||
function handleSettingsPayload(payload: unknown) {
|
||||
touchStreamActivity()
|
||||
void applySettingsFromStream(payload)
|
||||
}
|
||||
|
||||
function coerceStreamProductList(payload: unknown): Product[] {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload as Product[]
|
||||
}
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return []
|
||||
}
|
||||
const root = payload as Record<string, unknown>
|
||||
if (Array.isArray(root.data)) return root.data as Product[]
|
||||
if (Array.isArray(root.products)) return root.products as Product[]
|
||||
if (Array.isArray(root.items)) return root.items as Product[]
|
||||
if (root.id != null && ('price' in root || 'title' in root || 'group_type' in root)) {
|
||||
return [payload as Product]
|
||||
}
|
||||
const values = Object.values(root)
|
||||
if (
|
||||
values.length > 0 &&
|
||||
values.every((item) => item && typeof item === 'object' && 'id' in (item as object))
|
||||
) {
|
||||
return values as Product[]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function handleListPayload(payload: unknown) {
|
||||
if (!Array.isArray(payload) || !payload.length) {
|
||||
const products = coerceStreamProductList(payload)
|
||||
if (!products.length) {
|
||||
return
|
||||
}
|
||||
|
||||
touchStreamActivity()
|
||||
applyProductsListFromStream(payload as Product[])
|
||||
priceStreamList.value = products as Array<Record<string, unknown>>
|
||||
syncCatalogFromStream(products)
|
||||
applyProductsListFromStream(products)
|
||||
}
|
||||
|
||||
function handleAppNotificationPayload(payload: unknown) {
|
||||
@@ -384,7 +546,7 @@ async function applyUnreadCountFromStreamPayload(payload: Record<string, unknown
|
||||
}
|
||||
}
|
||||
|
||||
function bindStreamEvents(source: EventSource) {
|
||||
function bindStreamEvents(source: AuthPriceStream) {
|
||||
source.addEventListener('last', (event) => {
|
||||
try {
|
||||
handleLastPayload(JSON.parse(event.data))
|
||||
@@ -393,6 +555,14 @@ function bindStreamEvents(source: EventSource) {
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('settings', (event) => {
|
||||
try {
|
||||
handleSettingsPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('Price SSE settings parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('list', (event) => {
|
||||
try {
|
||||
handleListPayload(JSON.parse(event.data))
|
||||
@@ -401,6 +571,31 @@ function bindStreamEvents(source: EventSource) {
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('products', (event) => {
|
||||
try {
|
||||
const rows = JSON.parse(event.data)
|
||||
if (Array.isArray(rows) && rows.length) {
|
||||
touchStreamActivity()
|
||||
priceStreamProducts.value = rows
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Price SSE products parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('time', (event) => {
|
||||
try {
|
||||
const payload = JSON.parse(event.data) as { unix?: number }
|
||||
const unix = Number(payload?.unix)
|
||||
if (unix > 0) {
|
||||
touchStreamActivity()
|
||||
priceStreamServerUnix.value = unix
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Price SSE time parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('app_notification', (event) => {
|
||||
try {
|
||||
handleAppNotificationPayload(JSON.parse(event.data))
|
||||
@@ -425,6 +620,16 @@ function bindStreamEvents(source: EventSource) {
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('colleague_order', (event) => {
|
||||
try {
|
||||
void import('@/composables/useColleagueOrderWait').then(({ emitColleagueOrderFromStream }) => {
|
||||
emitColleagueOrderFromStream(JSON.parse(event.data))
|
||||
})
|
||||
} catch (error) {
|
||||
console.warn('Colleague order SSE parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('ping', () => {
|
||||
touchStreamActivity()
|
||||
})
|
||||
@@ -475,7 +680,7 @@ function connect() {
|
||||
|
||||
if (eventSource) {
|
||||
const state = eventSource.readyState
|
||||
if (state === EventSource.OPEN || state === EventSource.CONNECTING) {
|
||||
if (state === STREAM_OPEN || state === STREAM_CONNECTING) {
|
||||
return
|
||||
}
|
||||
disconnectSourceOnly()
|
||||
@@ -484,7 +689,7 @@ function connect() {
|
||||
markConnectingLifecycle()
|
||||
|
||||
try {
|
||||
eventSource = new EventSource(url)
|
||||
eventSource = new AuthPriceStream(url, tvStreamKey || '')
|
||||
} catch (error) {
|
||||
console.warn('Price SSE connect failed', error)
|
||||
handleStreamLost()
|
||||
@@ -507,7 +712,7 @@ function connect() {
|
||||
|
||||
eventSource.onerror = () => {
|
||||
const state = eventSource?.readyState
|
||||
if (state === EventSource.OPEN || state === EventSource.CONNECTING) {
|
||||
if (state === STREAM_OPEN || state === STREAM_CONNECTING) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -569,6 +774,22 @@ function unbindBrowserNetworkListeners() {
|
||||
window.removeEventListener('offline', onBrowserOffline)
|
||||
}
|
||||
|
||||
export function startTvPriceStream(
|
||||
settingGetter: (key: string) => unknown,
|
||||
key: string,
|
||||
) {
|
||||
const secret = key.trim()
|
||||
if (!secret) return
|
||||
tvStreamKey = secret
|
||||
startPriceSocket(settingGetter)
|
||||
}
|
||||
|
||||
export function stopTvPriceStream() {
|
||||
if (!tvStreamKey) return
|
||||
tvStreamKey = null
|
||||
stopPriceSocket()
|
||||
}
|
||||
|
||||
export function startPriceSocket(settingGetter: (key: string) => unknown) {
|
||||
getSetting = settingGetter
|
||||
subscribers += 1
|
||||
@@ -621,7 +842,7 @@ function onVisibilityChange() {
|
||||
void maybeShowNetworkAlert()
|
||||
}
|
||||
|
||||
if (!eventSource || eventSource.readyState !== EventSource.OPEN) {
|
||||
if (!eventSource || eventSource.readyState !== STREAM_OPEN) {
|
||||
forceReconnect()
|
||||
}
|
||||
}
|
||||
@@ -631,7 +852,7 @@ function onPageShow(event: PageTransitionEvent) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.persisted || !eventSource || eventSource.readyState !== EventSource.OPEN) {
|
||||
if (event.persisted || !eventSource || eventSource.readyState !== STREAM_OPEN) {
|
||||
reconnectAttempt = 0
|
||||
networkAlertOpen = false
|
||||
forceReconnect()
|
||||
|
||||
@@ -9,6 +9,15 @@ export const priceStreamLifecycle = ref<PriceStreamLifecycle>('idle')
|
||||
|
||||
export const priceStreamConnectingSince = ref(0)
|
||||
|
||||
/** آخرین رویداد list استریم */
|
||||
export const priceStreamList = ref<Array<Record<string, unknown>>>([])
|
||||
|
||||
/** آخرین بدنهٔ tv/products که از SSE آمده */
|
||||
export const priceStreamProducts = ref<Array<Record<string, unknown>>>([])
|
||||
|
||||
/** unix ساعت سرور از رویداد time استریم */
|
||||
export const priceStreamServerUnix = ref(0)
|
||||
|
||||
const CONNECTING_POLL_AFTER_MS = 8000
|
||||
|
||||
export function shouldUsePricePolling(): boolean {
|
||||
|
||||
@@ -3,6 +3,13 @@ export type ProductCashFeeSource = {
|
||||
cash_fee_sell?: number | null
|
||||
cash_fee_buy_is_percent?: boolean | null
|
||||
cash_fee_sell_is_percent?: boolean | null
|
||||
special_profit_buy?: number | null
|
||||
special_profit_sell?: number | null
|
||||
}
|
||||
|
||||
export type ProductCashFeeOptions = {
|
||||
/** پیشفرض true. اگر مظنهٔ last از قبل special_pricing دارد باید false باشد. */
|
||||
includeSpecial?: boolean
|
||||
}
|
||||
|
||||
/** 0.5 => 0.5% ، 5 => 5% — همیشه عدد درصد */
|
||||
@@ -42,23 +49,37 @@ export function resolveProductCashFeeRial(
|
||||
return Math.round(Math.abs(base * resolveCashFeePercentRatio(raw)))
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
export function resolveProductCashFeeBuyRial(
|
||||
product: ProductCashFeeSource,
|
||||
basePriceRial: number,
|
||||
options?: ProductCashFeeOptions,
|
||||
) {
|
||||
const baseFee = resolveProductCashFeeRial(
|
||||
product.cash_fee_buy,
|
||||
product.cash_fee_buy_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
const special = Number((product as any).special_profit_buy ?? 0)
|
||||
if (options?.includeSpecial === false) {
|
||||
return baseFee
|
||||
}
|
||||
const special = Number(product.special_profit_buy ?? 0)
|
||||
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
export function resolveProductCashFeeSellRial(
|
||||
product: ProductCashFeeSource,
|
||||
basePriceRial: number,
|
||||
options?: ProductCashFeeOptions,
|
||||
) {
|
||||
const baseFee = resolveProductCashFeeRial(
|
||||
product.cash_fee_sell,
|
||||
product.cash_fee_sell_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
const special = Number((product as any).special_profit_sell ?? 0)
|
||||
if (options?.includeSpecial === false) {
|
||||
return baseFee
|
||||
}
|
||||
const special = Number(product.special_profit_sell ?? 0)
|
||||
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
/** دستهبندی یکسان محصول — همتراز با khaneghi_user */
|
||||
export const PRODUCT_CATEGORY_ABSHODE = 'آبشده'
|
||||
|
||||
@@ -49,12 +51,31 @@ export function resolveMeltedPriceSource(product?: {
|
||||
return 'app'
|
||||
}
|
||||
|
||||
/** قیمت از همکار: قیمت هر عدد، نه هر گرم */
|
||||
export function isColleaguePriceProduct(product?: {
|
||||
colleague_price?: boolean | number | null
|
||||
colleague_price_product_id?: string | number | null
|
||||
} | null) {
|
||||
if (!product) {
|
||||
return false
|
||||
}
|
||||
const flagged = product.colleague_price === true || Number(product.colleague_price) === 1
|
||||
if (!flagged) {
|
||||
return false
|
||||
}
|
||||
if (product.colleague_price_product_id === undefined) {
|
||||
return true
|
||||
}
|
||||
return Number(product.colleague_price_product_id) > 0
|
||||
}
|
||||
|
||||
/** محصول با پرچم صریح «قیمت اپ» */
|
||||
export function isAppPriceProduct(product?: {
|
||||
app_price?: boolean | number | null
|
||||
reading_method?: string | null
|
||||
colleague_price?: boolean | number | null
|
||||
} | null) {
|
||||
if (!product || product.reading_method) {
|
||||
if (!product || product.reading_method || isColleaguePriceProduct(product)) {
|
||||
return false
|
||||
}
|
||||
return product.app_price === true || Number(product.app_price) === 1
|
||||
@@ -66,8 +87,9 @@ export function isMeltedProductUsingAppPrice(product?: {
|
||||
direct_price?: number | null
|
||||
trade_by_quantity?: boolean | number | null
|
||||
price?: number | null
|
||||
colleague_price?: boolean | number | null
|
||||
} | null) {
|
||||
if (!product || resolveMeltedPriceSource(product) !== 'app') {
|
||||
if (!product || isColleaguePriceProduct(product) || resolveMeltedPriceSource(product) !== 'app') {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -85,3 +107,32 @@ export function isMeltedProductUsingAppPrice(product?: {
|
||||
|
||||
return Number(product.price ?? 0) <= 0
|
||||
}
|
||||
|
||||
/** آبشده موجودی انبار فروشگاهی ندارد */
|
||||
export function productTracksStoreInventory(product?: { group_type?: string | null } | null) {
|
||||
return !isMeltedTradeGroup(product?.group_type)
|
||||
}
|
||||
|
||||
export function isProductOutOfStock(product?: {
|
||||
group_type?: string | null
|
||||
inventory?: number | null
|
||||
} | null) {
|
||||
if (!product || !productTracksStoreInventory(product)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (product.inventory === undefined || product.inventory === null) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
const settings = useSettingsStore()
|
||||
if (settings.loaded && !settings.isSettingTruthy('is_store')) {
|
||||
return false
|
||||
}
|
||||
} catch {
|
||||
/* تنظیمات در دسترس نیست — فقط روی خود فیلد موجودی تکیه کن */
|
||||
}
|
||||
|
||||
return Number(product.inventory) <= 0
|
||||
}
|
||||
|
||||
@@ -4,9 +4,13 @@ import mokaabImg from '@/assets/img/mokaabImg.svg'
|
||||
import sekkeImg from '@/assets/img/sekkeImg.svg'
|
||||
import parsianImg from '@/assets/img/parsianImg.svg'
|
||||
import venusImg from '@/assets/img/venousImg.svg'
|
||||
import { getConfigApp } from '@/utils/config'
|
||||
|
||||
export type ProductImageSource = {
|
||||
file?: { src?: string | null } | null
|
||||
file?: { id?: number | null; src?: string | null; full_src?: string | null; url?: string | null } | null
|
||||
file_id?: number | string | null
|
||||
img?: string | null
|
||||
image?: string | null
|
||||
group_type?: string | null
|
||||
} | null | undefined
|
||||
|
||||
@@ -16,6 +20,63 @@ function isUsableImageSrc(src?: string | null): boolean {
|
||||
return value !== '' && value !== 'null' && value !== 'undefined'
|
||||
}
|
||||
|
||||
function absolutizeImageUrl(url: string): string {
|
||||
const normalized = normalizePublicFileUrl(url)
|
||||
return normalized ?? url
|
||||
}
|
||||
|
||||
function projectBase(): string {
|
||||
return String(getConfigApp('node_server') || '').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
function storageRelativePath(value: string): string | null {
|
||||
const match = value.match(/(?:^|\/)(storage\/.+)$/i)
|
||||
return match ? match[1].replace(/^\/+/, '') : null
|
||||
}
|
||||
|
||||
function joinProjectUrl(relative: string): string {
|
||||
const path = relative.replace(/^\//, '')
|
||||
let base = projectBase()
|
||||
if (!base && typeof window !== 'undefined') {
|
||||
base = `${window.location.origin}/server`
|
||||
}
|
||||
if (!base) {
|
||||
return `/server/${path}`
|
||||
}
|
||||
base = base.replace(/\/$/, '')
|
||||
if (path.startsWith('storage/') && !/\/(server|api)(\/|$)/i.test(base)) {
|
||||
base = `${base}/server`
|
||||
}
|
||||
let url = `${base}/${path}`
|
||||
if (typeof window !== 'undefined' && window.location.protocol === 'https:') {
|
||||
url = url.replace(/^http:\/\//i, 'https://')
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
export function normalizePublicFileUrl(raw?: string | null): string | null {
|
||||
if (raw == null) return null
|
||||
const trimmed = String(raw).trim()
|
||||
if (!trimmed || trimmed.toLowerCase() === 'null' || trimmed.toLowerCase() === 'undefined') {
|
||||
return null
|
||||
}
|
||||
if (/^(data:|blob:)/i.test(trimmed)) return trimmed
|
||||
|
||||
const storagePath = storageRelativePath(trimmed)
|
||||
if (storagePath) {
|
||||
return joinProjectUrl(storagePath)
|
||||
}
|
||||
|
||||
if (/^https?:\/\//i.test(trimmed)) {
|
||||
if (typeof window !== 'undefined' && window.location.protocol === 'https:') {
|
||||
return trimmed.replace(/^http:\/\//i, 'https://')
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
|
||||
return joinProjectUrl(trimmed)
|
||||
}
|
||||
|
||||
export function getProductFallbackImage(product?: ProductImageSource): string {
|
||||
const type = (product?.group_type ?? '').trim()
|
||||
if (!type) return defaultImg
|
||||
@@ -43,9 +104,14 @@ export function getProductFallbackImage(product?: ProductImageSource): string {
|
||||
}
|
||||
|
||||
export function resolveProductImageSrc(product?: ProductImageSource): string {
|
||||
const remoteSrc = product?.file?.src
|
||||
const remoteSrc = product?.file?.full_src || product?.file?.url || product?.file?.src || product?.image || product?.img
|
||||
if (isUsableImageSrc(remoteSrc)) {
|
||||
return remoteSrc!.trim()
|
||||
const url = absolutizeImageUrl(remoteSrc!.trim())
|
||||
const version = product?.file_id ?? product?.file?.id
|
||||
if (version != null && version !== '' && Number(version) > 0 && /^https?:\/\//i.test(url) && !/[?&]v=/.test(url)) {
|
||||
return `${url}${url.includes('?') ? '&' : '?'}v=${encodeURIComponent(String(version))}`
|
||||
}
|
||||
return url
|
||||
}
|
||||
return getProductFallbackImage(product)
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||
import { resolveProductCashFeeBuyRial, resolveProductCashFeeSellRial } from '@/utils/productCashFee'
|
||||
import {
|
||||
isAppPriceProduct,
|
||||
isColleaguePriceProduct,
|
||||
isMeltedProductUsingAppPrice,
|
||||
isMeltedTradeGroup,
|
||||
isMetalCommodityGroup,
|
||||
usesQuantityTrade,
|
||||
} from '@/utils/productCategories'
|
||||
import { isProductTradingHoursOpen } from '@/utils/productTradeOpen'
|
||||
import { lastPriceIncludesSpecial } from '@/utils/specialPricing'
|
||||
|
||||
/**
|
||||
* قیمتگیری محصول — همتراز با khaneghi_user:
|
||||
@@ -22,6 +25,53 @@ function hasReferenceReadingMethod(product: Product): boolean {
|
||||
return Boolean(product.reading_method)
|
||||
}
|
||||
|
||||
/** پایه از buy/sell مظنه آمده — special همانجا اعمال شده و نباید دوباره جمع شود */
|
||||
function productUsesLiveBoardQuote(product: Product, side: 'buy' | 'sell'): boolean {
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
const stored = side === 'sell'
|
||||
? Number(product.sellPrice ?? product.price ?? 0)
|
||||
: Number(product.price ?? 0)
|
||||
if (stored > 0) {
|
||||
return false
|
||||
}
|
||||
const live = side === 'buy' ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
|
||||
return isMeltedTradeGroup(product.group_type) && live > 0
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const live = side === 'buy' ? getTradeBuyPrice(lastPrice.value) : getTradeSellPrice(lastPrice.value)
|
||||
return live > 0
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function cashFeeOptions(product: Product, side: 'buy' | 'sell') {
|
||||
if (lastPriceIncludesSpecial(lastPrice.value) && productUsesLiveBoardQuote(product, side)) {
|
||||
return { includeSpecial: false as const }
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function buyCashFee(product: Product, base: number) {
|
||||
return resolveProductCashFeeBuyRial(product, base, cashFeeOptions(product, 'buy'))
|
||||
}
|
||||
|
||||
function sellCashFee(product: Product, base: number) {
|
||||
return resolveProductCashFeeSellRial(product, base, cashFeeOptions(product, 'sell'))
|
||||
}
|
||||
|
||||
/** قیمت منبع همکار؛ اگر خالی بود آبشده همان مظنهٔ صفحه اصلی را میگیرد */
|
||||
function getColleagueSourcedUnitPrice(product: Product, live: number, apiPrice = Number(product.price ?? 0)): number {
|
||||
if (apiPrice > 0) {
|
||||
return apiPrice
|
||||
}
|
||||
if (isMeltedTradeGroup(product.group_type) && live > 0) {
|
||||
return applyPriceOffsetPercent(live, product.price_offset_percent)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
function hasProductUnitWeight(product?: Product | null) {
|
||||
if (!product || isMeltedTradeGroup(product.group_type)) {
|
||||
return false
|
||||
@@ -30,7 +80,7 @@ function hasProductUnitWeight(product?: Product | null) {
|
||||
}
|
||||
|
||||
function productPriceAmountFactor(product?: Product | null) {
|
||||
if (!product || product.reading_method) {
|
||||
if (!product || product.reading_method || isColleaguePriceProduct(product)) {
|
||||
return 1
|
||||
}
|
||||
if (isAppPriceProduct(product)) {
|
||||
@@ -83,27 +133,18 @@ export function getProductBaseBuyPrice(product?: Product | null): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return getColleagueSourcedUnitPrice(product, getTradeBuyPrice(lastPrice.value))
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const apiPrice = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
|
||||
if (!useLast) {
|
||||
const liveBuy = getTradeBuyPrice(lastPrice.value)
|
||||
if (liveBuy > 0) {
|
||||
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
if (apiPrice > 0) {
|
||||
return apiPrice
|
||||
}
|
||||
|
||||
const liveBuy = getTradeBuyPrice(lastPrice.value)
|
||||
if (liveBuy > 0) {
|
||||
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
|
||||
}
|
||||
|
||||
if (productUsesLastPriceIfZero(product) && Number(product.price ?? 0) > 0) {
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -133,9 +174,13 @@ export function getProductBuyPrice(product?: Product | null): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
const fee = resolveProductCashFeeBuyRial(product, base)
|
||||
const fee = buyCashFee(product, base)
|
||||
const withFee = base + fee
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return withFee
|
||||
}
|
||||
|
||||
if (isAppPriceProduct(product)) {
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
@@ -165,27 +210,22 @@ export function getProductBaseSellPrice(product?: Product | null): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return getColleagueSourcedUnitPrice(
|
||||
product,
|
||||
getTradeSellPrice(lastPrice.value),
|
||||
Number(product.sellPrice ?? product.price ?? 0),
|
||||
)
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
|
||||
const apiPrice = Number(product.price ?? 0)
|
||||
const useLast = productUsesLastPriceIfZero(product)
|
||||
|
||||
if (!useLast) {
|
||||
const liveSell = getTradeSellPrice(lastPrice.value)
|
||||
if (liveSell > 0) {
|
||||
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
if (apiPrice > 0) {
|
||||
return apiPrice
|
||||
}
|
||||
|
||||
const liveSell = getTradeSellPrice(lastPrice.value)
|
||||
if (liveSell > 0) {
|
||||
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
|
||||
}
|
||||
|
||||
if (productUsesLastPriceIfZero(product) && Number(product.price ?? 0) > 0) {
|
||||
return Number(product.price ?? 0)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -212,25 +252,34 @@ export function getProductSellPrice(product?: Product | null): number {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (isColleaguePriceProduct(product)) {
|
||||
return base - sellCashFee(product, base)
|
||||
}
|
||||
|
||||
if (isAppPriceProduct(product)) {
|
||||
const withFee = base - resolveProductCashFeeSellRial(product, base)
|
||||
const withFee = base - sellCashFee(product, base)
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
|
||||
if (isMeltedProductUsingAppPrice(product) || isMeltedTradeGroup(product.group_type)) {
|
||||
return base - resolveProductCashFeeSellRial(product, base)
|
||||
return base - sellCashFee(product, base)
|
||||
}
|
||||
|
||||
if (usesQuantityTrade(product) && hasProductUnitWeight(product)) {
|
||||
const withFee = base - resolveProductCashFeeSellRial(product, base)
|
||||
const withFee = base - sellCashFee(product, base)
|
||||
return withFee * productPriceAmountFactor(product)
|
||||
}
|
||||
|
||||
if (usesQuantityTrade(product)) {
|
||||
return base - resolveProductCashFeeSellRial(product, base)
|
||||
return base - sellCashFee(product, base)
|
||||
}
|
||||
|
||||
return base - resolveProductCashFeeSellRial(product, base)
|
||||
return base - sellCashFee(product, base)
|
||||
}
|
||||
|
||||
/** کارت فروشگاه: قیمت نمایشی صفر → «بدون قیمت» */
|
||||
export function isProductWithoutDisplayPrice(product?: Product | null): boolean {
|
||||
return getProductBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
export function isProductPriceInactive(product?: Product | null): boolean {
|
||||
@@ -238,6 +287,10 @@ export function isProductPriceInactive(product?: Product | null): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
if (!isProductTradingHoursOpen(product)) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (
|
||||
hasReferenceReadingMethod(product)
|
||||
&& !productUsesLastPriceIfZero(product)
|
||||
@@ -249,6 +302,35 @@ export function isProductPriceInactive(product?: Product | null): boolean {
|
||||
return getProductBaseBuyPrice(product) <= 0
|
||||
}
|
||||
|
||||
function tvBuyUnitPrice(product: Product): number {
|
||||
return Number(product.tv_price ?? 0)
|
||||
}
|
||||
|
||||
function tvSellUnitPrice(product: Product): number {
|
||||
return Number(product.tv_sell_price ?? 0)
|
||||
}
|
||||
|
||||
export function getTvProductBuyPrice(product?: Product | null): number {
|
||||
if (!product) {
|
||||
return 0
|
||||
}
|
||||
return tvBuyUnitPrice(product)
|
||||
}
|
||||
|
||||
export function getTvProductSellPrice(product?: Product | null): number {
|
||||
if (!product) {
|
||||
return 0
|
||||
}
|
||||
return tvSellUnitPrice(product)
|
||||
}
|
||||
|
||||
export function isTvProductPriceInactive(product?: Product | null): boolean {
|
||||
if (!product) {
|
||||
return true
|
||||
}
|
||||
return tvBuyUnitPrice(product) <= 0 && tvSellUnitPrice(product) <= 0
|
||||
}
|
||||
|
||||
/**
|
||||
* نمایش محصول در فروشگاه — اولویت با `show` سرور.
|
||||
* آبشدهٔ قیمتاپ با مظنه زنده حتی اگر show هنوز false باشد.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Product } from '@/models/products'
|
||||
import { isOutsideProductActivationWindow } from '@/utils/storeHours'
|
||||
|
||||
type TradeOpenProduct = Pick<Product, 'open_buy' | 'open_sell'> | null | undefined
|
||||
|
||||
@@ -8,12 +9,14 @@ function asBool(value: boolean | number | null | undefined) {
|
||||
|
||||
export function isProductBuyOpen(product: TradeOpenProduct) {
|
||||
if (!product) return true
|
||||
return asBool(product?.open_buy)
|
||||
if (product.open_buy === undefined || product.open_buy === null) return true
|
||||
return asBool(product.open_buy)
|
||||
}
|
||||
|
||||
export function isProductSellOpen(product: TradeOpenProduct) {
|
||||
if (!product) return true
|
||||
return asBool(product?.open_sell)
|
||||
if (product.open_sell === undefined || product.open_sell === null) return true
|
||||
return asBool(product.open_sell)
|
||||
}
|
||||
|
||||
export function isAnyProductTradeOpen(product: TradeOpenProduct) {
|
||||
@@ -24,6 +27,26 @@ export function isProductTradeOpen(product: TradeOpenProduct, isBuy: boolean) {
|
||||
return isBuy ? isProductBuyOpen(product) : isProductSellOpen(product)
|
||||
}
|
||||
|
||||
/** ساعت فعالسازی محصول: بازهٔ auto_open/auto_close، بعد فلگ استریم */
|
||||
export function isProductTradingHoursOpen(
|
||||
product?: {
|
||||
show?: boolean
|
||||
trade_open?: boolean
|
||||
auto_open_at?: string | null
|
||||
auto_close_at?: string | null
|
||||
} | null,
|
||||
) {
|
||||
// روت /gold محصول را prop نمیگیرد؛ نبود محصول یعنی ساعت محصول اعمال نشود (مثل open_buy)
|
||||
if (!product) return true
|
||||
if (isOutsideProductActivationWindow(product)) return false
|
||||
if (typeof product.trade_open === 'boolean') return product.trade_open
|
||||
return product.show === true
|
||||
}
|
||||
|
||||
export function productHoursClosedMessage() {
|
||||
return 'این محصول در حال حاضر خارج از ساعت کاری است.'
|
||||
}
|
||||
|
||||
/** تب اولیه با توجه به query و وضعیت باز/بسته خرید و فروش */
|
||||
export function resolveProductTradeIsBuy(product: TradeOpenProduct, routeState?: string | null) {
|
||||
const wantSell = routeState === 'sell'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
|
||||
export const serviceFeePercentage = ref<number>(0.01)
|
||||
export const serviceFeePercentage = ref<number>(0)
|
||||
|
||||
/**
|
||||
* @deprecated منطق کارمزد دیگر به این کلید وابسته نیست.
|
||||
@@ -25,6 +25,12 @@ export const TRADE_GRAM_STORAGE_DECIMALS = 10
|
||||
/** حداکثر اعشار نمایش به کاربر در اپ */
|
||||
export const TRADE_GRAM_DISPLAY_DECIMALS = 8
|
||||
|
||||
/** اعشار فیلد گرم وقتی از ریال تبدیل میشود (فقط نمایش همان فیلد؛ مقدار دقیق جداست) */
|
||||
export const TRADE_GRAM_INPUT_DECIMALS = 3
|
||||
|
||||
/** حداکثر اعشاری که کاربر میتواند در فیلد گرم تایپ کند */
|
||||
export const TRADE_GRAM_TYPING_DECIMALS = 6
|
||||
|
||||
/** زیر این مقدار (گرم)، معادل گرم در فیلد ورودی نشان داده نمیشود */
|
||||
export const TRADE_GRAM_MIN_DISPLAY_GRAMS = 0.0001
|
||||
|
||||
@@ -59,7 +65,88 @@ export function formatTradeGramInputValue(grams?: number | null): string | undef
|
||||
const value = Number(grams ?? 0)
|
||||
if (!Number.isFinite(value) || value <= 0) return undefined
|
||||
if (value < TRADE_GRAM_MIN_DISPLAY_GRAMS) return undefined
|
||||
return formatTradeGramFixedText(value)
|
||||
return value.toFixed(TRADE_GRAM_INPUT_DECIMALS)
|
||||
}
|
||||
|
||||
/** متن اینپوت گرم وقتی مقدار از ریال آمده — فقط نمایش سهرقمی؛ منبع حقیقت همان گرم دقیق است */
|
||||
export function tradeGramInputDisplay(exactGrams?: number | string | null): string {
|
||||
if (exactGrams === undefined || exactGrams === null || exactGrams === '') return ''
|
||||
const n = Number(exactGrams)
|
||||
if (!Number.isFinite(n) || n <= 0) return ''
|
||||
return formatTradeGramInputValue(n) ?? ''
|
||||
}
|
||||
|
||||
/** متن اینپوت گرم وقتی خود کاربر وزن زده — تا ۶ رقم، بدون پد اجباری */
|
||||
export function tradeGramTypedDisplay(exactGrams?: number | string | null): string {
|
||||
if (exactGrams === undefined || exactGrams === null || exactGrams === '') return ''
|
||||
const n = Number(exactGrams)
|
||||
if (!Number.isFinite(n) || n <= 0) return ''
|
||||
return trimTrailingDecimalZeros(n.toFixed(TRADE_GRAM_TYPING_DECIMALS))
|
||||
}
|
||||
|
||||
export function tradeGramFieldText(
|
||||
exactGrams: number | string | null | undefined,
|
||||
inputLock: TradeInputLock,
|
||||
draft: string | null,
|
||||
): string {
|
||||
if (draft !== null) return draft
|
||||
if (inputLock === 'rial') return tradeGramInputDisplay(exactGrams)
|
||||
return tradeGramTypedDisplay(exactGrams)
|
||||
}
|
||||
|
||||
/** هنگام تایپ در فیلد گرم: حداکثر شش رقم اعشار؛ نقطهٔ انتهایی برای «۱۲.» نگه داشته میشود */
|
||||
export function sanitizeTradeGramTypingText(raw: unknown): string {
|
||||
const text = String(raw ?? '')
|
||||
if (text === '') return ''
|
||||
const firstDot = text.indexOf('.')
|
||||
if (firstDot === -1) return text
|
||||
const intPart = text.slice(0, firstDot)
|
||||
const decRaw = text.slice(firstDot + 1).replace(/\./g, '')
|
||||
if (decRaw === '') return `${intPart}.`
|
||||
return `${intPart}.${decRaw.slice(0, TRADE_GRAM_TYPING_DECIMALS)}`
|
||||
}
|
||||
|
||||
/** متن شروع ویرایش وقتی فیلد از روی ریال پر شده (۱.۰۰۰ → ۱) */
|
||||
export function tradeGramInputEditText(exactGrams?: number | string | null): string {
|
||||
const shown = tradeGramInputDisplay(exactGrams)
|
||||
if (!shown) return ''
|
||||
return shown.replace(/\.?0+$/, '')
|
||||
}
|
||||
|
||||
/** گرم دقیق از درصد کیف — بدون رند نمایشی اینپوت */
|
||||
export function exactGoldFromWalletPercent(balance: number, percent: number): number {
|
||||
if (!(Number(percent) > 0) || !(Number(balance) > 0)) return 0
|
||||
return normalizeOrderGoldAmount((Number(balance) * Number(percent)) / 100)
|
||||
}
|
||||
|
||||
/**
|
||||
* اگر متن اینپوت همان نمایش سهرقمی مقدار دقیق فعلی باشد، دقیق را نگه میدارد.
|
||||
* در غیر این صورت عدد تایپشده منبع حقیقت میشود.
|
||||
*/
|
||||
export function goldFromGramInputDisplay(
|
||||
raw: unknown,
|
||||
exactGrams?: number | string | null
|
||||
): number | undefined {
|
||||
if (raw === '' || raw == null) return undefined
|
||||
const text = sanitizeTradeGramTypingText(raw).trim()
|
||||
if (text === '' || text === '.') return undefined
|
||||
const forNumber = text.endsWith('.') ? text.slice(0, -1) : text
|
||||
if (forNumber === '') return undefined
|
||||
const typed = Number(forNumber)
|
||||
if (!Number.isFinite(typed) || typed <= 0) return undefined
|
||||
|
||||
const exact = Number(exactGrams)
|
||||
if (Number.isFinite(exact) && exact > 0) {
|
||||
const shown = formatTradeGramInputValue(exact)
|
||||
const typedShown = tradeGramTypedDisplay(exact)
|
||||
if (
|
||||
(shown != null && (text === shown || text === shown.replace(/\.?0+$/, ''))) ||
|
||||
text === typedShown
|
||||
) {
|
||||
return normalizeOrderGoldAmount(exact)
|
||||
}
|
||||
}
|
||||
return normalizeOrderGoldAmount(typed)
|
||||
}
|
||||
|
||||
function feeRate() {
|
||||
@@ -78,7 +165,8 @@ export async function loadServiceFeeFromSettings() {
|
||||
(s) => s?.key === 'fee_service_charge_percentage' && s?.is_active === true
|
||||
)
|
||||
if (feeSetting?.value !== undefined && feeSetting?.value !== null) {
|
||||
serviceFeePercentage.value = Number(feeSetting.value)
|
||||
const raw = String(feeSetting.value).trim()
|
||||
serviceFeePercentage.value = raw === '' ? 0 : Number(raw)
|
||||
}
|
||||
|
||||
const feeModeSetting = settings.find(
|
||||
|
||||
@@ -48,6 +48,13 @@ export function getSpecialPricingState() {
|
||||
return state
|
||||
}
|
||||
|
||||
/** مظنهٔ last از قبل اختلاف ویژه دارد (سرور یا applyBoardSpecial) */
|
||||
export function lastPriceIncludesSpecial(
|
||||
payload?: { special_pricing?: unknown } | null,
|
||||
): boolean {
|
||||
return Boolean(payload && typeof payload === 'object' && payload.special_pricing)
|
||||
}
|
||||
|
||||
/** اگر سرور قبلاً special_pricing نزده، اختلاف تابلو را روی last اعمال کن */
|
||||
export function applyBoardSpecialToLastPayload<T extends Record<string, any>>(payload: T): T {
|
||||
if (!payload || typeof payload !== 'object') return payload
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import { useSettingsStore } from '@/store/settingsStore'
|
||||
import { getTradeBuyPrice, getTradeSellPrice, lastPrice } from '@/utils/price'
|
||||
import { isLastPriceAbsenceSettled, lastPrice, lastPriceReady } from '@/utils/price'
|
||||
|
||||
export interface StoreTradingHours {
|
||||
start: string
|
||||
@@ -12,8 +12,24 @@ export interface EffectiveTradingHours {
|
||||
start: string
|
||||
end: string
|
||||
enforced: boolean
|
||||
dayEnabled: boolean
|
||||
}
|
||||
|
||||
type WeekdayKey = 'sat' | 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri'
|
||||
|
||||
type DaySchedule = {
|
||||
enabled: boolean
|
||||
start: string
|
||||
end: string
|
||||
}
|
||||
|
||||
type WeeklySchedule = {
|
||||
mode: 'uniform' | 'per_day'
|
||||
days: Record<WeekdayKey, DaySchedule>
|
||||
}
|
||||
|
||||
const WEEKDAY_BY_JS: WeekdayKey[] = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
|
||||
|
||||
const productTradingHours = ref<{ start: string; end: string } | null>(null)
|
||||
const productTradingHoursVersion = ref(0)
|
||||
|
||||
@@ -44,7 +60,7 @@ export function formatTradingTimeDisplay(time: string): string {
|
||||
return normalized
|
||||
}
|
||||
|
||||
function hasProductTradingWindow(start?: string | null, end?: string | null): boolean {
|
||||
export function hasProductTradingWindow(start?: string | null, end?: string | null): boolean {
|
||||
const open = formatTradingTimeDisplay(normalizeTradingTimeSetting(start, '00:00:00'))
|
||||
const close = formatTradingTimeDisplay(normalizeTradingTimeSetting(end, '00:00:00'))
|
||||
if (!open || !close) {
|
||||
@@ -54,6 +70,11 @@ function hasProductTradingWindow(start?: string | null, end?: string | null): bo
|
||||
return open !== close
|
||||
}
|
||||
|
||||
/** بعد از merge زندهٔ تنظیمات ساعت کاری — computedهای صفحه اصلی دوباره حساب شوند */
|
||||
export function touchStoreHoursSettings() {
|
||||
productTradingHoursVersion.value += 1
|
||||
}
|
||||
|
||||
export function setProductTradingHours(start?: string | null, end?: string | null) {
|
||||
if (!hasProductTradingWindow(start, end)) {
|
||||
productTradingHours.value = null
|
||||
@@ -81,29 +102,93 @@ export function syncProductTradingHoursFromProducts(
|
||||
setProductTradingHours(null, null)
|
||||
}
|
||||
|
||||
export function getStoreTradingHours(): StoreTradingHours {
|
||||
const settings = useSettingsStore()
|
||||
const closeRaw = settings.getSettingByKey('close_price')
|
||||
const closePriceEnabled =
|
||||
closeRaw === true ||
|
||||
closeRaw === 1 ||
|
||||
String(closeRaw ?? 'false').trim().toLowerCase() === 'true'
|
||||
function weekdayKey(now: Date): WeekdayKey {
|
||||
return WEEKDAY_BY_JS[now.getDay()] ?? 'sat'
|
||||
}
|
||||
|
||||
return {
|
||||
start: normalizeTradingTimeSetting(settings.getSettingByKey('startDay'), '00:00'),
|
||||
end: normalizeTradingTimeSetting(settings.getSettingByKey('endDay'), '23:59'),
|
||||
closePriceEnabled,
|
||||
function parseWeeklySchedule(raw: unknown): WeeklySchedule | null {
|
||||
const text = String(raw ?? '').trim()
|
||||
if (!text) return null
|
||||
try {
|
||||
const parsed = JSON.parse(text) as Partial<WeeklySchedule>
|
||||
if (!parsed?.days || typeof parsed.days !== 'object') return null
|
||||
const mode = parsed.mode === 'per_day' ? 'per_day' : 'uniform'
|
||||
const defaults = getStoreTradingHours()
|
||||
const keys: WeekdayKey[] = ['sat', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri']
|
||||
const days = {} as Record<WeekdayKey, DaySchedule>
|
||||
for (const key of keys) {
|
||||
const row = parsed.days[key]
|
||||
days[key] = {
|
||||
enabled: row?.enabled !== false,
|
||||
start: normalizeTradingTimeSetting(row?.start, defaults.start),
|
||||
end: normalizeTradingTimeSetting(row?.end, defaults.end),
|
||||
}
|
||||
}
|
||||
return { mode, days }
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function getEffectiveTradingHours(): EffectiveTradingHours {
|
||||
export function isOutsideProductActivationWindow(
|
||||
product?: { auto_open_at?: string | null; auto_close_at?: string | null } | null,
|
||||
now = new Date(),
|
||||
): boolean {
|
||||
void productTradingHoursVersion.value
|
||||
if (!product || !hasProductTradingWindow(product.auto_open_at, product.auto_close_at)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return isOutsideTimeWindow(
|
||||
now,
|
||||
normalizeTradingTimeSetting(product.auto_open_at, '00:00:00'),
|
||||
normalizeTradingTimeSetting(product.auto_close_at, '00:00:00'),
|
||||
)
|
||||
}
|
||||
|
||||
function isOutsideTimeWindow(now: Date, start: string, end: string): boolean {
|
||||
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
|
||||
const openSeconds = parseTimeToSeconds(start)
|
||||
const closeSeconds = parseTimeToSeconds(end)
|
||||
if (closeSeconds <= openSeconds) {
|
||||
return currentSeconds < openSeconds && currentSeconds > closeSeconds
|
||||
}
|
||||
return currentSeconds < openSeconds || currentSeconds > closeSeconds
|
||||
}
|
||||
|
||||
export function getStoreTradingHours(): StoreTradingHours {
|
||||
const settings = useSettingsStore()
|
||||
void settings.settingsRevision
|
||||
return {
|
||||
start: normalizeTradingTimeSetting(settings.getSettingByKey('startDay'), '00:00'),
|
||||
end: normalizeTradingTimeSetting(settings.getSettingByKey('endDay'), '23:59'),
|
||||
closePriceEnabled: settings.isSettingTruthy('close_price'),
|
||||
}
|
||||
}
|
||||
|
||||
export function getEffectiveTradingHours(now = new Date()): EffectiveTradingHours {
|
||||
void productTradingHoursVersion.value
|
||||
const settings = getStoreTradingHours()
|
||||
const weekly = parseWeeklySchedule(useSettingsStore().getSettingByKey('trading_hours_by_day'))
|
||||
|
||||
if (settings.closePriceEnabled && weekly?.mode === 'per_day') {
|
||||
const day = weekly.days[weekdayKey(now)]
|
||||
if (day) {
|
||||
return {
|
||||
start: day.start,
|
||||
end: day.end,
|
||||
enforced: true,
|
||||
dayEnabled: day.enabled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.closePriceEnabled) {
|
||||
return {
|
||||
start: settings.start,
|
||||
end: settings.end,
|
||||
enforced: true,
|
||||
dayEnabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +197,7 @@ export function getEffectiveTradingHours(): EffectiveTradingHours {
|
||||
start: productTradingHours.value.start,
|
||||
end: productTradingHours.value.end,
|
||||
enforced: true,
|
||||
dayEnabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,36 +205,47 @@ export function getEffectiveTradingHours(): EffectiveTradingHours {
|
||||
start: settings.start,
|
||||
end: settings.end,
|
||||
enforced: false,
|
||||
dayEnabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
export function isStoreClosedBySchedule(now = new Date()): boolean {
|
||||
const { start, end, enforced } = getEffectiveTradingHours()
|
||||
if (!enforced) {
|
||||
/** خارج از ساعت کاری سراسری — فقط وقتی close_price روشن باشد (صفحه اصلی) */
|
||||
export function isOutsideGlobalStoreHours(now = new Date()): boolean {
|
||||
const settings = getStoreTradingHours()
|
||||
if (!settings.closePriceEnabled) {
|
||||
return false
|
||||
}
|
||||
|
||||
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
|
||||
const openSeconds = parseTimeToSeconds(start)
|
||||
const closeSeconds = parseTimeToSeconds(end)
|
||||
|
||||
return currentSeconds < openSeconds || currentSeconds > closeSeconds
|
||||
}
|
||||
|
||||
export function isStoreClosed(): boolean {
|
||||
void productTradingHoursVersion.value
|
||||
const { closePriceEnabled } = getStoreTradingHours()
|
||||
|
||||
if (closePriceEnabled) {
|
||||
if (lastPrice.value?.closed === true) {
|
||||
const weekly = parseWeeklySchedule(useSettingsStore().getSettingByKey('trading_hours_by_day'))
|
||||
if (weekly?.mode === 'per_day') {
|
||||
const day = weekly.days[weekdayKey(now)]
|
||||
if (day && !day.enabled) {
|
||||
return true
|
||||
}
|
||||
|
||||
return isStoreClosedBySchedule()
|
||||
if (day) {
|
||||
return isOutsideTimeWindow(now, day.start, day.end)
|
||||
}
|
||||
}
|
||||
|
||||
// وقتی close_price خاموش است، صفر بودن قیمت مرجع به معنی بسته بودن فروشگاه نیست.
|
||||
return isStoreClosedBySchedule()
|
||||
return isOutsideTimeWindow(now, settings.start, settings.end)
|
||||
}
|
||||
|
||||
export function isStoreClosedBySchedule(now = new Date()): boolean {
|
||||
const { start, end, enforced, dayEnabled } = getEffectiveTradingHours(now)
|
||||
if (!enforced) {
|
||||
return false
|
||||
}
|
||||
if (!dayEnabled) {
|
||||
return true
|
||||
}
|
||||
return isOutsideTimeWindow(now, start, end)
|
||||
}
|
||||
|
||||
/** باز/بسته بودن فروشگاه فقط از استریم last.closed — نه ساعت دستگاه کاربر */
|
||||
export function isStoreClosed(): boolean {
|
||||
void lastPriceReady.value
|
||||
void lastPrice.value
|
||||
return lastPrice.value?.closed === true
|
||||
}
|
||||
|
||||
export function getStoreClosedMessage(): string {
|
||||
@@ -167,35 +264,83 @@ export type PriceDisplayState = 'open' | 'closed' | 'no_quote'
|
||||
|
||||
export const NO_QUOTE_MESSAGE = 'مظنه در دسترس نیست'
|
||||
|
||||
/** سوییچ: خارج از ساعت کاری هم قیمت صفحه اصلی نشان داده شود */
|
||||
export function shouldShowHomePriceWhenClosed(): boolean {
|
||||
return useSettingsStore().isSettingTruthy('show_home_price_when_closed')
|
||||
}
|
||||
|
||||
export function shouldShowLastSavedPrice(): boolean {
|
||||
return useSettingsStore().isSettingTruthy('show_last_price')
|
||||
}
|
||||
|
||||
/** فقط این منابع «آخرین قیمت ذخیرهشده» هستند؛ باقی price_source مظنهٔ زنده است */
|
||||
const STORED_PRICE_SOURCES = ['database_last']
|
||||
|
||||
function hasShowableHomePrice(p = lastPrice.value): boolean {
|
||||
if (!p) return false
|
||||
return Number(p.buy) > 0 || Number(p.sell) > 0 || Number(p.price_last) > 0 || Number(p.price) > 0
|
||||
}
|
||||
|
||||
/** قیمت از مرجع زنده آمده یا از آخرین ردیف ذخیرهشده */
|
||||
function hasLiveQuote(p = lastPrice.value): boolean {
|
||||
if (!hasShowableHomePrice(p)) return false
|
||||
|
||||
const source = String((p as { price_source?: string })?.price_source ?? '').trim().toLowerCase()
|
||||
if (source) return !STORED_PRICE_SOURCES.includes(source)
|
||||
|
||||
return (
|
||||
Number(p?.montzar ?? 0) > 0
|
||||
|| Number((p as { zaarbox?: number })?.zaarbox ?? 0) > 0
|
||||
|| Number(p?.main_product ?? 0) > 0
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* وضعیت نمایش قیمت در صفحه اصلی:
|
||||
* - closed → فروشگاه بسته است (خارج از ساعت کاری close_price یا بازه محصول)
|
||||
* - no_quote → مظنه در دسترس نیست (قیمت زنده نداریم و show_last_price خاموش است)
|
||||
* - open → نمایش عادی قیمت
|
||||
*
|
||||
* اولویت با status ارسالی از سرور است؛ اگر نبود به منطق سمت کلاینت برمیگردیم.
|
||||
* وضعیت نمایش قیمت در صفحه اصلی — همان منطق بکاند:
|
||||
* خارج از ساعت کاری (close_price روشن) → show_home_price_when_closed روشن: آخرین قیمت؛ خاموش: closed
|
||||
* داخل ساعت کاری → مظنه زنده: open ؛ وگرنه فقط با show_last_price آخرین قیمت؛ وگرنه no_quote
|
||||
*/
|
||||
export function getPriceDisplayState(): PriceDisplayState {
|
||||
void productTradingHoursVersion.value
|
||||
void useSettingsStore().settingsRevision
|
||||
const p = lastPrice.value
|
||||
const status = p?.status
|
||||
|
||||
if (status === 'closed') {
|
||||
return 'closed'
|
||||
}
|
||||
if (status === 'no_quote') {
|
||||
return getTradeBuyPrice(p) > 0 ? 'open' : 'no_quote'
|
||||
}
|
||||
if (status === 'open') {
|
||||
return getTradeBuyPrice(p) > 0 || getTradeSellPrice(p) > 0 ? 'open' : 'no_quote'
|
||||
const serverStatus = p?.status
|
||||
// اگر عدد قیمت هست، no_quote لحظهای سرور را جدی نگیر (race با تیک بعدی)
|
||||
if (serverStatus === 'no_quote' && hasShowableHomePrice(p)) {
|
||||
// fall through به منطق کلاینت
|
||||
} else if (serverStatus === 'open' || serverStatus === 'closed' || serverStatus === 'no_quote') {
|
||||
return serverStatus
|
||||
}
|
||||
|
||||
// سرور status نفرستاده (سازگاری با نسخه قدیمی) → استنتاج سمت کلاینت
|
||||
if (isStoreClosed()) {
|
||||
return 'closed'
|
||||
if (p?.closed === true) {
|
||||
if (!shouldShowHomePriceWhenClosed()) return 'closed'
|
||||
return hasShowableHomePrice(p) ? 'open' : 'no_quote'
|
||||
}
|
||||
|
||||
return getTradeBuyPrice(p) > 0 || getTradeSellPrice(p) > 0 ? 'open' : 'no_quote'
|
||||
if (hasLiveQuote(p)) return 'open'
|
||||
if (shouldShowLastSavedPrice() && hasShowableHomePrice(p)) return 'open'
|
||||
if (hasShowableHomePrice(p)) return 'open'
|
||||
|
||||
return 'no_quote'
|
||||
}
|
||||
|
||||
/**
|
||||
* اسکلتون تا وقتی قیمت قابلنمایش برسد، یا وضعیت بسته قطعی شود،
|
||||
* یا بعد از اولین پاسخ خالی پنجرهٔ settle تمام شود (مظنه واقعاً نیست).
|
||||
*/
|
||||
export function isHomeQuotePending(): boolean {
|
||||
const settings = useSettingsStore()
|
||||
void lastPriceReady.value
|
||||
void lastPrice.value
|
||||
void isLastPriceAbsenceSettled()
|
||||
void settings.loaded
|
||||
void settings.settingsRevision
|
||||
|
||||
if (!settings.loaded || !lastPriceReady.value) return true
|
||||
if (hasShowableHomePrice(lastPrice.value)) return false
|
||||
if (lastPrice.value?.status === 'closed') return false
|
||||
return !isLastPriceAbsenceSettled()
|
||||
}
|
||||
|
||||
export function getPriceDisplayMessage(state: PriceDisplayState = getPriceDisplayState()): string {
|
||||
|
||||