live.vue 8.1 KB

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