followInput.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="follow-input-wrapper">
  3. <div class="at-user-item" v-for="(item, index) in pageAtUserList" :key="index">
  4. <img :src="require('../../assets/svg/icon-del-follows-user.svg')"
  5. class="icon-del"
  6. @click="delUser(item, index)">
  7. <pre :id='"pre" + index' class="at-user-input-placeholder">{{item.name}}</pre>
  8. @<input class="at-user-input"
  9. :id='"input" + index'
  10. v-model="item.name"
  11. @change="onIptChange(item, index)"
  12. @input="onInput(item, index)"
  13. @keyup="onKeyup(item, index)"
  14. @blur="onblur(item, index)"
  15. @focus="onfocus(item, index)"/>
  16. <div class="user-list-wrapper" v-if="currentIptIndex == index && userList.length">
  17. <div class="item"
  18. v-for="(item, index) in userList"
  19. :key="index"
  20. :class="{'active': index === currentUserIndex}"
  21. @mouseenter="onUserMouseEnter(item, index)"
  22. @mouseleave="onUserMouseLeave(item, index)"
  23. @click="selectedUser(item, index)">
  24. <div class="following" v-if="item.following">
  25. <img :src="require('../../assets/svg/icon-following-user.svg')">following
  26. </div>
  27. <div class="content">
  28. <img class="avatar" :src="item.avatarlUrl">
  29. <div>
  30. <div class="name">{{item.name}}</div>
  31. <div class="screenName">@{{item.screenName}}</div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. <div class="icon-add-wrapper" v-if="pageAtUserList.length < 5"
  38. @click="addInput"
  39. @mouseenter="handleMouseEn"
  40. @mouseleave="handleMouseLe">
  41. <img :src="require('../../assets/svg/icon-add-user-default.svg')"
  42. class="icon-add"
  43. v-if="!isActiveAddBtn">
  44. <img :src="require('../../assets/svg/icon-add-user-active.svg')"
  45. class="icon-add"
  46. v-else>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. /* eslint-disable */
  52. import { reactive, ref, onMounted, defineEmits, defineProps, watch } from "vue";
  53. import {searchTwitterUser} from "../../http/publishApi";
  54. import {debounce, getStorage} from "../../uilts/help";
  55. const props = defineProps({
  56. atUserList: {
  57. type: Array,
  58. default: () => {
  59. return []
  60. }
  61. }
  62. })
  63. let currentIptIndex = ref(-1);
  64. let isActiveAddBtn = ref(false);
  65. let currentUserIndex = ref(-1);
  66. let userList = ref([]);
  67. let userInfo = reactive({});
  68. let pageAtUserList = ref(props.atUserList);
  69. const emits = defineEmits(["addUser", "setUser", "delUser"]);
  70. onMounted(() => {
  71. if(!pageAtUserList.value.length) {
  72. getUserInfo((info) => {
  73. if(info.nickName) {
  74. addUser(info.nickName);
  75. setTimeout(() => {
  76. setIptWidth(0);
  77. })
  78. }
  79. });
  80. } else {
  81. for(let i = 0; i < pageAtUserList.value.length; i++ ) {
  82. setTimeout(() => {
  83. setIptWidth(i);
  84. })
  85. }
  86. }
  87. })
  88. watch(
  89. () => props.atUserList,
  90. (newVal) => {
  91. console.log(newVal, '222')
  92. },
  93. {
  94. deep: true
  95. }
  96. );
  97. const getUserInfo = (cb) => {
  98. let localUserInfo = getStorage('de-userInfo');
  99. console.log('localUserInfo',localUserInfo)
  100. if(localUserInfo) {
  101. userInfo = localUserInfo;
  102. }
  103. cb && cb(localUserInfo);
  104. }
  105. const addUser = (name = '') => {
  106. emits('addUser', {
  107. name
  108. })
  109. }
  110. const addInput = () => {
  111. addUser('');
  112. setTimeout(() => {
  113. setIptWidth(props.atUserList.length - 1);
  114. })
  115. }
  116. const delUser = (params, index) => {
  117. emits("delUser", {index})
  118. }
  119. const onfocus = (params, index) => {
  120. console.log(params, index)
  121. }
  122. const onblur = (params, index) => {
  123. console.log(params, index)
  124. }
  125. const onInput = debounce(function(params, index) {
  126. currentIptIndex.value = index;
  127. emits("setUser", {index: index, name: params.name})
  128. getTwitterUsers(params.name)
  129. }, 800)
  130. const onKeyup = (params, index) => {
  131. setIptWidth(index);
  132. }
  133. const setIptWidth = (index) => {
  134. document.getElementById('input'+index).style.width = document.getElementById('pre'+index).offsetWidth + 'px'
  135. }
  136. const onIptChange = (params, index) => {
  137. console.log(index)
  138. }
  139. const handleMouseEn = () => {
  140. isActiveAddBtn.value = true;
  141. }
  142. const handleMouseLe = () => {
  143. isActiveAddBtn.value = false;
  144. }
  145. const getTwitterUsers = (query, cb) => {
  146. searchTwitterUser({
  147. params: {
  148. name : query
  149. }
  150. }).then(res => {
  151. if(res.code == 0) {
  152. userList.value = res.data;
  153. }
  154. cb && cb(res);
  155. console.log('searchTwitterUser',res)
  156. })
  157. }
  158. const selectedUser = (params, index) => {
  159. emits("setUser", {index: currentIptIndex.value, name: params.screenName});
  160. setTimeout(() => {
  161. setIptWidth(currentIptIndex.value);
  162. currentIptIndex.value = -1;
  163. })
  164. }
  165. const onUserMouseEnter = (params, index) => {
  166. currentUserIndex.value = index;
  167. }
  168. const onUserMouseLeave = (params, index) => {
  169. currentUserIndex.value = -1;
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .follow-input-wrapper {
  174. width: 100%;
  175. display: flex;
  176. flex-wrap: wrap;
  177. padding: 0px 0 14px 18px;
  178. box-sizing: border-box;
  179. .icon-add{
  180. width: 24px;
  181. height: 24px;
  182. margin-left: 10px;
  183. cursor: pointer;
  184. }
  185. .at-user-item {
  186. display: flex;
  187. align-items: center;
  188. border: 1px solid #ECECEC;
  189. box-sizing: border-box;
  190. border-radius: 100px;
  191. color: #389AFF;
  192. font-weight: 500;
  193. font-size: 15px;
  194. padding: 4px 12px;
  195. position: relative;
  196. margin-right: 10px;
  197. background-color: #fff;
  198. margin-top: 14px;
  199. .icon-del {
  200. width: 18px;
  201. height: 18px;
  202. position: absolute;
  203. right: -7px;
  204. top: -6px;
  205. cursor: pointer;
  206. }
  207. .at-user-input-placeholder {
  208. position: absolute;
  209. top: -1000px;
  210. font-size: 13px;
  211. min-width: 12px;
  212. max-width: 128px;
  213. }
  214. .at-user-input {
  215. color: #389AFF;
  216. border: none;
  217. outline: none;
  218. }
  219. .user-list-wrapper {
  220. width: 284px;
  221. height: 430px;
  222. position: absolute;
  223. box-shadow: 0px 4px 20px 0px #0000004D;
  224. overflow-y: scroll;
  225. background-color: #fff;
  226. top: 30px;
  227. left: -90px;
  228. z-index: 1000;
  229. border-radius: 10px;
  230. .item {
  231. width: 100%;
  232. height: auto;
  233. box-sizing: border-box;
  234. padding: 8px 16px;
  235. cursor: pointer;
  236. .following {
  237. font-weight: 500;
  238. font-size: 14px;
  239. color: #566370;
  240. display: flex;
  241. align-items: center;
  242. margin-left: 20px;
  243. img {
  244. margin-right: 6px;
  245. }
  246. }
  247. .content {
  248. display: flex;
  249. align-items: center;
  250. box-sizing: border-box;
  251. margin: 5px 0;
  252. height: 100%;
  253. .avatar {
  254. width: 40px;
  255. height: 40px;
  256. border-radius: 50%;
  257. margin-right: 10px;
  258. }
  259. div {
  260. width: calc(100% - 50px);
  261. .name {
  262. font-weight: 600;
  263. font-size: 16px;
  264. margin-bottom: 2px;
  265. color: #000;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. white-space: nowrap;
  269. }
  270. .screenName {
  271. font-size: 15px;
  272. color: #566370;
  273. }
  274. }
  275. }
  276. }
  277. .active {
  278. background-color: #F7F9F9 !important;
  279. }
  280. }
  281. }
  282. .icon-add-wrapper {
  283. display: flex;
  284. align-items: center;
  285. margin-top: 14px;
  286. }
  287. }
  288. </style>