liveDrawer.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <BasicDrawer
  3. v-bind="$attrs"
  4. @register="registerDrawer"
  5. showFooter
  6. :title="getTitle"
  7. width="60%"
  8. @ok="handleSubmit"
  9. >
  10. <div class="entry-x">
  11. <BasicForm @register="registerForm">
  12. <template #map>
  13. <!-- <Card style="width: 300px; height: 300px"> -->
  14. <div ref="wrapRef" style="width: 100%; height: 400px"></div>
  15. <!-- </Card> -->
  16. </template>
  17. </BasicForm>
  18. </div>
  19. </BasicDrawer>
  20. </template>
  21. <script lang="ts">
  22. import { defineComponent, ref, computed, unref, nextTick, onMounted, reactive } from 'vue';
  23. import { BasicForm, useForm, FormSchema } from '/@/components/Form/index';
  24. // import { Card } from 'ant-design-vue';
  25. import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  26. // import { useMessage } from '/@/hooks/web/useMessage';
  27. import { useI18n } from '/@/hooks/web/useI18n';
  28. import { brandTypeListApi, uploadLiveApi, getAllSceneApi } from '/@/api/scene/live';
  29. import { data as CascaderData } from '/@/utils/cascaderData';
  30. import { useScript } from '/@/hooks/web/useScript';
  31. const A_MAP_URL = 'https://webapi.amap.com/maps?v=2.0&key=e661b00bdf2c44cccf71ef6070ef41b8';
  32. // const A_MAP_URL = 'https://webapi.amap.com/maps?v=2.0&key=5a2d384532ae531bf99bd8487c4f03d2';
  33. // const A_MAP_URL = 'https://webapi.amap.com/maps?v=1.4.10&key=e661b00bdf2c44cccf71ef6070ef41b8';
  34. //webapi.amap.com/maps?v=1.4.10&key=e661b00bdf2c44cccf71ef6070ef41b8
  35. // Card
  36. export default defineComponent({
  37. name: 'MenuDrawer',
  38. components: { BasicDrawer, BasicForm },
  39. emits: ['success', 'register'],
  40. setup() {
  41. const isUpdate = ref(true);
  42. const wrapRef = ref<HTMLDivElement | null>(null);
  43. const defaultAddress = reactive({
  44. address: '山阴路688号恒隆广场B座1217',
  45. longt: '山阴路688号恒隆广场B座1217',
  46. });
  47. console.log('defaultAddress', defaultAddress);
  48. const { toPromise } = useScript({ src: A_MAP_URL });
  49. const { t } = useI18n();
  50. // const { createMessage } = useMessage();
  51. const schemas: FormSchema[] = [
  52. {
  53. field: 'type',
  54. label: t('routes.scenes.liveType'),
  55. component: 'ApiSelect',
  56. // colProps: {
  57. // xl: 5,
  58. // xxl: 5,
  59. // },
  60. componentProps: {
  61. api: brandTypeListApi,
  62. resultField: 'list',
  63. labelField: 'name',
  64. valueField: 'id',
  65. params: {
  66. page: 1,
  67. limit: 1000,
  68. },
  69. },
  70. },
  71. {
  72. field: 'name',
  73. component: 'Input',
  74. label: t('routes.scenes.liveName'),
  75. required: true,
  76. },
  77. {
  78. field: 'appListPicUrl',
  79. label: t('routes.scenes.appListPicUrl'),
  80. component: 'Upload',
  81. helpMessage: '推荐大小:400 * 400 像素',
  82. required: true,
  83. colProps: {
  84. span: 10,
  85. },
  86. componentProps: {
  87. api: uploadLiveApi,
  88. maxgoodsNumber: 1,
  89. afterFetch: function (data) {
  90. Reflect.set(data, 'url', data.message.url);
  91. return data;
  92. },
  93. },
  94. },
  95. {
  96. field: 'sceneUrl',
  97. label: t('routes.scenes.sceneUrl'),
  98. component: 'ApiSelect',
  99. required: true,
  100. colProps: {
  101. span: 10,
  102. },
  103. componentProps: {
  104. api: getAllSceneApi,
  105. },
  106. },
  107. // :fieldNames="{ label: 'name', value: 'code', children: 'children' }"
  108. {
  109. field: 'location',
  110. label: '直播间位置',
  111. component: 'ApiCascader',
  112. labelWidth: 100,
  113. componentProps: {
  114. api: () => {
  115. return CascaderData;
  116. },
  117. apiParamKey: 'provinceCode',
  118. dataField: 'children',
  119. labelField: 'name',
  120. valueField: 'code',
  121. isLeaf: (record) => {
  122. return !(record.levelType < 3);
  123. },
  124. },
  125. colProps: {
  126. span: 20,
  127. },
  128. },
  129. {
  130. field: 'map',
  131. label: '地图位置',
  132. component: 'Input',
  133. labelWidth: 100,
  134. slot: 'map',
  135. colProps: {
  136. span: 20,
  137. },
  138. },
  139. ];
  140. // updateSchema, validate
  141. const [registerForm, { resetFields, setFieldsValue }] = useForm({
  142. labelWidth: 120,
  143. schemas: schemas,
  144. showActionButtonGroup: false,
  145. baseColProps: { lg: 24, md: 24 },
  146. });
  147. // closeDrawer;
  148. const [registerDrawer, { setDrawerProps }] = useDrawerInner(async (data) => {
  149. resetFields();
  150. setDrawerProps({ confirmLoading: false });
  151. isUpdate.value = !!data?.isUpdate;
  152. if (unref(isUpdate)) {
  153. console.log('data.record', data);
  154. setFieldsValue({
  155. ...data.record,
  156. });
  157. }
  158. initMap();
  159. // updateSchema({
  160. // field: 'parentId',
  161. // componentProps: {
  162. // treeData,
  163. // },
  164. // });
  165. });
  166. async function initMap() {
  167. await toPromise();
  168. await nextTick();
  169. const wrapEl = unref(wrapRef);
  170. console.log('wrapEl', wrapEl);
  171. if (!wrapEl) return;
  172. const AMap = (window as any).AMap;
  173. console.log('AMap', AMap);
  174. // center: [this.longitude || 120.262337, this.latitude || 30.178285],
  175. // const geocoder = new AMap.Geocoder({});
  176. const map = new AMap.Map(wrapEl, {
  177. zoom: 18,
  178. center: [120.262337, 30.178285],
  179. viewMode: '3D',
  180. resizeEnable: true,
  181. floorControl: true,
  182. showIndoorMap: true,
  183. });
  184. AMap.plugin('AMap.Geocoder', function () {
  185. var geocoder = new AMap.Geocoder({
  186. // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
  187. city: '010',
  188. });
  189. geocoder.getLocation('北京市海淀区苏州街', function (status, result) {
  190. if (status === 'complete' && result.info === 'OK') {
  191. // result中对应详细地理坐标信息
  192. console.log('result', result);
  193. }
  194. });
  195. });
  196. const marker = new AMap.Marker({
  197. position: new AMap.LngLat(120.262337, 30.178285),
  198. title: 'lala',
  199. });
  200. map.add(marker);
  201. }
  202. onMounted(() => {
  203. initMap();
  204. });
  205. const getTitle = computed(() => (!unref(isUpdate) ? '新增直播间' : '编辑直播间'));
  206. async function handleSubmit() {}
  207. return { registerDrawer, registerForm, getTitle, handleSubmit, wrapRef };
  208. },
  209. });
  210. </script>