live.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable" :rowSelection="{ type: 'checkbox' }">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleAddLiveScene"> 新增</a-button>
  6. <!-- <a-button type="primary" color="warning" @click="() => {}"> 编辑</a-button>
  7. <a-button type="primary" color="error" @click="() => {}"> 删除</a-button> -->
  8. </template>
  9. <template #cover="{ record }">
  10. <TableImg
  11. :size="150"
  12. :simpleShow="true"
  13. :imgList="[record.appListPicUrl || '/resource/img/pic_bg@2x.png']"
  14. />
  15. </template>
  16. <template #houseType="{ record }">
  17. {{ renderHouseType(Number(record.type)) }}
  18. </template>
  19. <template #action="{ record }">
  20. <TableAction
  21. :actions="[
  22. {
  23. icon: 'eos-icons:role-binding',
  24. label: t('routes.scenes.bindAnchor'),
  25. color: 'success',
  26. onClick: handleBindAnchor.bind(null, record),
  27. },
  28. {
  29. icon: 'ant-design:delete-outlined',
  30. color: 'warning',
  31. label: '编辑',
  32. onClick: handleEditLiveScene.bind(null, record),
  33. },
  34. {
  35. icon: 'ant-design:delete-outlined',
  36. color: 'error',
  37. label: '删除',
  38. popConfirm: {
  39. title: '是否确认删除',
  40. confirm: handleDeleteLiveScene.bind(null, record),
  41. },
  42. },
  43. ]"
  44. />
  45. </template>
  46. </BasicTable>
  47. <bindModal @register="registerBindModal" @success="reload" />
  48. <addLiveModal @register="registeraddLiveModal" />
  49. <LiveDrawer @register="registerLiveDrawer" @success="reload" />
  50. </div>
  51. </template>
  52. <script lang="ts">
  53. import { defineComponent } from 'vue';
  54. import {
  55. BasicTable,
  56. useTable,
  57. BasicColumn,
  58. // FormSchema,
  59. FormProps,
  60. TableAction,
  61. TableImg,
  62. } from '/@/components/Table';
  63. import { useMessage } from '/@/hooks/web/useMessage';
  64. // import { uploadApi } from '/@/api/sys/upload';
  65. import { Tag } from 'ant-design-vue';
  66. import { h } from 'vue';
  67. import { ListApi, brandTypeListApi, LiveSceneDeleteApi } from '/@/api/scene/live';
  68. import { useI18n } from '/@/hooks/web/useI18n';
  69. import { useModal } from '/@/components/Modal';
  70. import { useDrawer } from '/@/components/Drawer';
  71. import bindModal from './bindModal.vue';
  72. import LiveDrawer from './liveDrawer.vue';
  73. export default defineComponent({
  74. components: { BasicTable, TableAction, TableImg, bindModal, LiveDrawer },
  75. setup() {
  76. const { createMessage } = useMessage();
  77. const { t } = useI18n();
  78. const [registerBindModal, { openModal: openBindModal }] = useModal();
  79. const [registerLiveDrawer, { openDrawer: openLiveDrawer }] = useDrawer();
  80. const columns: BasicColumn[] = [
  81. {
  82. title: 'ID',
  83. dataIndex: 'id',
  84. fixed: 'left',
  85. width: 100,
  86. },
  87. {
  88. title: t('routes.scenes.anchorRoom'),
  89. dataIndex: 'name',
  90. ellipsis: false,
  91. width: 130,
  92. },
  93. {
  94. title: t('common.type'),
  95. dataIndex: 'type',
  96. slots: { customRender: 'houseType' },
  97. width: 100,
  98. },
  99. {
  100. title: '场景名称',
  101. dataIndex: 'sceneName',
  102. width: 140,
  103. },
  104. {
  105. title: t('routes.scenes.appListPicUrl'),
  106. dataIndex: 'appListPicUrl',
  107. slots: { customRender: 'cover' },
  108. width: 150,
  109. },
  110. {
  111. title: t('routes.scenes.sortOrder'),
  112. dataIndex: 'sortOrder',
  113. width: 150,
  114. sorter: true,
  115. },
  116. {
  117. title: t('routes.scenes.webSite'),
  118. dataIndex: 'liveRoomUrl',
  119. slots: { customRender: 'link' },
  120. width: 180,
  121. },
  122. {
  123. title: t('routes.scenes.bindShowerNameList'),
  124. dataIndex: 'bindShowerNameList',
  125. ellipsis: false,
  126. width: 180,
  127. },
  128. {
  129. title: t('routes.scenes.livestreamStatus'),
  130. dataIndex: 'livestreamStatus',
  131. width: 180,
  132. customRender: ({ record }) => {
  133. const enable = record.livestreamStatus === 1;
  134. const color = enable ? 'green' : 'red';
  135. const text = enable ? t('common.yes') : t('common.no');
  136. return h(Tag, { color: color }, () => text);
  137. },
  138. },
  139. {
  140. title: t('common.operation'),
  141. dataIndex: '',
  142. slots: { customRender: 'action' },
  143. width: 250,
  144. fixed: 'right',
  145. },
  146. ];
  147. const searchForm: Partial<FormProps> = {
  148. labelWidth: 100,
  149. schemas: [
  150. {
  151. field: 'sceneName',
  152. label: t('routes.scenes.anchorRoom'),
  153. component: 'Input',
  154. componentProps: {
  155. maxLength: 100,
  156. },
  157. colProps: {
  158. xl: 5,
  159. xxl: 5,
  160. },
  161. },
  162. {
  163. field: 'type',
  164. label: t('common.type'),
  165. component: 'ApiSelect',
  166. colProps: {
  167. xl: 5,
  168. xxl: 5,
  169. },
  170. componentProps: {
  171. api: brandTypeListApi,
  172. resultField: 'list',
  173. labelField: 'name',
  174. valueField: 'brandType',
  175. params: {
  176. page: 1,
  177. limit: 1000,
  178. },
  179. },
  180. },
  181. {
  182. field: 'livestreamStatus',
  183. label: t('routes.scenes.livestreamStatus'),
  184. component: 'Select',
  185. colProps: {
  186. xl: 5,
  187. xxl: 5,
  188. },
  189. componentProps: {
  190. options: [
  191. {
  192. label: t('common.all'),
  193. value: '',
  194. key: '0',
  195. },
  196. {
  197. label: t('common.yes'),
  198. value: 1,
  199. key: '1',
  200. },
  201. {
  202. label: t('common.no'),
  203. value: 0,
  204. key: '2',
  205. },
  206. ],
  207. },
  208. },
  209. ],
  210. };
  211. function renderHouseType(type: number): string {
  212. switch (type) {
  213. case 0:
  214. return '新房';
  215. case 1:
  216. return '二手房';
  217. case 2:
  218. return '公寓';
  219. case 3:
  220. return '民宿';
  221. case 4:
  222. return '装修';
  223. default:
  224. return t(`routes.scenes.houseType.9`);
  225. }
  226. }
  227. const [registerTable, { reload }] = useTable({
  228. title: t(`routes.scenes.liveBroadcast`),
  229. api: ListApi,
  230. columns: columns,
  231. useSearchForm: true,
  232. formConfig: searchForm,
  233. showTableSetting: true,
  234. tableSetting: { fullScreen: true },
  235. showIndexColumn: false,
  236. rowKey: 'id',
  237. pagination: { pageSize: 20 },
  238. clickToRowSelect: false,
  239. fetchSetting: {
  240. pageField: 'page',
  241. sizeField: 'limit',
  242. listField: 'list',
  243. totalField: 'totalCount',
  244. },
  245. sortFn: (sortInfo) => {
  246. console.log('sortInfo', sortInfo);
  247. let order = sortInfo.order && sortInfo.order.replace('end', '');
  248. return { ...sortInfo, sidx: sortInfo.field, order: order };
  249. },
  250. // defSort: {
  251. // field: 'order',
  252. // order: 'asc',
  253. // },
  254. });
  255. function handleBindAnchor(record: Recordable) {
  256. openBindModal(true, record);
  257. }
  258. function handleAddLiveScene() {
  259. openLiveDrawer(true, {
  260. isUpdate: false,
  261. });
  262. }
  263. function handleEditLiveScene(record: Recordable) {
  264. openLiveDrawer(true, {
  265. record,
  266. isUpdate: true,
  267. });
  268. }
  269. async function handleDeleteLiveScene(record: Recordable) {
  270. try {
  271. const id = [record.id];
  272. const res = await LiveSceneDeleteApi(id);
  273. console.log('res', res);
  274. // createMessage.success(t('common.optSuccess'));
  275. reload();
  276. } catch (error) {}
  277. }
  278. return {
  279. registerTable,
  280. createMessage,
  281. renderHouseType,
  282. t,
  283. registerBindModal,
  284. handleBindAnchor,
  285. reload,
  286. registerLiveDrawer,
  287. handleAddLiveScene,
  288. handleDeleteLiveScene,
  289. handleEditLiveScene,
  290. };
  291. },
  292. });
  293. </script>