• 用智能插件(Fitten Code: Faster and Better AI Assistant)再次修改vue3 <script setup>留言板


     

     

    1. <template>
    2. <div>
    3. <button class="openForm" @click="openForm" v-if="!formVisible">编辑button>
    4. <button @click="closeForm" v-if="formVisible">取消编辑button>
    5. <hr />
    6. <form
    7. v-if="formVisible"
    8. @submit.prevent="addMemo"
    9. class="draggable-form"
    10. :style="{ top: formPosition.y + 'px', left: formPosition.x + 'px' }"
    11. >
    12. <div class="form-title" @mousedown="startDrag">{{ formTitle }}div>
    13. <div class="form-content">
    14. <input type="reset" value="重置" />
    15. <textarea v-model="newItem" rows="10" placeholder="请输入备注内容">textarea>
    16. <button type="submit" class="addBtn">添加button>
    17. div>
    18. form>
    19. <div class="memo" @click="handleMemoAction">
    20. <div v-for="(memo, index) in memos" :key="index" class="item">
    21. <span class="item-number">{{ index + 1 }}.span>
    22. <button v-if="showActions && !memo.finished" @click="completeMemo(index)">完成button>
    23. <button v-if="showActions && memo.finished" @click="cancelMemo(index)">取消button>
    24. <span class="text-content" :class="{ content: true, finish: memo.finished }">
    25. {{ memo.name }}
    26. span>
    27. <button v-if="showActions && memo.finished" @click="reworkMemo(index)">修改button>
    28. <button
    29. class="deleteBtn"
    30. v-if="showActions && memo.finished"
    31. v-show="noindex == index ? false : true"
    32. @click="deleteMemo(index)"
    33. >
    34. 删除
    35. button>
    36. <span v-show="noindex == index ? true : false" class="alter">
    37. <textarea v-model="newItem">textarea>
    38. <button @click="csu">提交button>
    39. span>
    40. div>
    41. div>
    42. div>
    43. template>
    44. <script setup>
    45. import { ref, reactive, onMounted } from 'vue'
    46. const formVisible = ref(false)
    47. const newItem = ref('')
    48. const memos = ref([])
    49. const showActions = ref(false)
    50. const noindex = ref(-1)
    51. const openForm = () => {
    52. formVisible.value = true
    53. showActions.value = true
    54. }
    55. const closeForm = () => {
    56. formVisible.value = false
    57. showActions.value = false
    58. }
    59. const reworkMemo = (index) => {
    60. if (newItem.value === '' || false) {
    61. newItem.value = memos.value[index].name
    62. noindex.value = index
    63. formVisible.value = false
    64. showActions.value = false
    65. } else {
    66. newItem.value = ''
    67. noindex.value = -1
    68. }
    69. }
    70. const csu = () => {
    71. if (noindex.value === -1) {
    72. return
    73. }
    74. memos.value[noindex.value].name = newItem.value
    75. // 取消备忘录的完成状态
    76. memos.value[noindex.value].finished = false
    77. noindex.value = -1
    78. newItem.value = ''
    79. saveTodo()
    80. }
    81. const addMemo = () => {
    82. if (newItem.value.trim() !== '') {
    83. memos.value.push({ name: newItem.value, finished: false })
    84. newItem.value = ''
    85. formVisible.value = false
    86. showActions.value = false
    87. saveTodo()
    88. }
    89. }
    90. const completeMemo = (index) => {
    91. memos.value[index].finished = true
    92. saveTodo()
    93. }
    94. const cancelMemo = (index) => {
    95. memos.value[index].finished = false
    96. saveTodo()
    97. }
    98. const deleteMemo = (index) => {
    99. memos.value.splice(index, 1)
    100. updateItemNumbers()
    101. formVisible.value = false
    102. showActions.value = false
    103. saveTodo()
    104. }
    105. const handleMemoAction = (event) => {
    106. const target = event.target
    107. if (target.innerHTML === '完成') {
    108. // handle complete action
    109. } else if (target.innerHTML === '取消') {
    110. // handle cancel action
    111. } else if (target.innerHTML === '删除') {
    112. // handle delete action
    113. }
    114. }
    115. const saveTodo = () => {
    116. localStorage.myLogs = JSON.stringify(memos.value)
    117. }
    118. const loadTodo = () => {
    119. const savedMemos = JSON.parse(localStorage.myLogs ?? '[]')
    120. memos.value = savedMemos
    121. updateItemNumbers()
    122. }
    123. const updateItemNumbers = () => {
    124. const itemNumbers = document.querySelectorAll('.item-number')
    125. itemNumbers.forEach((item, index) => {
    126. item.textContent = index + 1
    127. })
    128. }
    129. loadTodo()
    130. /*窗口移动事件*/
    131. const formTitle = '鼠标事件绑定标题栏实现拖动功能'
    132. const formPosition = reactive({ x: 0, y: 0 }) // 记录窗口位置的变量
    133. const startDrag = (event) => {
    134. event.preventDefault() // 阻止默认拖动行为
    135. const offsetX = event.clientX - formPosition.x
    136. const offsetY = event.clientY - formPosition.y
    137. const onDrag = (e) => {
    138. formPosition.x = e.clientX - offsetX
    139. formPosition.y = e.clientY - offsetY
    140. }
    141. const onStopDrag = () => {
    142. document.removeEventListener('mousemove', onDrag)
    143. document.removeEventListener('mouseup', onStopDrag)
    144. }
    145. document.addEventListener('mousemove', onDrag)
    146. document.addEventListener('mouseup', onStopDrag)
    147. }
    148. onMounted(() => {
    149. const initialX = window.innerWidth / 4 // 窗口水平
    150. const initialY = window.innerHeight / 4 // 窗口垂直
    151. formPosition.x = initialX
    152. formPosition.y = initialY
    153. })
    154. script>
    155. <style scoped>
    156. /* 全局样式 */
    157. * {
    158. margin: 0;
    159. padding: 0;
    160. box-sizing: border-box;
    161. user-select: none;
    162. }
    163. button,
    164. input {
    165. cursor: pointer;
    166. margin: 0 5px;
    167. border: none;
    168. &:hover {
    169. color: #fff;
    170. background-color: hsla(160, 100%, 37%, 0.2);
    171. box-shadow: 0 0 15px rgba(255, 254, 254, 0.5);
    172. }
    173. }
    174. /* 拖动窗口的样式 */
    175. .draggable-form {
    176. position: fixed;
    177. /* 最小宽度 */
    178. min-width: 50%;
    179. background-color: #fff;
    180. box-shadow: 2px 2px 5px rgba(251, 249, 249, 0.76);
    181. border-radius: 8px;
    182. background-color: rgba(0, 0, 0, 0.5);
    183. z-index: 9;
    184. box-shadow: 0 0 10px rgba(255, 254, 254, 0.5);
    185. }
    186. .form-title {
    187. text-align: center;
    188. padding: 5px;
    189. box-shadow: 0 0 10px rgba(93, 93, 93, 0.537);
    190. color: hsla(160, 100%, 37%, 1);
    191. cursor: move;
    192. }
    193. .form-content {
    194. display: flex;
    195. textarea {
    196. flex: 1;
    197. font-size: 1.5rem;
    198. background-color: rgba(0, 0, 0, 0.5);
    199. color: rgb(255, 255, 255);
    200. text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
    201. &::placeholder {
    202. text-align: center;
    203. }
    204. }
    205. }
    206. /* 文本显示区样式 */
    207. .memo {
    208. display: flex;
    209. align-content: flex-start;
    210. flex-wrap: wrap;
    211. margin: 0 20px;
    212. }
    213. .item {
    214. margin: 5px 10px;
    215. padding: 0 5px;
    216. border-radius: 10px;
    217. background-color: rgba(0, 0, 0, 0.5);
    218. box-shadow: 0 0 10px rgba(255, 254, 254, 0.5);
    219. display: flex;
    220. align-items: center;
    221. transition: all 0.3s ease-in-out;
    222. &:hover {
    223. transform: scale(1.05);
    224. box-shadow: 0 0 15px rgba(255, 254, 254, 0.5);
    225. }
    226. }
    227. .item-number {
    228. /* 粗字体 */
    229. font-weight: bold;
    230. color: #fff;
    231. text-shadow: 1px 1px 1px #030303;
    232. /* 背景颜色 */
    233. background-color: #09de69;
    234. border-radius: 20px;
    235. }
    236. .text-content {
    237. color: hsla(160, 100%, 37%, 1);
    238. user-select: text;
    239. padding: 0 5px;
    240. &:hover {
    241. color: #fff;
    242. background-color: hsla(160, 100%, 37%, 0.2);
    243. }
    244. }
    245. /* 点击完成按钮显示.finish样式 */
    246. .finish {
    247. /* 文本-装饰:删除线 */
    248. /* text-decoration: line-through; */
    249. background-color: rgb(191, 210, 255);
    250. color: rgb(255, 250, 250);
    251. text-shadow: 1px 1px 1px #030303;
    252. box-shadow:
    253. inset -2px -2px 3px rgba(255, 255, 255, 0.6),
    254. inset 2px 2px 3px rgba(0, 0, 0, 0.6);
    255. border-radius: 20px;
    256. }
    257. /* 点击删除按钮显示.alter样式 */
    258. .deleteBtn {
    259. color: #f3d303;
    260. text-shadow: 1px 1px 1px rgb(0, 0, 0);
    261. background: #ff0000;
    262. border-radius: 5px;
    263. border: none;
    264. margin: 5px;
    265. padding: 2px;
    266. /* 粗体 */
    267. font-weight: bold;
    268. &:hover {
    269. background-color: #f3d303;
    270. color: #ff0505;
    271. }
    272. }
    273. style>

  • 相关阅读:
    鸿鹄工程项目管理系统 Spring Cloud+Spring Boot+Mybatis+Vue+ElementUI+前后端分离构建工程项目管理系统项目背景
    小程序赋能生鲜食品进销存,线上+物流系统两手抓
    配置Mysql与注册登录模块
    开发中常用的日期转换
    VERI-ZEXE: Decentralized Private Computation with Universal Setup
    代码随想录day29|491.递增子序列|46.全排列|47.全排列 II|Golang
    React 函数组件
    java基础面试
    Spring Security入门
    a_good_idea
  • 原文地址:https://blog.csdn.net/lulei5153/article/details/139666494